I have a WPF application that will always run on windows 7, it opens and displays in full-screen mode
There is a button within WPF app that opens up Word
I would like the WPF application on opening up Word to send a command to the operating system so that it tiles both the WPF application and the Word application windows side by side, so that they each take up 50% of screen each. Is this possible? if yes would anyone know what the code may be? ( a bit like when you right click on windows 7 task bar and click Show Windows Side by Side)
Yes it is possible and is relatively easy.
You say that you already have code that opens your WPF window “full screen”. Assuming this is a true “full screen” view and not a “maximized” window you have already calculated the screen rectangle. If not, you can use the
Screenclass fromSystem.Windows.Formsto get the screen rectangle. Remember that theScreenclass is part of WinForms, so it uses device coordinates (pixels) instead of resolution-independent coordinates (96dpi) so you’ll need to convert from Rectangle to Rect and then apply thePresentationSource.FromVisual(window).TransformFromDevicetransform to get WPF coordinates.Once you have the screen Rect in device-independent (96dpi) coordinates, you must compute the separate rectangles. For example here is the computation for a 50% horizontal division of screenRect:
Once you have the bounds you can adjust your own window simply enough:
Moving the Word window is slightly more complicated. You must convert to device coordinates, start the process, wait for Word to initialize, then call Win32’s
SetWindowPosfunction. This must be done on a separate thread to avoid blocking the UI.Don’t forget the
DllImportforSetWindowPos. Something like this should work: