PolGraphic
PolGraphic

Reputation: 3364

WM_MOUSEWHEEL stops working while other events still works on in WinAPI (C++)

I have an strange issue in my c++ WinAPI application.

When I run my application, the scroll works and I see MessageBox each time I use it. But then, I click here and there, change window, go back to mine and... everything works, except for mouse scroll (program doesn't receive message and no MessageBox appears, while e.g. LBM, RBM and keys works just fine and program react to them).

It is possible that's due to SetCapture/ReleaseCapture that I execute during program? If not, than what can cause such strange behaviour when all works expcept for mouse scroll (which works from start).

I have the typicall loop:

while(GetMessage (&msg, NULL, 0, 0) > 0){
     TranslateMessage(&msg);
     DispatchMessage(&msg);
}

And my events handler:

LRESULT CALLBACK WndProc( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam ){
switch(message){
    case WM_MOUSEMOVE:
        {   
            //fun stuff here
        }
        break;
    case WM_MOUSEWHEEL:
        {
            MessageBox(NULL, L"MouseWheel", L"MouseWheel", NULL);
            //even more fun stuff here
        }
        break;
    case WM_CREATE:
        {   
        }
        break;
    case WM_CTLCOLORSTATIC:
        {
            //...
            return (LRESULT)GetStockObject(NULL_BRUSH);
        }
        break;
    case WM_PAINT:
        engine->render();
        break;
    case WM_DESTROY:
                PostQuitMessage(0);
        break;
    case WM_LBUTTONDOWN:
        {
            //fun stuff
        }
        break;

    case WM_LBUTTONUP:
        {
            //fun stuff
        }
        break;
    case WM_CHAR:
        switch(wParam){
            //...
        }
        break;

    case WM_SETCURSOR:
        view->refreshCursor();
        break;

    case WM_KEYDOWN:
        switch (wParam){
            /...
        }
        break;

    default:
        return DefWindowProc(hWnd, message, wParam, lParam);
}

return 0;
}

Maybe it's because my window is not active? LMB will work because it will make it active also. But hovers (done with mousemove) still works when my window is not active. How to capture mouse wheel even when window is not active?

Upvotes: 0

Views: 2206

Answers (1)

c-smile
c-smile

Reputation: 27460

Sent to the focus window when the mouse wheel is rotated.

http://msdn.microsoft.com/en-us/library/windows/desktop/ms645617(v=vs.85).aspx

Upvotes: 2

Related Questions