I'm writing a program to open several links and paths in new windows and put them to certain spots on a certain screen.
Until now I use the code below:
class Program
{
[DllImport("shell32.dll", EntryPoint = "ShellExecute")]
public static extern long ShellExecute(int hwnd, string cmd, string file, string param1, string param2, int swmode);
[DllImport("user32.dll")]
private static extern IntPtr GetForegroundWindow();
[DllImport("user32.dll", EntryPoint = "SetWindowPos")]
public static extern IntPtr SetWindowPos(IntPtr hWnd, int hWndInsertAfter, int x, int Y, int cx, int cy, int wFlags);
static void Main(string[] args)
{
IntPtr hwnd;
ShellExecute(0, "open", "C:\Program Files\Mozilla Firefox\firefox.exe", "www.example.de", "", 5);
Thread.Sleep(5000);
hwnd = GetForegroundWindow();
SetWindowPos(hwnd, 0, 0, 0, 960, 1080, 0);
//and so on for 8 applications on 4 screens...
}
}
I used the ugly sleep command because it takes some time for this old Computer to open the URL or application.
Is there a way to check if the window is open yet?
So the program only proceeds when the Window is already there.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…