2

インターネットブラウザの2つのインスタンスを開く必要があり、各インスタンスはコンソールアプリから別のモニター(2つあります)で開きます。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);
    }

ありがとうDavid

4

2 に答える 2

0

プロセスがメイン ウィンドウを開く時間がないため、メソッドに渡すウィンドウ ハンドルは空です。

SetWindowPos を呼び出す前に、適切なタイムアウトを追加してみてください。1 秒か 2 秒で十分です。

process.Start();

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

SetWindowPos(...);
于 2012-08-22T17:05:12.147 に答える
0

このコードは、たとえば、notepad.exe で機能します。process.MainWindowHandle == IntPtr.Zero、およびprocess.HasExited == true. ウィンドウ ハンドルを見つける正しい方法を見つける必要があります。

于 2012-08-22T17:05:23.160 に答える