Search code examples
c++windowswinapiwtl

Why a child window may not receive mouse events?


I have a custom WTL control which is a panel with a list and a custom scroll bar.

class Panel
: public ATL::CWindowImpl<Panel>, public WTL::CDoubleBufferImpl<Panel> {
public:
    DECLARE_WND_CLASS("Panel")

    BEGIN_MSG_MAP_EX(Panel)
        MSG_WM_CREATE(OnCreate)
        MSG_WM_DESTROY(OnDestroy)
        MSG_WM_SIZE(OnSize)
        CHAIN_MSG_MAP(CDoubleBufferImpl<Panel>)
        REFLECT_NOTIFICATIONS()
    END_MSG_MAP()

The scroll bar is created by the panel in OnCreate():

m_scrollBar.Create(m_hWnd, WTL::CRect(...));

That scroll bar works fine in many other dialog windows. However, inside that panel control the scroll bar appears, but receives no mouse events at all. If I add WM_MOUSEMOVE handler to the panel, it does get called.

What could be the problem?


Solution

  • Found it. The problem was in the scroll bar class declaration:

    class CScrollBase : public ATL::CWindowImpl<CScrollBase, WTL::CStatic>
    

    Changing to:

    class CScrollBase : public ATL::CWindowImpl<CScrollBase>
    

    makes the scroll bar work on the panel.