我有一个C#窗口应用程序,并最终从互操作组件中启动对话框。 问题是,这个对话窗口有时出现在c#应用程序的主窗口后面,迫使用户使用alt-tab来查找它。C#从窗口句柄获取父进程
我已经把措施纳入地方找到这个对话窗口,并把它向前......
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
}
...但“发现”对话是有问题的对话框的类名和窗体标题的变化。
但是,对话窗口的父进程(任务管理器>转到进程)与当前进程相同。所以为了正确'找到'这个对话窗口,我的目的是枚举所有的窗口,找到父进程ID并与当前进程进行比较。
有没有办法从窗口句柄中获得整个父进程?
非常好,谢谢。这个答案和这篇文章(http://stackoverflow.com/questions/2281429/how-to-enumerate-all-windows-within-a-process)导致我的解决方案。 – MoSlo