Search code examples
c++mousewheelwtl

Handling wm_mousewheel message in WTL


I am trying to handle wm_mousewheel for my application.

Code:

BEGIN_MSG_MAP(DxWindow)     
  MESSAGE_HANDLER(WM_MOUSEWHEEL, KeyHandler)
END_MSG_MAP()
.
.
.

LRESULT DxWindow::KeyHandler( UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled )
 {
     if(uMsg==wm_mousewheel)
     {
       //Perform task.
     }
     return 0;
 }

But this code doesn't work.KeyHandler doesn't receive wm_mousewheel message. I am testing this application on vista. If my approach is wrong how to handle wm_mousewheel properly? Do vista is responsible for failure in handling wm_mousewheel message?


Solution

  • From the doc: The WM_MOUSEWHEEL message is sent to the focus window when the mouse wheel is rotated. The DefWindowProc function propagates the message to the window's parent. There should be no internal forwarding of the message, since DefWindowProc propagates it up the parent chain until it finds a window that processes it.

    1. Change your test to if(uMsg == WM_MOUSEWHEEL).
    2. Check that your window or one of it's children has focus.
    3. If this is related to your previous wtl-child-window-event-handling question, I edited my answer to not forward WM_MOUSEWHEEL.