If you kindly ask, WindowFromPoint will ignore your window (which is being dragged) and return the next window. This is what Internet Explorer does when you drag a tab.
To do this:
Troubleshooting (if you still get your window from WindowFromPoint )
- Test
GetCurrentThreadID() == GetWindowThreadProcessId(WindowFromPoint(), 0) to make sure that you are calling the correct thread. - In
WM_NCHITTEST , verify that the hwnd parameter is equal to what you get from WindowFromPoint()
Example (the area inside the rectangle returns the base window from WindowFromPoint ):
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { static const RECT s_TransparentRect = {100, 100, 200, 200}; switch (message) { case WM_NCCREATE: SetTimer(hWnd, 1, 100, 0); break; case WM_TIMER: { POINT cursorPos; GetCursorPos(&cursorPos); TCHAR buffer[256]; _snwprintf_s(buffer, _countof(buffer), _TRUNCATE, _T("WindowFromPoint: %08X\n"), (int)WindowFromPoint(cursorPos)); SetWindowText(hWnd, buffer); } break; case WM_PAINT: { PAINTSTRUCT ps; BeginPaint(hWnd, &ps); Rectangle(ps.hdc, s_TransparentRect.left, s_TransparentRect.top, s_TransparentRect.right, s_TransparentRect.bottom); EndPaint(hWnd, &ps); } break; case WM_NCHITTEST: { POINT cursorPos; GetCursorPos(&cursorPos); MapWindowPoints(HWND_DESKTOP, hWnd, &cursorPos, 1); if (PtInRect(&s_TransparentRect, cursorPos)) return HTTRANSPARENT; } break; } return DefWindowProc(hWnd, message, wParam, lParam); }
Codeguard
source share