mfccontrolscwnd

How to check if CWnd message map contains message id without handling message?


ParentWnd contains mfc control called modeOfOperation (drop down list). When modeOfOperation is Normal everything is normal. We added new modeOfOperation=Extreme. When modeOfOperation is Extreme I want to disable 90% of existing ParentWnd controls because they don't work in Extreme mode. I have existing codebase with hundreds of UI controls. I want to find one place in code to disable 90% of them without hurting rest of functionality.

I know that 90% of UI controls that I need to disable are in several child windows. One of them is m_childWindow1. I need to tell if given message is is handled by m_childWindow1,...,m_childWindowN.

So ParentWnd routes messages to childWindow. I want to override childWindow handler in case when given message is handled by childWindow. So I need function like bool CWnd::isMessageIdInMessageMap(int id).

BOOL ParentWnd::OnCmdMsg( UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo ) 
{
if ( nCode == CN_UPDATE_COMMAND_UI )
    {
        CWnd *contents = m_childWindow1->getContents();
        if( contents )
            {
            if( contents->OnCmdMsg( nID, nCode, pExtra, pHandlerInfo ) ) 
                {
                //I want to enter additional code here
                //But I don't want to call contents->OnCmdMsg
                return true;
                }
            }
        }
    }
...
}

Solution

  • Simply use the existing functions (OnCmdMsg).

    Create your own CCmdUI object (overwrite the Enable... functions if required) pass is as pExtra argument to OnCmdMsg and you know after the call if the was a handler or not.

    There are no side effects...