Vinz
Vinz

Reputation: 3198

CStatic subclassed Control fails to receive input messages

I am using a MFC dialog based application and have a subclassed CStatic control. I would like to receive WM_MOUSEWHEEL and other messages inside my subclassed control but somehow those messages never arrive.

Here is how my Dialog looks like:

enter image description here

I'm only doing some really simple drawing and want to be able to move my list up and down by scrolling.

I did already:

Sadly nothing ever gets called when I'm scrolling inside the Dialog / Pressing a key or clicking with my mouse. The messages just don't arrive.

Here is my Mousewheel handler for example:

class CFolderView : public CStatic
{
   ...
   afx_msg BOOL OnMouseWheel(UINT nFlags, short zDelta, CPoint pt);
   DECLARE_MESSAGE_MAP()
   ...
}

BEGIN_MESSAGE_MAP(CFolderView, CStatic)
    ON_WM_MOUSEWHEEL()
    ON_WM_KEYDOWN()
    ON_WM_LBUTTONDOWN()
END_MESSAGE_MAP()

BOOL CFolderView::OnMouseWheel(UINT nFlags, short zDelta, CPoint pt)
{
    MessageBox("Mouse Wheel moved!", "Debug", MB_OK);

    return CStatic::OnMouseWheel(nFlags, zDelta, pt);
}

I fail to understand why no input messages are being sent to my subclassed control. Is there some switch that enables input for a subclassed control?

Upvotes: 1

Views: 784

Answers (1)

Andrew Komiagin
Andrew Komiagin

Reputation: 6556

You cannot handle WM_MOUSEWHEEL in CStatic because it cannot get focus by design.

From MSDN:

The WM_MOUSEWHEEL message is sent to the focus window when the mouse wheel is rotated

By looking at your screenshot I'd suggest subclassing CListBox instead.

Upvotes: 2

Related Questions