我需要在默認瀏覽器中打開一個網站。然後我想在第二個屏幕上顯示瀏覽器。因此我嘗試以下方法:從瀏覽器進程獲取句柄
private void button1_Click(object sender, EventArgs e)
{
var externalApplication = new Process();
externalApplication.StartInfo.WindowStyle = ProcessWindowStyle.Normal;
externalApplication.StartInfo.FileName = "http://www.example.com/";
externalApplication.Start();
externalApplication.WaitForInputIdle();
var handle = externalApplication.MainWindowHandle;
Console.Write(handle);
Program.MoveWindow(handle, 0, 0, 1500, 1, true);
}
[DllImport("user32.dll", SetLastError = true)]
internal static extern bool MoveWindow(IntPtr hWnd, int X, int Y, int nWidth, int nHeight, bool bRepaint);
現在我的問題是,無論是WaitForInputIdle()
也不MainWindowHandle()
似乎在這裏工作。他們都拋出一個InvalidOperationException: No process is associated with this object
Does [this](https://social.msdn.microsoft.com/Forums/en-US/79b6be7e-5f00-474c-a485-50db92feefe2/no-process-is-associated-with-this-object- in-waitforinputidle-and-movewindow-for-audio-files?forum = csharpgeneral)幫助你? –