如何找到桌面上报错的窗口,不管是父窗口还是子窗口,而且获得它的出错信息呢?
主要是利用API函数: 复制 保存
[DllImport("user32.dll")]public static extern int FindWindowEx(int hwndParent, int hwndChildAfter, string lpszClass, string lpszWindow);[DllImport("user32.dll")]public static extern int FindWindow(string strclassName, string strWindowName);[DllImport("user32.dll")]public static extern int GetLastActivePopup(int hWnd);[DllImport("user32.dll")]public static extern int AnyPopup();[DllImport("user32.dll")]public static extern int GetWindowText(int hWnd, StringBuilder lpString, int nMaxCount);[DllImport("user32.dll")]public static extern int EnumThreadWindows(int dwThreadId, CallBack lpfn, int lParam);[DllImport("user32.dll")]public static extern int EnumWindows(CallBack lpfn, int lParam);[DllImport("user32.dll")]public static extern int EnumChildWindows(int hWndParent, CallBack lpfn, int lParam);
复制 保存
////// 回调函数代理/// public delegate bool CallBack(int hwnd, int lParam);
复制 保存
////// 进程回调处理函数/// /// /// ///public static bool ThreadWindowProcess(int hwnd, int lParam){ EnumChildWindows(hwnd, callBackEnumChildWindows, 0); return true;}/// /// 窗口回调处理函数/// /// /// ///public static bool WindowProcess(int hwnd, int lParam){ EnumChildWindows(hwnd, callBackEnumChildWindows, 0); return true;}/// /// 子窗口回调处理函数/// /// /// ///public static bool ChildWindowProcess(int hwnd, int lParam){ StringBuilder title = new StringBuilder(200); int len; len = GetWindowText(hwnd, title, 200); if (len > 0) { if (title.ToString().IndexOf(GlobalManager.ErrorMessage) != -1) { FindError = true; } } return true;}
复制 保存
////// 进程窗口回调函数代理/// public static CallBack callBackEnumThreadWindows = new CallBack(ThreadWindowProcess);////// 窗口回调函数代理/// public static CallBack callBackEnumWindows = new CallBack(WindowProcess);////// 子窗口回调函数代理/// public static CallBack callBackEnumChildWindows = new CallBack(ChildWindowProcess);
复制 保存
////// 客户端是否弹出对话框/// ///public bool IsClientPopupWindows(){ bool FindError = false; EnumWindows(callBackEnumWindows, 0); return FindError;}