7
votes

I want to maximize a random window on the left side of my screen. Can I use Windows Aero functions from my code ? This window can be maximized like that with the mouse. I just want to do that programmatically.

I use C# and I can get the IntPtr of the window.

If possible without faking mouse or keyboard input.

3
Unfortunately not, Microsoft in their wisdom did not provide any public API for the aero snap functionality.Jonathan Potter
This can be done without p/invoke, Just not with ease,Nicolas Tyler
Can't you mimick this behavior by setting the window position and size, based on the desktop size? Should be easy enough, just not very "clean"Kippie
Just pinvoke MoveWindow().Hans Passant
@HansPassant Did that already combining it with the answer of Nicolas. But I'm still kinda interested in using Aero.Bitterblue

3 Answers

5
votes

This can be done without p/invoke.

Try this:

Rectangle rect = Screen.PrimaryScreen.WorkingArea;
rect.Width = rect.Width / 2;
Bounds = rect;

This will put the current window on the left of the primary screen.

Then just add this to put it on the right of the screen.

Location = new Point(rect.Width, 0);
3
votes

It's not exactly the same but fakes it well:

ShowWindow(handle, SW_MAXIMIZE);
// for a split second you might see a maximized window here
MoveWindow(handle, 0, 0, Screen.PrimaryScreen.WorkingArea.Width / 2, Screen.PrimaryScreen.WorkingArea.Height, true);
0
votes

Will require heavy lifting for real-time placements, especially for non-child processes. Example - www.ishadow.com/vdm. For manual "fixing" of maximized windows position MoveWindow(hWnd, startPos, 0, winWidth, winHeight, true) after ShowWindow(hWnd, SW_MAXIMIZE) usually (try Task Manager on Windows 10) works as pointed above.