0

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;
                }
            }
        }
    }
...
}
pusheax
  • 123
  • 3
  • 10
  • *"So I need function like `bool CWnd::isMessageIdInMessageMap(int id)`."* - Why? Simply call `OnCmdMsg` and have the framework deal with message handler lookup. If no `CmdTarget` handles a particular message, it returns `false`. Please read [Command Routing](https://msdn.microsoft.com/en-us/library/shfzay75.aspx). Regardless of that, your question is in dire need of editing. As posted, it's hard to tell, what you are really looking for. – IInspectable Dec 18 '15 at 12:49
  • I'm looking for function CWnd::isMessageIdInMessageMap(int id) without side effects. I don't want to call OnCmdMsg because it has side effects like enabling cmd - it's visible to user. – pusheax Dec 18 '15 at 12:51
  • Yes, that's what your question says. And I asked you to clarify, **why** you think, that this would be helpful. – IInspectable Dec 18 '15 at 12:52
  • I have 200 handlers for m_childWindow and I don't want to insert code in each one of them to diable UI control. I want to do it in one place. – pusheax Dec 18 '15 at 12:54
  • This doesn't help to clarify, what you are really after. Please update your question, so that it contains all relevant information. Right now, it seems like you have decided to go for the wrong solution, and now need help with that. I doubt this is a solution to your actual problem. Without knowing, what you are really trying to do, it's hard to tell, though. – IInspectable Dec 18 '15 at 13:00

1 Answers1

0

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...

xMRi
  • 14,982
  • 3
  • 26
  • 59