他のアプリケーションのメイン ウィンドウへの hWnd を取得する必要があります。その方法を覚えている唯一の方法は、自分のウィンドウが見つかるまですべてのウィンドウをループすることです。もっと直接的な方法があるかもしれません
[DllImport("user32.dll")] private static extern
int EnumWindows(EnumWindowsProc ewp, int lParam);
public delegate bool EnumWindowsProc(int hWnd, int lParam);
public void EnumerateAllWindows()
{
EnumWindowsProc ewp = new EnumWindowsProc(EvalWindow);
EnumWindows(ewp, 0);
}
private bool EvalWindow(int hWnd, int lParam)
{
//this will be called for each window..
// use GetWindowThreadProcessId to get the PID for each window
// and use Process.GetProcessById to get the PID you are looking for
// then bring it to foregroun using of these calls below:
}
[DllImport("user32.dll")]
public static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
[DllImport("user32.dll")]
public static extern bool BringWindowToTop(IntPtr hWnd);
DllImport("user32.dll")] public static extern bool SetForegroundWindow(IntPtr hWnd