Question

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.

Was it helpful?

Solution 2

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);

OTHER TIPS

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);

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top