我想创建一个C#控制台应用程序来启动在多个监视器上最大化的多个IE实例。
更新:这是我到目前为止所尝试的内容。当我启动第二个IE实例时,它不会在第二个屏幕上打开。我认为它与MainWindowHandle有关,因为IE可能只有一个主窗口句柄,它与多个窗口共享。最后一行代码实际上抛出了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以外的其他应用程序。