2

I have encountered an annoying problem. When the mouse pointer is positioned over my main window and the owning popup window is shown (see example below) or is made invisible a WM_MOUSEMOVE message is generated each time even if the mouse has not been moved. For several reasons it can't be tolerated in my case.

    hWnd = CreateWindowEx(0, wcx.lpszClassName, L"Demo", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, nullptr, 0, hInstance, nullptr);
    HWND hWndPopupTest = CreateWindowEx(WS_EX_NOACTIVATE | WS_EX_TOPMOST, L"Static", L"DemoPopup", WS_POPUP | WS_VISIBLE, 10, 10, 100, 100, hWnd, 0, hInstance, nullptr);
    ShowWindow(hWnd, SW_SHOW);
    ShowWindow(hWndPopup, SW_SHOWNOACTIVATE);
    Sleep(1000);
    ShowWindow(hWndPopup, SW_HIDE);

The same behavior occurs when ReleaseCapture is called. Is this a feature that can be disabled? Is it a known "problem" or is there a workaround?

Edit: Dirty Workaround

In (main) window procedure we could test if the mouse position has changed since last WM_MOUSEMOVE. If the position has not changed it must be because wither a popup window was shown/hidden or a some window capture was released.

bkausbk
  • 2,740
  • 1
  • 36
  • 52
  • 2
    It cannot be disabled. Actually important, it ensures that the cursor shape is correct. You'll have to work around it. – Hans Passant May 19 '17 at 11:10
  • Is this behavior documented somewhere? – bkausbk May 19 '17 at 11:30
  • 1
    [Why do I get spurious WM_MOUSEMOVE messages?](https://blogs.msdn.microsoft.com/oldnewthing/20031001-00/?p=42343), [Sure, I can get spurious WM_MOUSEMOVE messages, but why do they keep streaming in?](https://blogs.msdn.microsoft.com/oldnewthing/20090617-00/?p=17863), and [Why do I get a spurious WM_MOUSEMOVE message whenever Resource Manager is running?](https://blogs.msdn.microsoft.com/oldnewthing/20160616-00/?p=93685). – IInspectable May 19 '17 at 11:35

1 Answers1

0

Based on the information provided here (thank you @IInspectable) my general solution would be to detect if the given point is a real point by looking in mouse position history with GetMouseMovePointsEx. If no point is found it means no valid movement occurred.

    POINT CurrentPoint{GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)};
    MapWindowPoints(hWnd, nullptr, &CurrentPoint, 1);
    MOUSEMOVEPOINT mmpi = {
        CurrentPoint.x, CurrentPoint.y, GetTickCount(), 0
    };
    MOUSEMOVEPOINT mmpo = {0};
    if (GetMouseMovePointsEx(sizeof(mmpi), &mmpi, &mmpo, 1, GMMP_USE_DISPLAY_POINTS) > 0) {
        MyInstance->HandleMouseMove(POINT{GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)}, wParam);
    } else {
        // No mouse point found in history, so couldn't be a valid point
    }
bkausbk
  • 2,740
  • 1
  • 36
  • 52