| 8 | namespace OpenKneeboard { |
| 9 | |
| 10 | static BOOL CALLBACK FindMainWindowCallback(HWND handle, LPARAM param) { |
| 11 | DWORD windowProcess = 0; |
| 12 | GetWindowThreadProcessId(handle, &windowProcess); |
| 13 | if (windowProcess != GetCurrentProcessId()) { |
| 14 | return TRUE; |
| 15 | } |
| 16 | |
| 17 | if (GetWindow(handle, GW_OWNER) != (HWND)0) { |
| 18 | return TRUE; |
| 19 | } |
| 20 | |
| 21 | if (!IsWindowVisible(handle)) { |
| 22 | return TRUE; |
| 23 | } |
| 24 | |
| 25 | if (IsIconic(handle)) { |
| 26 | return TRUE; |
| 27 | } |
| 28 | |
| 29 | // In general, console windows can be main windows, but: |
| 30 | // - never relevant for a graphics tablet |
| 31 | // - debug builds of OpenKneeboard often create console windows for debug |
| 32 | // messages |
| 33 | if (handle == GetConsoleWindow()) { |
| 34 | return TRUE; |
| 35 | } |
| 36 | |
| 37 | RECT clientRect {}; |
| 38 | if (!GetClientRect(handle, &clientRect)) { |
| 39 | return TRUE; |
| 40 | } |
| 41 | |
| 42 | // Origin of client rect is always (0,0), bottom right is 1px outside the |
| 43 | // window |
| 44 | if (clientRect.right <= 1 || clientRect.bottom <= 1) { |
| 45 | return TRUE; |
| 46 | } |
| 47 | |
| 48 | *reinterpret_cast<HWND*>(param) = handle; |
| 49 | return FALSE; |
| 50 | } |
| 51 | |
| 52 | HWND FindMainWindow() { |
| 53 | HWND ret {0}; |
nothing calls this directly
no outgoing calls
no test coverage detected