0

複数のモニターで最大化された IE の複数のインスタンスを起動する C# コンソール アプリケーションを作成したいと考えています。

更新:これが私がこれまでに試したことです。2 番目の IE インスタンスを起動すると、2 番目の画面で開きません。IEには複数のウィンドウと共有するメインウィンドウハンドルが1つしかない可能性があるため、MainWindowHandleと関係があると思います。コードの最後の行は、実際には InvalidOperationException をスローします。このコードは、メモ帳の起動には機能しますが、IE には機能しません。

using System;
using System.Diagnostics;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Windows.Forms;

namespace TestLauncher
{
    class Launcher2
    {
        [DllImport("user32.dll")]
        private extern static bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, int uFlags);
        const int SWP_SHOWWINDOW = 0x0040;

        static readonly IntPtr HWND_TOP = IntPtr.Zero;

        public void Launch()
        {
            Process p1 = new Process();
            p1.StartInfo.FileName = "iexplore.exe";
            p1.StartInfo.Arguments = "microsoft.com";
            p1.Start();
            p1.WaitForInputIdle(2000);
            System.Threading.Thread.Sleep(2000);

            Rectangle monitor = Screen.AllScreens[0].WorkingArea;
            SetWindowPos(p1.MainWindowHandle, HWND_TOP, monitor.Left, monitor.Top, monitor.Width, monitor.Height, SWP_SHOWWINDOW);


            Process p2 = new Process();
            p2.StartInfo.FileName = "iexplore.exe";
            p2.StartInfo.Arguments = "google.com";
            p2.Start();
            p2.WaitForInputIdle(2000);
            System.Threading.Thread.Sleep(2000);

            Rectangle monitor2 = Screen.AllScreens[1].WorkingArea;
            SetWindowPos(p2.MainWindowHandle, HWND_TOP, monitor2.Left, monitor2.Top, monitor2.Width, monitor2.Height, SWP_SHOWWINDOW);
        }
    }
}

可能であれば、IE 以外のアプリケーションも起動できるほど柔軟なソリューションを探しています。

4

0 に答える 0