gpt4 book ai didi

c# - SetWindowPos 实现

转载 作者:太空宇宙 更新时间:2023-11-03 16:27:33 26 4
gpt4 key购买 nike

我需要打开两个 Internet 浏览器实例,每个实例都在控制台应用程序的不同监视器(有两个)中打开。我找到了 SetWindowPos 方法,但找不到使用方法。就我而言,它什么也没做……

请帮助我正确使用此方法...

这是我使用的代码:

[DllImport("user32.dll")]
public static extern IntPtr SetWindowPos(IntPtr hWnd, int hWndInsertAfter, int x, int Y, int cx, int cy, int wFlags);

public static void Launch()
{
Process process = new Process();

process.StartInfo.FileName = "iexplore.exe";
process.StartInfo.Arguments = "microsoft.com";
process.StartInfo.WindowStyle = ProcessWindowStyle.Maximized;


process.Start();

Rectangle monitor = Screen.AllScreens[1].WorkingArea;
SetWindowPos(process.MainWindowHandle, 0, monitor.Left, monitor.Top, monitor.Width - 200, monitor.Height, 0);
}

谢谢大卫

最佳答案

您传递给方法的那个窗口句柄是空的,因为进程没有时间打开它的主窗口。

尝试在调用 SetWindowPos 之前添加一个合理的超时时间,一两秒应该足够了:

process.Start();

System.Threading.Thread.Sleep(1000);
process.WaitForInputIdle(); // just in case

SetWindowPos(...);

关于c# - SetWindowPos 实现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12076972/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com