I have a C# windows application and ultimately launches a dialog from an interop component. The problem is that this dialog window sometimes appears behind the c# application's main window, forcing a user to alt-tab to find it.

I've put measures into place to find this dialog window and bring it forward...

private static extern bool SetForegroundWindow(IntPtr hWnd);

public class SearchData
{
    public string Wndclass;
    public string Title;
    public IntPtr hWnd;
}

private static extern bool EnumWindows(EnumWindowsProc lpEnumFunc, ref SearchData data);
private delegate bool EnumWindowsProc(IntPtr hWnd, ref SearchData data);

public static bool EnumProc(IntPtr hWnd, ref SearchData data)
{
  //Code to determine whether the window from handle hWnd is our target window.
  //apply handle, title, class to data and halt the enumeration
}

...but 'finding' the dialog is problematic as the dialog's className and form title changes.

However, the dialog window's parent process (Task Manager>Go To Process) is the same as the current process. So to correctly 'find' this dialog window, my aim is to enumerate through all the windows, find the parent processID and compare against CurrentProcess.

Is there a way to obtain the overall parent process from a window handle?

有帮助吗?

解决方案

GetWindowThreadProccessId will do the work.

其他提示

Try hiding your application window prior to opening the dialog. That way it won't appear behind it.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top