【MFC】CDialogBar中按钮不可用

现象展现:函数

具体缘由:spa

A button in a CDialogBar object is disabled automatically if the command routing does not contain a command handler function for the button.
To enable a button in a CDialogBar object, the command routing must include a command handler for the button. 

NOTE: Because the CDialogBar object is not included in the routing scheme, the ON_BN_CLICKED() or ON_COMMAND() handler must be placed in one of the objects mentioned above that is in the routing scheme and not in the CDialogBar class.code

解决办法:blog

一、若是按钮的消息处理是在CMainFrame中的就不用OnUpdateCmdUI,在其余类的话仍是要重载OnUpdateCmdUI的get

二、重载CMainFrame::OnCmdMsg函数io

BOOL CMainFrame::OnCmdMsg(UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo)
{
    if(m_wndDlgBar.OnCmdMsg(nID, nCode, pExtra, pHandlerInfo))
    {
        return TRUE;
    }
    return CMDIFrameWndEx::OnCmdMsg(nID, nCode, pExtra, pHandlerInfo);
}

三、重载CDialogBar::OnUpdateCmdUIfunction

void CMyDialogBar::OnUpdateCmdUI(CFrameWnd* pTarget, BOOL bDisableIfNoHandler)
{
    CDialogBar::OnUpdateCmdUI(pTarget, FALSE);
}
相关文章
相关标签/搜索