我有一個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