Visual C++中自绘菜单的实现(7)
if(lpItem->uID==0)//分隔条
{
rect.top =rect.Height()/2+rect.top ;
rect.bottom =rect.top +2;
rect.left +=2;
rect.right -=2;
dc.Draw3dRect(rect,RGB(64,0,128),RGB(255,255,255));
}
else
{
//得到当前菜单项目的状态;
BOOL bSelected =lpDIS->itemState & ODS_SELECTED;
BOOL bChecked =lpDIS->itemState & ODS_CHECKED;
BOOL bGrayed =lpDIS->itemState & ODS_GRAYED;
BOOL bHasImage =(lpItem->uIndex!=-1);
//设定菜单文本的区域
CRect rtText(rect.left+m_szImage.cx+4+2, rect.top,rect.right ,rect.bottom );
rtText.InflateRect(-2,-2);
//绘制菜单位图
DrawMenuItemImage(&dc,rect,bSelected,bChecked,bGrayed,bHasImage,lpItem);
//绘制菜单文本
TextMenu(&dc,rect,rtText,bSelected,bGrayed,lpItem);
}
dc.Detach();
}
////////////////////////////////////////////////////////////改变菜单风格
//注意第二个参数:FALSE:表示pMenu指向的不是主框架菜单
void CMenuEx::ChangeStyle(CMenu *pMenu,CToolBar *pToolBar,BOOL bIsMainMenu)
{
ASSERT(pMenu);
TRACE("ChangeStyle
"); LPMENUITEM lpItem;
CMenu *pSubMenu;
int m,nPosition=0; //该变量用来绘制纵向位图的位置
int inx;
UINT idx,x;
for(int i=(int)pMenu->GetMenuItemCount()-1 ;i>=0; i--)
{
//得到菜单的信息
lpItem =new MENUITEM;
lpItem->uID =pMenu->GetMenuItemID(i);
if(!bIsMainMenu) //不是第一级菜单
lpItem->uPositionImageLeft =-1;//上下文菜单不支持纵向位图
else
lpItem->uPositionImageLeft =nPosition;
if(lpItem->uID >0)
{
if(bIsMainMenu)
nPosition +=m_szImage.cy+4;
//保存菜单文本
pMenu->GetMenuString(i,lpItem->strText,MF_BYPOSITION);
//由工具栏位图中寻找菜单项的位图,如果没有则uIndex为-1
lpItem->uIndex =-1;
if(pToolBar)
{
for(m=0; m<(pToolBar->GetToolBarCtrl().GetButtonCount()) ;m++)
{
pToolBar->GetButtonInfo(m,idx,x,inx);