Programmatically Maximize Window On Half Of Screen

夙愿已清 提交于 2019-12-10 03:41:58

问题


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.


回答1:


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



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



回答3:


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.



来源:https://stackoverflow.com/questions/18313673/programmatically-maximize-window-on-half-of-screen

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!