怎样制作 Office XP 类型的菜单?(100分)

  • 主题发起人 主题发起人 HammerLi
  • 开始时间 开始时间
H

HammerLi

Unregistered / Unconfirmed
GUEST, unregistred user!
我想知道 Office XP 中那种风格的菜单是怎样实现的?大家帮忙,谢谢!
 
用第三方控件<br><br>试试XPMENU,再研究源码,好长,我是没看完的
 
xpMenu 控件可做到
 
有这样的组件,我用是XPmenu,你可以在网上找一找,一定能找到的
 
用XPMenu,详情访问http://www.shagrouni.com
 
TeThemeEngine<br>可切换多种风格,含Office XP .
 
都不好,最好的是TooBar2000+增强包。菜单阴影效果非常好!
 
非常感谢大家的建议,但是我的问题的本意是希望得到具体的实现方法,而不是简单的依<br>靠第三方工具,我想这样的讨论才能提高我们的变成水平吧!希望有兴趣的朋友一起来探<br>讨!
 
没有人对这个问题感兴趣吗?
 
菜单的字画属性设为真<br>//此过程为菜单项的高级自画列表事件代码<br>procedure TForm1.menuFileNewAdvancedDrawItem(Sender: TObject; ACanvas: TCanvas; ARect: TRect; State: TOwnerDrawState);<br>var<br>&nbsp; MenuHeight,BmpPos:Integer;//菜单项的高度;菜单中所画图标的边距<br>&nbsp; TempMenuItem:TMenuItem; //调用此过程的菜单项<br>&nbsp; DrawIco:TIcon; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//图标对象,用以画出菜单项的图标<br>&nbsp; TempRect:TRect; &nbsp; &nbsp; &nbsp; &nbsp;//临时的矩形区域,程序中多次使用<br>&nbsp; ShowCaption:String; &nbsp; &nbsp;//菜单项的标题<br>&nbsp; ImageList:TCustomImageList; //菜单项所使用的图标列表控件<br>begin<br>TempMenuItem:=(Sender as TMenuItem);//获取调用此过程的菜单项<br>ShowCaption:=TempMenuItem.Caption; &nbsp;//获取菜单标题<br>DrawIco:=TIcon.Create; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//创建图标对象<br><br>with ACanvas,ARect do<br>&nbsp; begin<br>&nbsp; &nbsp; MenuHeight:=25; //此数值与在 OnMeasureItem 事件中设置的Height属性值相同<br>&nbsp; &nbsp; BmpPos:=(MenuHeight-16) div 2;{<br>&nbsp; &nbsp; &nbsp; 计算所画的图标边距,所显示的图标尺寸一般为16,所以此处取值也为16,<br>&nbsp; &nbsp; &nbsp; 可根据实际更改此数值。}<br><br>&nbsp; &nbsp; Brush.Color :=RGB(255,251,247);//设置菜单的背景色,此处设为奶白色,可根据需要更改<br>&nbsp; &nbsp; FillRect(Arect); //填充背景<br>&nbsp; &nbsp; Brush.Color:=RGB(223,215,207);//设置菜单项图标区域的背景色,可根据需要更改<br>&nbsp; &nbsp; TempRect:=Rect(Left,Top,MenuHeight,Bottom);//设置图标背景的矩形区域<br>&nbsp; &nbsp; FillRect(TempRect);//填充图标背景<br><br>&nbsp; &nbsp; if TempMenuItem.Caption='-' then<br>&nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; Pen.Color:=RGB(175,183,207);<br>&nbsp; &nbsp; &nbsp; &nbsp; MoveTo(Left+MenuHeight+5,Top+((Bottom-Top) div 2)-1);<br>&nbsp; &nbsp; &nbsp; &nbsp; LineTo(Right,Top+((Bottom-Top) div 2)-1);<br>&nbsp; &nbsp; &nbsp; &nbsp; Pen.Color:=clWhite;//RGB(175,183,207);<br>&nbsp; &nbsp; &nbsp; &nbsp; MoveTo(Left+MenuHeight+5,Top+((Bottom-Top) div 2));<br>&nbsp; &nbsp; &nbsp; &nbsp; LineTo(Right,Top+((Bottom-Top) div 2));<br>&nbsp; &nbsp; &nbsp; &nbsp; Exit;<br>&nbsp; &nbsp; &nbsp; end;{以上程序判断该菜单项是否为分隔线,<br>&nbsp; &nbsp; &nbsp; 如果是,则画出分隔线样式后退出此过程。可根据需要更改其效果}<br><br>&nbsp; &nbsp; ImageList:=TempMenuItem.GetImageList;//获取所使用的图标列表控件<br>&nbsp; &nbsp; if ImageList&lt;&gt;nil then //如果主菜单关联了图标列表控件<br>&nbsp; &nbsp; &nbsp; if (TempMenuItem.Imageindex&lt;&gt;-1) then //如果该菜单项指定了图标<br>&nbsp; &nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ImageList.GetIcon(TempMenuItem.ImageIndex,DrawIco);//从图标列表控件中获取图标<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if TempMenuItem.Checked then //如果该菜单项有复选标记则画出一个蓝色框<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; brush.Color:=RGB(175,183,207);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Pen.Color :=clBlack;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; RoundRect(Left+1,Top+2,MenuHeight-2,Bottom-2,0,0);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; &nbsp; &nbsp; end<br>&nbsp; &nbsp; &nbsp; else //如果该菜单项没有指定图标<br>&nbsp; &nbsp; &nbsp; &nbsp; if TempMenuItem.Checked then Imagelist.GetIcon(11,DrawIco);<br>&nbsp; &nbsp; &nbsp; &nbsp; {如果菜单项有复选标记,则从图标列表控件中获取一个表示复选的图标<br>&nbsp; &nbsp; &nbsp; &nbsp; 数字11是该图标的索引号,可根据实际更改;如没有该图标,可将这两句删除}<br><br>&nbsp; &nbsp; if (odSelected in State) {and (Not (odDisabled in State))} then<br>&nbsp; &nbsp; {如果该菜单项处于被选择状态,则画出以下选择样式<br>&nbsp; &nbsp; 注释的一句加上的话表示如果菜单项处于无效状态则光标指向时无任何效果}<br><br>&nbsp; &nbsp; &nbsp; begin //以下程序画出一个蓝色框以表示该菜单项处于被选择状态<br>&nbsp; &nbsp; &nbsp; &nbsp; Inc(Left,2);Inc(Top,2);<br>&nbsp; &nbsp; &nbsp; &nbsp; Brush.Style:=bsSolid;<br>&nbsp; &nbsp; &nbsp; &nbsp; brush.Color:=clGray;//RGB(110,120,180);<br>&nbsp; &nbsp; &nbsp; &nbsp; Pen.Color:=clMenu;<br>&nbsp; &nbsp; &nbsp; &nbsp; RoundRect(Left,Top,Right,Bottom,5,5);<br>&nbsp; &nbsp; &nbsp; &nbsp; {以上四句画出蓝色框的阴影}<br><br>&nbsp; &nbsp; &nbsp; &nbsp; brush.Color:=RGB(175,183,207);<br>&nbsp; &nbsp; &nbsp; &nbsp; Dec(Left,2);Dec(Top,2);<br>&nbsp; &nbsp; &nbsp; &nbsp; Dec(Right,2);Dec(Bottom,2);<br>&nbsp; &nbsp; &nbsp; &nbsp; Pen.Color :=clBlack;<br>&nbsp; &nbsp; &nbsp; &nbsp; RoundRect(Left,Top,Right,Bottom,3,3);<br>&nbsp; &nbsp; &nbsp; &nbsp; {以上四句画出蓝色框}<br><br>&nbsp; &nbsp; &nbsp; &nbsp; Draw(BmpPos,Top+BmpPos,DrawIco);<br>&nbsp; &nbsp; &nbsp; &nbsp; //画出图标阴影(我不知道怎样把图标颜色变成灰度,只好原样画上)<br>&nbsp; &nbsp; &nbsp; &nbsp; Dec(BmpPos,1);<br>&nbsp; &nbsp; &nbsp; end;<br><br>&nbsp; &nbsp; Draw (BmpPos,Top+BmpPos,DrawIco);//画出图标<br>&nbsp; &nbsp; DrawIco.Free; &nbsp;//图标已画出,可以释放图标对象<br>&nbsp; &nbsp; TempRect:=Rect(Left+MenuHeight+10,Top,Right,Bottom);//设置菜单标题的矩形区域<br>&nbsp; &nbsp; Brush.Style:=bsClear;//设置画刷的填充样式为透明,这样画出的菜单标题就为透明底色<br>&nbsp; &nbsp; with Font do //根据菜单项的状态设置字体样式<br>&nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; if (odDisabled in State) then Color :=clgray else Color :=clblack;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {设置菜单项在有效或无效状态时的字体颜色,具体的颜色可根据实际更改}<br><br>&nbsp; &nbsp; &nbsp; &nbsp; if TempMenuItem.Default then Style:= Style+[fsBold];<br>&nbsp; &nbsp; &nbsp; &nbsp; {如果菜单项为默认,则设置字体为粗体}<br>&nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; DrawText(Handle,PChar(ShowCaption),-1,TempRect,DT_LEFT or DT_SINGLELINE or DT_VCENTER);<br>&nbsp; &nbsp; {最后画出菜单项的标题}<br>&nbsp; end;<br>end;<br><br><br>//此过程为菜单项的尺寸设置列表事件<br>procedure TForm1.menuFileNewMeasureItem(Sender: TObject; ACanvas: TCanvas;<br>&nbsp; var Width, Height: Integer);<br>begin<br>if TMenuItem(Sender).Caption&lt;&gt;'-' then Height:=25;<br>//如果菜单项不是分隔线则设置其高度,可根据需要更改,更改后注意将高级自画事件中的 MenuHeight 变量设置为相同数值<br>end;<br><br><br>//此过程为主菜单项的高级自画事件,主要是画出一个带阴影的矩形框<br>procedure TForm1.menuFileAdvancedDrawItem(Sender: TObject; ACanvas: TCanvas;<br>&nbsp; ARect: TRect; State: TOwnerDrawState);<br>var<br>&nbsp; TempMenuItem:TMenuItem;<br>&nbsp; TempRect:TRect;<br>&nbsp; ShowCaption:String;<br>begin<br>TempMenuItem:=(Sender as TMenuItem);<br>ShowCaption:=TempMenuItem.Caption;<br>with acanvas,arect do<br>&nbsp; begin<br>&nbsp; &nbsp; FillRect(ARect);<br>&nbsp; &nbsp; Inc(Left,1);<br>&nbsp; &nbsp; <br>&nbsp; &nbsp; if (odSelected in State) then //如果该菜单项处于被选择状态<br>&nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; Brush.Color:=RGB(189,190,189);<br>&nbsp; &nbsp; &nbsp; &nbsp; TempRect:=Rect(Left,Top+3,Right,Bottom);<br>&nbsp; &nbsp; &nbsp; &nbsp; FillRect(TempRect);<br><br>&nbsp; &nbsp; &nbsp; &nbsp; Brush.Color:=RGB(181,182,181);<br>&nbsp; &nbsp; &nbsp; &nbsp; TempRect:=Rect(Left,Top+2,Right-1,Bottom);<br>&nbsp; &nbsp; &nbsp; &nbsp; FillRect(TempRect);<br><br>&nbsp; &nbsp; &nbsp; &nbsp; Brush.Color:=RGB(165,162,165);<br>&nbsp; &nbsp; &nbsp; &nbsp; TempRect:=Rect(Left,Top+1,Right-2,Bottom);<br>&nbsp; &nbsp; &nbsp; &nbsp; FillRect(TempRect);<br>&nbsp; &nbsp; &nbsp; &nbsp; //以上三段分别画出阴影<br><br>&nbsp; &nbsp; &nbsp; &nbsp; Inc(Bottom,5);<br>&nbsp; &nbsp; &nbsp; &nbsp; Pen.Color:=RGB(99,97,99);<br>&nbsp; &nbsp; &nbsp; &nbsp; Brush.Color:=clMenu;<br>&nbsp; &nbsp; &nbsp; &nbsp; RoundRect(Left,Top,Right-3,Bottom,5,5);<br>&nbsp; &nbsp; &nbsp; &nbsp; Dec(Bottom,5);<br>&nbsp; &nbsp; &nbsp; &nbsp; TempRect:=Rect(Left,Bottom,Right,Bottom+5);<br>&nbsp; &nbsp; &nbsp; &nbsp; FillRect(TempRect);<br>&nbsp; &nbsp; &nbsp; &nbsp; //画出边框颜色为灰色的矩形框<br>&nbsp; &nbsp; &nbsp; end;<br>&nbsp; DrawText(Handle,pchar(ShowCaption),-1,ARect,DT_CENTER or DT_SINGLELINE or DT_VCENTER);<br>&nbsp; //最后画出菜单标题<br>&nbsp; end;<br>end;
 
xpmenu很好的
 
Delphi6/70支持XP,自带的例子:../Demos/ActionBands/WorldPad,如果你用的是Delphi7,如果安装了Gexpert,XPMenu那个第三方控件对于ToolBar上的SpeedButton不能做到XP效果,非常奇怪
 
看看dexbar的源代码如果你有时间的话
 
接受答案了.
 
后退
顶部