Я пытался создать простую программу на C #, чтобы запускать различное программное обеспечение и перемещать его на определенный экран, чтобы иметь возможность автоматически настраивать различные окна на машине с 12 мониторами.
Большинство этих окон запускается в Chrome или Internet Explorer.
Код, который я использую для перемещения приложений, следующий: [DllImport ("User32.dll")] static extern int SetForegroundWindow (IntPtr hWnd);
[DllImport("user32.dll", EntryPoint = "SetWindowPos")]
public static extern IntPtr SetWindowPos(IntPtr hWnd, int hWndInsertAfter, int x, int Y, int cx, int cy, int wFlags);
this.process = Process.Start(this.startInfo);
process.WaitForInputIdle();
SetForegroundWindow(this.process.MainWindowHandle);
Console.WriteLine("Process ID: "+ this.process.Handle);
this.process.Refresh();
Console.WriteLine("Main window handle: " + this.process.MainWindowHandle);
Point screenlocation = Screen.AllScreens[MonitorNum].Bounds.Location;
SetWindowPos(this.process.MainWindowHandle, -1, screenlocation.X, screenlocation.Y, Screen.AllScreens[MonitorNum].Bounds.Width, Screen.AllScreens[MonitorNum].Bounds.Height, 1);
Кажется, он отлично работает с Блокнотом, но когда это браузер, MainWindowHandle всегда возвращает IntPtr.Zero, даже если я обновляю процесс.
Любой совет?