Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/278.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何从WinForms应用程序控制新进程窗口的大小和位置?_C#_Windows_Winforms_32bit 64bit - Fatal编程技术网

C# 如何从WinForms应用程序控制新进程窗口的大小和位置?

C# 如何从WinForms应用程序控制新进程窗口的大小和位置?,c#,windows,winforms,32bit-64bit,C#,Windows,Winforms,32bit 64bit,我的WinForms应用程序使用Process.Start()在其本机应用程序中打开文件。我想将屏幕一分为二,一半显示我的WinForms应用程序,另一半显示新进程。我知道我可以使用Process.MainWindowHandle获取窗口句柄,但如何设置其大小和位置 我想我必须使用某种Windows API,但哪一种以及如何使用?由于这不是真正的“在我的驾驶室”,我不确定是否(以及如何)需要在64位Windows上使用不同的API。所讨论的Windows API方法是SetWindowPos。您

我的WinForms应用程序使用
Process.Start()
在其本机应用程序中打开文件。我想将屏幕一分为二,一半显示我的WinForms应用程序,另一半显示新进程。我知道我可以使用
Process.MainWindowHandle
获取窗口句柄,但如何设置其大小和位置


我想我必须使用某种Windows API,但哪一种以及如何使用?由于这不是真正的“在我的驾驶室”,我不确定是否(以及如何)需要在64位Windows上使用不同的API。

所讨论的Windows API方法是SetWindowPos。您可以这样声明:

[DllImport("user32.dll")]
private extern static bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, int uFlags);
请在这里阅读:

已添加

Process.MainWindowHandle是您将使用的hWnd参数。 HwnInsertAfter可能是您自己表单的句柄(Form.handle)。 您可以使用屏幕类型访问有关桌面的信息:

添加了托马斯的评论

在调用SetWindowPos之前,请确保等待输入

Process process = Process.Start(...);
if (process.WaitForInputIdle(15000))
    SetWindowPos(process.MainWindowHandle, this.Handle, ...);

上面的SetWindowPos声明适用于32位和64位窗口。

在尝试调整窗口大小之前,您可能需要在进程上调用WaitForInput…Thomas,这正是我所需要的!您可能需要添加Thomas关于
Process.WaitForInputIdle
的内容。如果你这样做了,我会把这个标记为答案。此外,这也是Win32 API的一部分。它在64位操作系统上工作吗?@flip疑惑:Win32只是API的通俗名称;它的所有功能也都在64位上工作。官方名称为“Windows API”。在这里,您可以找到一个使用枚举作为标志的版本,该版本还包含XML注释: