I am starting an executable several times like this
Process proc = new Process();
proc.StartInfo.FileName = path + "/BuiltGame.exe";
proc.Start();
Process proc1 = new Process();
proc1.StartInfo.FileName = path + "/BuiltGame.exe";
proc1.Start();
Now I want to resize and move the spawned windows.
I am currently using MoveWindow and FindWindow
[DllImport("user32.dll", SetLastError = true)]
internal static extern bool MoveWindow(IntPtr hWnd, int X, int Y, int nWidth, int nHeight, bool bRepaint);
[DllImport("user32.dll", SetLastError = true)]
internal static extern IntPtr FindWindow(string windowClass, string title);
Initially I thought that I could just use the handle from the spawned process
MoveWindow(proc.Handle, 0, 0, 100, 100, true);
But it didn't work and I tried to use FindWindow
IntPtr Handle = FindWindow(null,"MyWindowTitle")
Which indeed worked and the returned handle from FindWindow
is a different one that from Process.Handle
After that I tried to use
MoveWindow(proc.MainWindowHandle, 0, 0, 100, 100, true);
But MainWindowHandle
is just 0.
The problem that I now have is that I want to start multiple processes and get the correct window handle from each window but FindWindow
only returns the first one.
How would I do this?