Professional UI Solutions
Site Map   /  Register
 
 

Forum

Please Log In to post a new message or reply to an existing one. If you are not registered, please register.

NOTE: Some forums may be read-only if you are not currently subscribed to our technical support services.

Forums » Prof-UIS Tech Support » Message routing from CExtToolControlBar in CExtControlBar docked in a MDI child window Collapse All
Subject Author Date
Paul Boswell Nov 28, 2008 - 3:01 PM

I have a CExtToolControlBar in a CWnd in a CExtControlBar (like the Open GL sample app). The CExtControlBar is docked in an MDI child window.


When the CExtControlBar is docked in the child window, the enabled/disabled state of the toolbar buttons is determined by the corresponding ON_UPDATE_COMMAND_UI functions in the child window (like normal). However, when the CExtControlBar is undocked, the buttons all go disabled.


It seems unusual that the buttons go disabled when the control bar is undocked. Any idea how to fix this?


Thanks.

Technical Support Dec 1, 2008 - 10:14 AM

Please add the following properties into your CWnd-derived class:

protected:
            bool m_bEnabledControlBarUpdate:1, m_bInConrolBarUpdate:1;

And initialize them in constructor(s):
   : m_bEnabledControlBarUpdate( false )
            , m_bInConrolBarUpdate( false )

The m_bEnabledControlBarUpdate property should be set to true in the PreSubclassWindow() virtual method:
void CExtResizableDialog::PreSubclassWindow() 
{
            CWnd::PreSubclassWindow();
            m_bEnabledControlBarUpdate = true;
}

It should be set to false in the PreSubclassWindow() virtual method:
void CExtResizableDialog::PostNcDestroy()
{
            m_bEnabledControlBarUpdate = false;
            CWnd::PostNcDestroy();
}

The WindowProc() virtual method should invoke the CExtControlBar::DoCustomModeUpdateControlBars() static method which does command updating invocations:
LRESULT CExtResizableDialog::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) 
{
bool bUpdateBarsOnThisMsg = false;
            if( m_bEnabledControlBarUpdate )
            {
                        CWinApp * pApp = AfxGetApp();
                        ASSERT( pApp != NULL );
                        BOOL bIdleMsg = pApp->IsIdleMessage(
#if _MFC_VER < 0x700
                                    &pApp->m_msgCur
#else
                                    &(::AfxGetThreadState()->m_msgCur)
#endif
                                    );
                        if( bIdleMsg )
                                    bUpdateBarsOnThisMsg = true;
            }

HWND hWndThis = m_hWnd;
LRESULT lResult = CWnd::WindowProc(message, wParam, lParam);
            if(                     hWndThis == NULL
                        ||           ( ! ::IsWindow(hWndThis) )
                        )
                        bUpdateBarsOnThisMsg = false;

            if(                     bUpdateBarsOnThisMsg
                        &&        ( ! m_bInConrolBarUpdate )
                        )
            {
                        m_bInConrolBarUpdate = true;
                        CExtControlBar::DoCustomModeUpdateControlBars( this );
                        m_bInConrolBarUpdate = false;
            }
            return lResult;
}


Paul Boswell Dec 1, 2008 - 7:49 AM

I take that back - that didn’t completely fix the problem.


Now, at least the command routing (of the buttons in the CExtToolControlBart) goes to its parent CWnd. However, it doesn’t go beyond that. For example, when handling the OnUpdateCommandUI for the toolbar buttons, any change to the state of the buttons in the rest of the app doesn’t change the state of the buttons in the said toolbar.

Paul Boswell Dec 1, 2008 - 6:44 AM

Figured it out - I needed to add the line:


(CExtToolControlBar).m_bPresubclassDialogMode = true;

Technical Support Dec 1, 2008 - 10:33 AM

Yes, that’s right. The improvement we suggested in our previous answer will do the guaranteed command processing in the same way like MFC does in frame windows.

Paul Boswell Dec 1, 2008 - 8:08 AM

I take that back - that didn’t completely fix the problem.


 


Now, at least the command routing (of the buttons in the CExtToolControlBart) goes to its parent CWnd. However, it doesn’t go beyond that. For example, when handling the OnUpdateCommandUI for the toolbar buttons, any change to the state of the buttons in the rest of the app doesn’t change the state of the buttons in the said toolbar.

Paul Boswell Dec 1, 2008 - 11:30 AM

Perfect - that’s just what I needed. Thanks a lot!