//public static Window Find(string winName) //{ // int iCount = 0; // while (iCount < 50) // { // IntPtr hWnd = WinAPI.FindWindow(null, winName); // if (hWnd != IntPtr.Zero) // { // Log.INFO(string.Format("Finded Window:[{0},{1}]", winName, hWnd.ToString("X8"))); // return new Window(hWnd, winName); // } // iCount++; // Thread.Sleep(200); // } // throw new ArgumentException(string.Format("can not find window:[{0}]", winName)); //} //internal void SendKeyBoard(char v) //{ // uint code = WinAPI.MapVirtualKey(v, 0); // uint lctrlParam = (0x00000001 | ((uint)WinAPI.VirtualKeyCode.VK_MENU << 16)); // WinAPI.PostMessage(_hWnd, (int)WinAPI.WMMessage.WM_KEYDOWN, (IntPtr)WinAPI.VirtualKeyCode.VK_MENU, (IntPtr)0); // Thread.Sleep(500); // uint lcodlParam = (0x00000001 | ((uint)code << 16)); // WinAPI.PostMessage(_hWnd, (int)WinAPI.WMMessage.WM_KEYDOWN, (IntPtr)code, (IntPtr)0); // Thread.Sleep(500); // //lctrlParam |= 0xC0000000; // WinAPI.PostMessage(_hWnd, (int)WinAPI.WMMessage.WM_KEYDOWN, (IntPtr)code, (IntPtr)1); // Thread.Sleep(500); // //lcodlParam |= 0xC0000000; // WinAPI.PostMessage(_hWnd, (int)WinAPI.WMMessage.WM_KEYDOWN, (IntPtr)WinAPI.VirtualKeyCode.VK_MENU, (IntPtr)1); //} //public static Window FindWindowContains(string subName) //{ // int iCount = 0; // while (iCount < 100) // { // Window findWindow = null; // WinAPI.EnumWindows(new WinAPI.EnumWindowsProc((hWnd, lParam) => // { // uint pid = 0; // int length = WinAPI.GetWindowTextLength(hWnd); // StringBuilder windowName = new StringBuilder(length + 1); // WinAPI.GetWindowText(hWnd, windowName, windowName.Capacity); // if (!windowName.ToString().Replace("&", "").Contains(subName)) // { // return true; // } // findWindow = (Window)Activator.CreateInstance(typeof(Window), hWnd, subName); // return false; // }), // (IntPtr)0); // if (findWindow != null) // { // Log.INFO(string.Format("Finded Window:[{0},{1}]", subName, findWindow._hWnd.ToString("X8"))); // return findWindow; // } // iCount++; // Thread.Sleep(200); // } // throw new ArgumentException(string.Format("can not find window:[{0}]", subName)); //} //public Window FindChildWindow(string subName) //{ // int iCount = 0; // while (iCount < 100) // { // Window findWindow = null; // WinAPI.EnumWindows(new WinAPI.EnumWindowsProc((hWnd, lParam) => // { // uint pid = 0; // int length = WinAPI.GetWindowTextLength(hWnd); // StringBuilder windowName = new StringBuilder(length + 1); // WinAPI.GetWindowText(hWnd, windowName, windowName.Capacity); // if (WinAPI.GetParent(hWnd) != _hWnd) // { // return true; // } // if (windowName.ToString().Replace("&", "") != subName) // { // return true; // } // findWindow = (Window)Activator.CreateInstance(typeof(Window), hWnd, subName); // return false; // }), // (IntPtr)0); // if (findWindow != null) // { // Log.INFO(string.Format("Finded chid Window:[{0},{1}], in window:[{2},{3}]", subName, findWindow._hWnd.ToString("X8"), _name, _hWnd.ToString("X8"))); // return findWindow; // } // iCount++; // Thread.Sleep(200); // } // throw new ArgumentException(string.Format("can not find child window:[{0}], in window:[{1}]", subName, _name)); //} //public Window FindChildWindowContains(string subName) //{ // int iCount = 0; // while (iCount < 200) // { // Window findWindow = null; // WinAPI.EnumChildWindows(_hWnd, new WinAPI.EnumWindowsProc((hWnd, lParam) => // { // uint pid = 0; // int length = WinAPI.GetWindowTextLength(hWnd); // StringBuilder windowName = new StringBuilder(length + 1); // WinAPI.GetWindowText(hWnd, windowName, windowName.Capacity); // if (!windowName.ToString().Replace("&", "").Contains(subName)) // { // return true; // } // findWindow = (Window)Activator.CreateInstance(typeof(Window), hWnd, subName); // return false; // }), // 0); // if (findWindow != null) // { // Log.INFO(string.Format("Finded child Window:[{0},{1}], in window:[{2},{3}]", subName, findWindow._hWnd.ToString("X8"), _name, _hWnd.ToString("X8"))); // return findWindow; // } // iCount++; // Thread.Sleep(500); // } // throw new ArgumentException(string.Format("can not find child window:[{0}], in window:[{1},{2}]", subName, _name, _hWnd)); //} internal void WaitExit(string ctrlName, Action <Button> continueAction) { Log.INFO(string.Format("Waiting Window[{0},{1}] Exit", _name, _hWnd)); while (WinAPI.IsWindow(_hWnd)) { string currFindName = ctrlName; Type findType = typeof(Button); object findObj = null; WinAPI.EnumChildWindows(_hWnd, new WinAPI.EnumWindowsProc((hWnd, lParam) => { return(EnumWindowsProc <Button>(hWnd, lParam, currFindName, ref findObj)); }), (int)_hWnd); if (findObj != null) { continueAction((Button)findObj); } Thread.Sleep(200); } }
public void WaitExit(int second = 5 *60, Action action = null) { Log.INFO(string.Format("Waiting Window[{0},{1}] Exit", _name, _hWnd)); for (int i = 0; i < second; i++) { if (!WinAPI.IsWindow(_hWnd)) { return; } if (action != null) { action(); } Application.WinTree newTree = _process.GetWindowTree(); IntPtr exceptHwnd = newTree.Find((IntPtr hwnd) => { string str = WinAPI.GetWindowText(hwnd); if (str.ToLower().Contains("error") || str.ToLower().Contains("fail") || str.ToLower().Contains("warn") || str.ToLower().Contains("not able")) { return(true); } return(false); }); if (exceptHwnd != IntPtr.Zero) { IntPtr defaultHwnd = newTree.Find((IntPtr hwnd) => { string str = WinAPI.GetWindowText(hwnd); if (str.Contains(" Defaulting to Generic profile")) { return(true); } return(false); }); if (defaultHwnd == IntPtr.Zero) { throw new Exception(string.Format("Find a error window:{0}, HWND:{1}", WinAPI.GetWindowText(exceptHwnd), exceptHwnd)); } } Thread.Sleep(1000); } throw new Exception(string.Format("Wait Window[{0},{1}] Exit Timeout!", _name, _hWnd)); }
public bool IsExit() { return(!WinAPI.IsWindow(_hWnd)); }