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 Screen
class from System.Windows.Forms
to get the screen rectangle. Remember that the Screen
class 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 the PresentationSource.FromVisual(window).TransformFromDevice
transform 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:
Rect rect1 = new Rect(screenRect.X, screenRect.Y, screenRect.Width/2, screenRect.Height);
Rect rect2 = new Rect(screenRect.X + screenRect.Width/2, screenRect.Y, screenRect.Width/2, screenRect.Height);
Once you have the bounds you can adjust your own window simply enough:
window.Left = rect1.X;
window.Top = rect1.Y;
window.Width = rect1.Width;
window.Height = rect1.Height;
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 SetWindowPos
function. This must be done on a separate thread to avoid blocking the UI.
// Transform rect2 to device coordinates
rect2.Transform(PresentationSource.FromVisual(window).TransformToDevice);
// Execute the rest of this in a separate thread
ThreadPool.QueueUserWorkItem(_ =>
{
// Start Word
var process = Process.Create(pathToWinwordExe);
// Wait for Word to initialize
process.WaitForInputIdle();
// Set the position of the main window
IntPtr hWnd = process.MainWindowHandle;
if(hWnd!=IntPtr.Zero)
SetWindowPos(
hWnd, IntPtr.Zero,
(int)rect2.X, (int)rect2.Y, (int)rect2.Width, (int)rect2.Height,
SWP_NOZORDER);
});
Don't forget the DllImport
for SetWindowPos
. Something like this should work:
[DllImport("user32.dll", CharSet=CharSet.Auto, SetLastError=true, ExactSpelling=true)]
public static extern bool SetWindowPos(
HandleRef hWnd, HandleRef hWndInsertAfter, int x, int y, int cx, int cy, int flags);