ST3
ST3

Reputation: 8946

Child window do not catch WM_MOUSEWHEEL event

I have main window which contains child. In child I need to handle mouse wheel scroll, however it doesn't matter where I scroll mouse wheel message goes to main window. I got those results with Spy++.

Don't know why it happens, but I think that something is wrong with child creation, my code:

m_window = CreateWindowEx(0, CustomTreeView::m_className.c_str(), NULL, WS_CHILD | WS_VISIBLE | WS_HSCROLL | WS_VSCROLL, x, y, width, height, parent, NULL, NULL, NULL);

Upvotes: 2

Views: 3382

Answers (1)

Jonathan Potter
Jonathan Potter

Reputation: 37122

The WM_MOUSEWHEEL message is sent to the window with focus (i.e. the last one to have SetFocus() called on it). It doesn't matter where the mouse cursor is located - the messages will always go to the focus window.

If the focus window doesn't handle the wheel message, it is propogated by DefWindowProc to the focus window's parent, and again to its parent, and so on. So wheel messages only move up the window hierarchy.

If you want a child window that doesn't have input focus to get wheel messages then you need to arrange to forward them to it yourself.

If you do this, you should do it via a different message, to avoid the possibility of infinite loops.

Upvotes: 9

Related Questions