I've been trying to make a simple program in C#, to launch different software, and move it to a specific screen, to be able to automatically set up different windows, on a machine with a total of 12 monitors.
Most of these windows is launched in either Chrome or Internet Explorer.
The code I use to move the appplications is the following: [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);
It seems to be working just fine with Notepad, but when it's a browser MainWindowHandle always return IntPtr.Zero, even if I refresh the Process.
Any advice?