The top level menu is the menu bar. This is the CExtMenuControlBar
class in Prof-UIS. The CExtMenuControlBar
menu bar control is based on the CExtToolControlBar
toolbar control. The menu bar implements the top menu level as a set of toolbar items with submenus. The toolbar/menu bar buttons are instances of the CExtBarButton
objects. You need to code your CExtBarButton
-derived class which paints text using some preferred text color and make the menu bar using your toolbar buttons. Here is how your menu bar button class should look like:
class CYourMenuBarButton : public CExtBarButton
{
public:
CYourMenuBarButton(
CExtToolControlBar * pBar = NULL,
UINT nCmdID = ID_SEPARATOR,
UINT nStyle = 0
)
: CExtBarButton( pBar, nCmdID, nStyle )
{
}
virtual ~CYourMenuBarButton()
{
}
void CExtBarButton::PaintCompound(
CDC & dc,
bool bPaintParentChain,
bool bPaintChildren,
bool bPaintOneNearestChildrenLevelOnly
)
{
ASSERT_VALID( this );
ASSERT_VALID( (&dc) );
ASSERT( dc.GetSafeHdc() != NULL );
CExtToolControlBar * pBar = GetBar();
ASSERT_VALID( pBar );
if( ! IsPaintAble( dc ) )
return;
if( AnimationClient_StatePaint( dc ) )
return;
if( bPaintParentChain )
PaintParentChain( dc );
CWnd * pCtrl = CtrlGet();
if( ( pCtrl != NULL )
&& ( ( ! m_bVertDocked )
|| GetCtrlVisibleVertically()
)
)
return;
CRect rcArea( m_ActiveRect );
if( rcArea.right <= rcArea.left
|| rcArea.bottom <= rcArea.top
)
return;
if( (! IsVisible() )
|| (GetStyle() & TBBS_HIDDEN) != 0
|| (! dc.RectVisible(&m_ActiveRect) )
)
return;
bool bDockSiteCustomizeMode =
pBar->_IsDockSiteCustomizeMode();
bool bPushed =
( IsPressed() && (!bDockSiteCustomizeMode) )
? true : false;
bool bEnabled =
( IsDisabled() && (!bDockSiteCustomizeMode) )
? false : true;
bool bHover =
( IsHover() && (!bDockSiteCustomizeMode) )
? true : false;
if( (! bDockSiteCustomizeMode )
&& (! GetBar()->IsForceHoverWhenMenuTracking() )
)
{
if( CExtToolControlBar::g_bMenuTracking
|| CExtPopupMenuWnd::IsMenuTracking()
)
bHover = false;
else if( !bHover )
bHover = IsPressedTracking();
//if( bPushed && bHover && IsPressedTracking() )
//bHover = false;
} // if( ! bDockSiteCustomizeMode ...
bool bIndeterminate =
( IsIndeterminate() && (!bDockSiteCustomizeMode) )
? true : false;
CExtSafeString sText = GetText();
CExtCmdIcon * pIcon = GetIconPtr();
CExtCmdIcon * pIconLarge = NULL;
if( pIcon != NULL
&& (! pIcon->IsEmpty() )
&& IsLargeIcon()
)
{
CSize _sizeIcon = pIcon->GetSize();
_sizeIcon.cx *= 2;
_sizeIcon.cy *= 2;
pIconLarge = new CExtCmdIcon;
if( pIconLarge->CreateScaledCopy(
*pIcon,
_sizeIcon
)
)
pIcon = pIconLarge;
#ifdef _DEBUG
else
{
ASSERT( FALSE );
}
#endif // _DEBUG
}
bool bPaintAsDropDown = IsPaintDropDown();
bool bHorz = IsHorzBarOrientation();
HFONT hFont =
(HFONT) pBar
-> OnGetToolbarFont( ! bHorz, false )
-> GetSafeHandle();
CExtPaintManager::PAINTPUSHBUTTONDATA _ppbd(
this,
bHorz,
rcArea,
sText,
pIcon,
true,
bHover,
bPushed,
bIndeterminate,
bEnabled,
m_bDrawBorder,
false,
false,
0,
hFont,
bPaintAsDropDown,
0,
(!bEnabled) || ( bEnabled && (!bHover) && (!bPushed) )
);
_ppbd.m_rcBorderSizes = OnQueryBorderSizes( bHorz );
_ppbd.m_nIconAlignment = OnQueryAlignmentIcon( bHorz );
_ppbd.m_nTextAlignment = OnQueryAlignmentText( bHorz );
_ppbd.m_rcIconMargins = OnQueryMarginsIcon( bHorz );
_ppbd.m_rcTextMargins = OnQueryMarginsText( bHorz );
if( OnQueryMaxButtonWidth( bHorz ) >= 0 )
_ppbd.m_bWordBreak = true;
if( GetSeparatedDropDown() )
{
_ppbd.m_bSeparatedDropDown = true;
_ppbd.m_bHoverDropDown = m_bDropDownHT;
if( ( m_bDropDownHT /*|| CExtToolControlBar::g_bMenuTracking*/ )
&& bPushed
&& ( ! bDockSiteCustomizeMode )
)
{
//_ppbd.m_bPushed = false;
_ppbd.m_bPushedDropDown = true;
}
}
_ppbd.m_clrCustomAccentEffectForIcon =
OnQueryCustomAccentEffectForIcon( dc );
bool bChecked =
( (GetStyle()&TBBS_CHECKED) != 0 )
? true
: false;
_ppbd.m_bChecked = bChecked;
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// TO-DO: specify your desired text colors here
//
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
_ppbd.m_clrForceTextNormal = RGB(255,0,0);
_ppbd.m_clrForceTextHover = RGB(255,0,0);
_ppbd.m_clrForceTextPressed = RGB(255,0,0);
_ppbd.m_clrForceTextDisabled = RGB(255,0,0);
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
pBar->PmBridge_GetPM()->PaintPushButton( dc, _ppbd );
#if (!defined __EXT_MFC_NO_CUSTOMIZE)
CExtCustomizeSite * pSite = pBar->GetCustomizeSite();
if( pSite != NULL
&& pSite->IsCustomizeMode()
&& pSite->CustomizedNodeGet() != NULL
&& pSite->CustomizedNodeGet() == GetCmdNode( false )
)
{
pBar->PmBridge_GetPM()->PaintDragSourceRect(
dc,
rcArea
);
}
#endif // (!defined __EXT_MFC_NO_CUSTOMIZE)
if( pIconLarge != NULL )
delete pIconLarge;
if( bPaintChildren )
PaintChildren( dc, bPaintOneNearestChildrenLevelOnly );
}
};
And here is how your menu bar class should look like:
class CYourMenuBar : public CExtMenuControlBar
{
public:
CYourMenuBar()
{
}
virtual ~CYourMenuBar()
{
}
CExtBarButton * OnCreateBarCommandBtn( UINT nCmdID, UINT nStyle = 0 )
{
ASSERT_VALID( this );
CExtBarButton * pTBB = new CYourMenuBarButton( this, nCmdID, nStyle );
ASSERT_VALID( pTBB );
return pTBB;
}
};