| 75 | } |
| 76 | |
| 77 | HWND WindowService::FindChildWnd(HWND child_hwnd, const wchar_t *title, const wchar_t *classname, std::wstring *retstring, |
| 78 | bool isGW_OWNER, bool isVisible, const wchar_t *process_name) { |
| 79 | child_hwnd = ::GetWindow(child_hwnd, GW_HWNDFIRST); |
| 80 | while (child_hwnd != NULL) { |
| 81 | if (isGW_OWNER) // 判断是否要匹配所有者窗口为0的窗口,即顶级窗口 |
| 82 | if (::GetWindow(child_hwnd, GW_OWNER) != 0) { |
| 83 | child_hwnd = ::GetWindow(child_hwnd, GW_HWNDNEXT); // 获取下一个窗口 |
| 84 | continue; |
| 85 | } |
| 86 | |
| 87 | if (isVisible) // 判断是否匹配可视窗口 |
| 88 | if (::IsWindowVisible(child_hwnd) == false) { |
| 89 | child_hwnd = ::GetWindow(child_hwnd, GW_HWNDNEXT); // 获取下一个窗口 |
| 90 | continue; |
| 91 | } |
| 92 | if (title == NULL && classname == NULL) { |
| 93 | if (process_name) { |
| 94 | DWORD pid = 0; |
| 95 | GetWindowThreadProcessId(child_hwnd, &pid); |
| 96 | if (EnumProcessbyName(pid, process_name)) { |
| 97 | if (retstring) |
| 98 | AppendHwndText(retstring, retstringlen, child_hwnd); |
| 99 | else |
| 100 | return child_hwnd; |
| 101 | } |
| 102 | } else { |
| 103 | if (retstring) |
| 104 | AppendHwndText(retstring, retstringlen, child_hwnd); |
| 105 | else |
| 106 | return child_hwnd; |
| 107 | } |
| 108 | } else if (title != NULL && classname != NULL) { |
| 109 | auto WindowClassName = WindowClassNameText(child_hwnd); |
| 110 | auto WindowTitle = WindowTitleText(child_hwnd); |
| 111 | if (wcslen(WindowClassName) > 1 && wcslen(WindowTitle) > 1) { |
| 112 | const wchar_t *strfindclass = wcsstr(WindowClassName, classname); // 模糊匹配 |
| 113 | const wchar_t *strfindtitle = wcsstr(WindowTitle, title); // 模糊匹配 |
| 114 | if (strfindclass && strfindtitle) { |
| 115 | if (process_name) // EnumWindowByProcess |
| 116 | { |
| 117 | DWORD pid = 0; |
| 118 | GetWindowThreadProcessId(child_hwnd, &pid); |
| 119 | if (EnumProcessbyName(pid, process_name)) { |
| 120 | if (retstring) |
| 121 | AppendHwndText(retstring, retstringlen, child_hwnd); |
| 122 | else |
| 123 | return child_hwnd; |
| 124 | } |
| 125 | } else { |
| 126 | if (retstring) |
| 127 | AppendHwndText(retstring, retstringlen, child_hwnd); |
| 128 | else |
| 129 | return child_hwnd; |
| 130 | } |
| 131 | } |
| 132 | } |
| 133 | |
| 134 | } else if (title != NULL) { |
nothing calls this directly
no test coverage detected