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 General Discussion » How properly to destroy CExtControlBar? Collapse All
Subject Author Date
Darius Mikalauskas Aug 10, 2006 - 8:55 AM

CExtControlBar object was created dynamically. Button X was subclassed to changed behaviour from "Hide" to "Close". I would like to ask how to destroy CExtControlBar properly?

Thank you in advance
Darius

Technical Support Aug 10, 2006 - 9:31 AM

You can use the following function to destroy the control bar:

#include "../Src/ExtDockBar.h"
#include "../Src/ExtControlBarTabbedFeatures.h"
 

void KillBar(
    CExtControlBar * pBar,
    bool bForceNoOptimizeMode = false // ignore this parameter
    )
{
    ASSERT_VALID( pBar );
    ASSERT_VALID( pBar->m_pDockBar );
    ASSERT_VALID( pBar->m_pDockSite );
CFrameWnd * pDockSite = pBar->m_pDockSite;
    ASSERT( pDockSite->GetSafeHwnd() != NULL );
CMiniDockFrameWnd * pMiniFrame = NULL;
    if( pBar->IsFloating() )
    {
        pMiniFrame = 
            DYNAMIC_DOWNCAST(
                CMiniDockFrameWnd,
                pBar->GetDockingFrame()
                );
        ASSERT_VALID( pMiniFrame );
    } // if( pBar->IsFloating() )
    else
    {
        ASSERT( ! pBar->m_pDockBar->m_bFloating );
#if (!defined __EXT_MFC_NO_TAB_CONTROLBARS)
        if( pBar->AutoHideModeGet() )
        {
            ASSERT_KINDOF( CExtDockBar, pBar->m_pDockBar );
            CExtDynAutoHideArea * pWndAutoHideArea =
                ((CExtDockBar*)pBar->m_pDockBar)->_GetAutoHideArea();
            ASSERT_VALID( pWndAutoHideArea );
            CExtDynAutoHideSlider * pWndSlider =
                pWndAutoHideArea->GetAutoHideSlider();
            ASSERT_VALID( pWndSlider );
            if( (pWndSlider->GetStyle()&WS_VISIBLE) != 0 )
                pWndSlider->SendMessage( WM_CANCELMODE );
            pWndAutoHideArea->RemoveControlBar( pBar, true );
        } // if( pBar->AutoHideModeGet() )
#endif // (!defined __EXT_MFC_NO_TAB_CONTROLBARS)
        if( pBar->m_pDockBar->IsKindOf(RUNTIME_CLASS(CExtDockBar)) )
        {
#if (!defined __EXT_MFC_NO_TAB_CONTROLBARS)
            if( pBar->m_pDockBar->IsKindOf(RUNTIME_CLASS(CExtDockDynTabBar)) )
            {
                CExtDynTabControlBar * pTabbedBar =
                    STATIC_DOWNCAST(
                        CExtDynTabControlBar,
                        pBar->m_pDockBar->GetParent()
                        );
                LONG nIdx = pTabbedBar->FindControlBar( pBar );
                if( nIdx >= 0 )
                {
                    LONG nSel = pTabbedBar->GetSwitcherSelection();
                    if( nIdx != nSel )
                        pTabbedBar->SetSwitcherSelection( nIdx );
                    pTabbedBar->RemoveSelFromSwitcher();
                } // if( nIdx >= 0 )
            } // if( pBar->m_pDockBar->IsKindOf(RUNTIME_CLASS(CExtDockDynTabBar)) )
#endif // (!defined __EXT_MFC_NO_TAB_CONTROLBARS)
            VERIFY(
                ((CExtDockBar *)pBar->m_pDockBar)->
                    RemoveControlBar( pBar, -1, 0, false )
                );
        }
        else
        {
            VERIFY( pBar->m_pDockBar->RemoveControlBar(pBar) );
        }
    } // else from if( pBar->IsFloating() )
    pDockSite->RemoveControlBar( pBar );
    pBar->m_pDockSite = NULL;
    pBar->m_pDockBar = NULL;
    if( pMiniFrame != NULL )
        pMiniFrame->DestroyWindow();
    else
        pBar->DestroyWindow();
    if( ! bForceNoOptimizeMode )
        CExtDockBar::_OptimizeCircles( pDockSite );
}
But we would recommend you use dynamic control bars which can be easily de-allocated using the CExtDynamicBarSite::BarFree() method. Besides dynamic control bars do not have the following restriction that have simple bars: all the bars whose states were saved before should be created before their state is loaded.

Darius Mikalauskas Aug 10, 2006 - 9:48 AM

Thanks- everything is working fine except that place of destroyed control bar is not redrawed when bar is docked (no problems when bar is floating).

Darius

Technical Support Aug 10, 2006 - 10:03 AM

This function is oriented for destroying many control bars with several sequential calls. So if the CWnd::GetParentFrame() method called for each control bar (that should be destroyed) returns a pointer to the main frame window, then you should re-compute the main frame’s layout using CFrameWnd::RecalcLayout() method.

Darius Mikalauskas Aug 10, 2006 - 10:05 AM

Now it working perfectly!
Thank you!