【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);
}
相關文章
相關標籤/搜索