1
votes

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:

  • Change the Tab-Order to ensure focus on the subclassed CStatic control first
  • Overwrote OnNcHitTest to give focus to the subclassed CStatic all the time
  • Added a scroll bar to the side
  • Wrote message handler for WM_MOUSEWHEEL, WM_LBUTTONDOWN, WM_KEYDOWN and WM_VSCROLL
  • Tried catching the messages in PreTranslateMessage

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?

1
Andrew already gave you a good answer, but I'd like to ask why you don't use a listbox to derive from instead? They can be heavily customized including icons and text together.Ulrich Eckhardt

1 Answers

2
votes

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.