Duilib HandleMessage与MessageHandler区别

Duilib HandleMessage与MessageHandler区别

flyfish

WindowImplBase的声明部分

        virtual LRESULT HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam);
        virtual LRESULT HandleCustomMessage(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
        virtual LRESULT MessageHandler(UINT uMsg, WPARAM wParam, LPARAM /*lParam*/, bool& /*bHandled*/);
WindowImplBase的实现部分

    LRESULT WindowImplBase::HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam)
    {
        LRESULT lRes = 0;
        BOOL bHandled = TRUE;
        switch (uMsg)
        {
        case WM_CREATE:         lRes = OnCreate(uMsg, wParam, lParam, bHandled); break;
        case WM_CLOSE:          lRes = OnClose(uMsg, wParam, lParam, bHandled); break;
......
        case WM_MOUSEHOVER: lRes = OnMouseHover(uMsg, wParam, lParam, bHandled); break;
        default:                bHandled = FALSE; break;
        }
        if (bHandled) return lRes;

        lRes = HandleCustomMessage(uMsg, wParam, lParam, bHandled);
        if (bHandled) return lRes;

        if (m_PaintManager.MessageHandler(uMsg, wParam, lParam, lRes))
            return lRes;
        return CWindowWnd::HandleMessage(uMsg, wParam, lParam);
    }

CWindowWnd是父类,WindowImplBase是子类

LRESULT CWindowWnd::HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    return ::CallWindowProc(m_OldWndProc, m_hWnd, uMsg, wParam, lParam);
}

从代码可以看出关系

如果派生类 如果实现这些虚函数 会先执行HandleMessage,然后是HandleCustomMessage 最后是MessageHandler,
所有写代码的时候只要实现HandleCustomMessage即可

你可能感兴趣的:(C++,VC)