I would like to turn the "Hide" [X] button in my CExtControlBars/CExtDynamicControlBars into a real "Close" button. There have been several previous discussions on this in this forum, and I want to verify that the following steps are what is required to do this:
1) Derive a class from <!--StartFragment -->CExtBarNcAreaButtonClose to override the OnNcAreaClicked method.
2) Derive a class from CExtControlBar to override the OnNcAreaButtonsReinitialize method. Insert my derived "Close" class instead of CExtBarNcAreaButtonClose.
3) Possibly override the OnDbsCreateTabbedBarInstance in my main frame in order to return one of my derived classes instead of the control bar class it returns:
CExtDynamicTabbedControlBar *
CMainFrame::OnDbsCreateTabbedBarInstance() const
{
ASSERT( this != NULL );
CExtDynamicTabbedControlBar * pBar =
new C_YOUR_DynamicTabbedControlBar;
return pBar;
}
4) Add this method to my main frame class:
<!--StartFragment -->
#include "AfxPriv.h"
#include "../Src/ExtDockBar.h"
#include "../Src/ExtControlBarTabbedFeatures.h"
. . .
void CMainFrame::_RemovePanel(
CExtControlBar * pBar
)
{
CMiniDockFrameWnd * pMiniFrame = NULL;
if( pBar->IsFloating() )
{
pMiniFrame =
DYNAMIC_DOWNCAST(
CMiniDockFrameWnd,
pBar->GetDockingFrame()
);
ASSERT_VALID( pMiniFrame );
}
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 );
}
#endif
if( pBar->m_pDockBar->
IsKindOf(
RUNTIME_CLASS( CExtDockBar )
)
)
{
#if (!defined __EXT_MFC_NO_TAB_CONTROLBARS)
if( pBar->m_pDockBar->
IsKindOf(
RUNTIME_CLASS(
CExtDockDynTabBar
)
)
)
{
CExtDynTabControlBar * pDynTabbedBar =
STATIC_DOWNCAST(
CExtDynTabControlBar,
pBar->m_pDockBar->GetParent()
);
LONG nIdx =
pDynTabbedBar->FindControlBar( pBar );
if( nIdx >= 0 )
{
LONG nSel =
pDynTabbedBar->
GetSwitcherSelection();
if( nIdx != nSel )
pDynTabbedBar->
SetSwitcherSelection( nIdx );
pDynTabbedBar->RemoveSelFromSwitcher();
if( pDynTabbedBar->
GetSwitcherItemCount() > 0
)
pDynTabbedBar->
SetSwitcherSelection(0);
pDynTabbedBar->
OnNcAreaButtonsReinitialize();
}
}
#endif
VERIFY(
((CExtDockBar *)pBar->m_pDockBar)->
RemoveControlBar( pBar, -1, 0, false )
);
}
else
{
VERIFY(
pBar->m_pDockBar->RemoveControlBar(pBar)
);
}
} // else from if( pBar->IsFloating() )
RemoveControlBar( pBar );
pBar->m_pDockSite = NULL;
pBar->m_pDockBar = NULL;
if( pMiniFrame != NULL )
pMiniFrame->DestroyWindow();
else
pBar->DestroyWindow();
CExtDockBar::_OptimizeCircles( this);
RecalcLayout();
}
5) Inside my CExtBarNcAreaButtonClose::OnButtonClose method, if CExtBarNcAreaButtonClose::OnButtonClose() returns true, call CMainFrame::_RemoveBar() on the button’s parent.
This seems like a lot of work, is there an easier way?
Thanks.