如何从 WinForms 应用程序控制新流程窗口的大小和位置?
我的 WinForms 应用程序使用 Process.Start() 在其本机应用程序中打开文件。我想将屏幕分成两半,在一半上显示我的 WinForms 应用程序,在另一半上显示新流程。我知道我可以使用 Process.MainWindowHandle 来获取窗口句柄,但是如何设置它的大小和位置?
我想我必须使用某种 Windows API,但是使用哪一种以及如何使用呢?由于这并不是真正的“在我的驾驶室”,我不确定是否(以及如何)需要在 64 位 Windows 上使用不同的 API。
My WinForms app uses Process.Start()
to open files in their native app. I want to split the screen in half, showing my WinForms app on one half and the new process on the other. I know I can use Process.MainWindowHandle
to get the window handle, but how can I set its size and position?
I imagine I have have to use some kind of Windows API, but which one and how? Since this is not really "in my wheelhouse", I am unsure of whether (and how) I need to use different APIs on 64bit Windows.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
所讨论的 Windows API 方法是 SetWindowPos。您可以像这样声明它:
并在这里阅读它:
http://msdn.microsoft.com/en-us/library/ms633545.aspx
添加
Process.MainWindowHandle 是您将使用的 hWnd 参数。
hWndInsertAfter 可能是您自己的 Form 句柄 (Form.Handle)。
您可以使用屏幕类型来访问有关桌面的信息:
http://msdn.microsoft.com/en-us /library/system.windows.forms.screen.aspx
添加了 Thomas 的评论
确保在调用 SetWindowPos 之前您 WaitForInputIdle。
上面的 SetWindowPos 声明适用于 32 位和 64 位 Windows。
The Windows API method in question is SetWindowPos. You can declare it like so:
and read about it here:
http://msdn.microsoft.com/en-us/library/ms633545.aspx
Added
Process.MainWindowHandle is the hWnd parameter you will use.
hWndInsertAfter will probably be your own Form's handle (Form.Handle).
You can use the Screen type to access information about the desktop:
http://msdn.microsoft.com/en-us/library/system.windows.forms.screen.aspx
Added Thomas' comment
Make sure you WaitForInputIdle before calling SetWindowPos.
The declaration for SetWindowPos above works for both 32- and 64-bit Windows.