关于自画菜单的问题(200分)

  • 主题发起人 主题发起人 dongxuzhao
  • 开始时间 开始时间
D

dongxuzhao

Unregistered / Unconfirmed
GUEST, unregistred user!
兄弟想做一个完全自画的菜单,可是总带有一个白色边框,请问如何才能去掉它.我试了几种方
法,但效果不好,请大侠们帮忙了.
 
你是怎么个自画的?
 
To wind2000:
在DrawItem中用CopyRect将BMP图贴上去的.
 
我有一Delphi 6作的菜单,超级COOL,目前在网上从未有过,小弟刚刚完成,
xsxdelphi@sohu.com索取全部源代码,记得,一性感美女图片交换!
基本原理:
MainMenu1.OwnerDraw:=true;
AdvancedDrawItem(..)
用到的API函数
WindowFromDC()
GetDC()
GetWindowDC()

 
很久以前的一个东东,写的很乱,你留下mail,给你 E 过去。
----------
源码:
unit Unit1;

interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Menus, jpeg, ExtCtrls, StdCtrls, Buttons;

type
TForm1 = class(TForm)
MainMenu1: TMainMenu;
main1: TMenuItem;
caption1: TMenuItem;
caption2: TMenuItem;
caption3: TMenuItem;
caption4: TMenuItem;
caption5: TMenuItem;
caption6: TMenuItem;
Image1: TImage;
caption61: TMenuItem;
caption81: TMenuItem;
caption62: TMenuItem;
caption63: TMenuItem;
caption64: TMenuItem;
caption65: TMenuItem;
caption66: TMenuItem;
procedure caption1MeasureItem(Sender: TObject; ACanvas: TCanvas;
var Width, Height: Integer);
procedure caption2MeasureItem(Sender: TObject; ACanvas: TCanvas;
var Width, Height: Integer);
procedure caption3MeasureItem(Sender: TObject; ACanvas: TCanvas;
var Width, Height: Integer);
procedure caption4MeasureItem(Sender: TObject; ACanvas: TCanvas;
var Width, Height: Integer);
procedure caption5MeasureItem(Sender: TObject; ACanvas: TCanvas;
var Width, Height: Integer);
procedure caption6MeasureItem(Sender: TObject; ACanvas: TCanvas;
var Width, Height: Integer);
procedure caption1DrawItem(Sender: TObject; ACanvas: TCanvas;
ARect: TRect; Selected: Boolean);
procedure caption2DrawItem(Sender: TObject; ACanvas: TCanvas;
ARect: TRect; Selected: Boolean);
procedure caption3DrawItem(Sender: TObject; ACanvas: TCanvas;
ARect: TRect; Selected: Boolean);
procedure caption4DrawItem(Sender: TObject; ACanvas: TCanvas;
ARect: TRect; Selected: Boolean);
procedure caption5DrawItem(Sender: TObject; ACanvas: TCanvas;
ARect: TRect; Selected: Boolean);
procedure caption6DrawItem(Sender: TObject; ACanvas: TCanvas;
ARect: TRect; Selected: Boolean);
procedure caption61DrawItem(Sender: TObject; ACanvas: TCanvas;
ARect: TRect; Selected: Boolean);
procedure caption81DrawItem(Sender: TObject; ACanvas: TCanvas;
ARect: TRect; Selected: Boolean);
procedure caption62DrawItem(Sender: TObject; ACanvas: TCanvas;
ARect: TRect; Selected: Boolean);
procedure caption64DrawItem(Sender: TObject; ACanvas: TCanvas;
ARect: TRect; Selected: Boolean);
procedure caption63DrawItem(Sender: TObject; ACanvas: TCanvas;
ARect: TRect; Selected: Boolean);
procedure caption66DrawItem(Sender: TObject; ACanvas: TCanvas;
ARect: TRect; Selected: Boolean);
procedure caption65DrawItem(Sender: TObject; ACanvas: TCanvas;
ARect: TRect; Selected: Boolean);
procedure caption61MeasureItem(Sender: TObject; ACanvas: TCanvas;
var Width, Height: Integer);
procedure caption81MeasureItem(Sender: TObject; ACanvas: TCanvas;
var Width, Height: Integer);
procedure caption62MeasureItem(Sender: TObject; ACanvas: TCanvas;
var Width, Height: Integer);
procedure caption64MeasureItem(Sender: TObject; ACanvas: TCanvas;
var Width, Height: Integer);
procedure caption63MeasureItem(Sender: TObject; ACanvas: TCanvas;
var Width, Height: Integer);
procedure caption66MeasureItem(Sender: TObject; ACanvas: TCanvas;
var Width, Height: Integer);
procedure caption65MeasureItem(Sender: TObject; ACanvas: TCanvas;
var Width, Height: Integer);
private
{ Private declarations }
public
procedure DrawItem(Sender: TMenuItem; ACanvas: TCanvas;
ARect: TRect; Selected: Boolean;StrOut:String);
{ Public declarations }
end;

var
Form1: TForm1;
i,ih,ind,iw,irate:integer;
rtemp:trect;
ig1,ig2:integer;
implementation

{$R *.DFM}
procedure TForm1.DrawItem(Sender: TMenuItem; ACanvas: TCanvas;
ARect: TRect; Selected: Boolean;StrOut:String);
var j:integer;
begin
i:=arect.Bottom-arect.Top;
ind:=sender.MenuIndex;
ih:=round(image1.Height/13*ind);
stretchBlt(acanvas.Handle,arect.Left,arect.Top,iw,i,image1.Canvas.Handle,0,ih,image1.Width,round(image1.Height/13),srccopy);
if selected then
begin
acanvas.Font.Color:=clwhite;
rtemp:=arect;
rtemp.Left:=rtemp.Left+iw;
ig1:=round((rtemp.Right-rtemp.Left)/10);
rtemp.Right:=rtemp.Left+ig1;
for j:=0 to 9 do
begin
acanvas.Brush.Color:=rgb(0,0,j*25);
acanvas.FillRect(rtemp);
rtemp.Left:=rtemp.Left+ig1;
rtemp.Right:=rtemp.Left+ig1;
end;
end
else
begin
acanvas.Brush.Color:=cl3dlight;
rtemp:=arect;
rtemp.Left:=rtemp.Left+iw;
acanvas.FillRect(rtemp);
acanvas.Font.Color:=clblack;
end;
acanvas.Brush.Style:=bsclear;
acanvas.TextOut(arect.Left+iw+5,arect.Top,strout);
end;

procedure TForm1.caption1MeasureItem(Sender: TObject; ACanvas: TCanvas;
var Width, Height: Integer);
begin
height:=acanvas.TextHeight('caption1')+5;
width:=acanvas.TextWidth('caption1')+50;
irate:=round(image1.height/(height*13));
iw:=round(image1.width/irate);
width:=width+iw;
end;

procedure TForm1.caption2MeasureItem(Sender: TObject; ACanvas: TCanvas;
var Width, Height: Integer);
begin
height:=acanvas.TextHeight('caption1')+5;
width:=acanvas.TextWidth('caption1')+50;
irate:=round(image1.height/(height*13));
iw:=round(image1.width/irate);
width:=width+iw;
end;

procedure TForm1.caption3MeasureItem(Sender: TObject; ACanvas: TCanvas;
var Width, Height: Integer);
begin
height:=acanvas.TextHeight('caption1')+5;
width:=acanvas.TextWidth('caption1')+5;
irate:=round(image1.height/(height*13));
iw:=round(image1.width/irate);
width:=width+iw;
end;

procedure TForm1.caption4MeasureItem(Sender: TObject; ACanvas: TCanvas;
var Width, Height: Integer);
begin
height:=acanvas.TextHeight('caption1')+5;
width:=acanvas.TextWidth('caption1')+5;
irate:=round(image1.height/(height*13));
iw:=round(image1.width/irate);
width:=width+iw;
end;

procedure TForm1.caption5MeasureItem(Sender: TObject; ACanvas: TCanvas;
var Width, Height: Integer);
begin
height:=acanvas.TextHeight('caption1')+5;
width:=acanvas.TextWidth('caption1')+5;
irate:=round(image1.height/(height*13));
iw:=round(image1.width/irate);
width:=width+iw;
end;

procedure TForm1.caption6MeasureItem(Sender: TObject; ACanvas: TCanvas;
var Width, Height: Integer);
begin
height:=acanvas.TextHeight('caption1')+5;
width:=acanvas.TextWidth('caption1')+5;
irate:=round(image1.height/(height*13));
iw:=round(image1.width/irate);
width:=width+iw;
end;

procedure TForm1.caption1DrawItem(Sender: TObject; ACanvas: TCanvas;
ARect: TRect; Selected: Boolean);
begin
DrawItem(TMenuItem(Sender),ACanvas,ARect,Selected,'234643623562346');
end;

procedure TForm1.caption2DrawItem(Sender: TObject; ACanvas: TCanvas;
ARect: TRect; Selected: Boolean);
begin
DrawItem(TMenuItem(Sender),ACanvas,ARect,Selected,'Caption2');
end;

procedure TForm1.caption3DrawItem(Sender: TObject; ACanvas: TCanvas;
ARect: TRect; Selected: Boolean);
begin
DrawItem(TMenuItem(Sender),ACanvas,ARect,Selected,'Caption3');
end;

procedure TForm1.caption4DrawItem(Sender: TObject; ACanvas: TCanvas;
ARect: TRect; Selected: Boolean);
begin
DrawItem(TMenuItem(Sender),ACanvas,ARect,Selected,'Caption4');
end;

procedure TForm1.caption5DrawItem(Sender: TObject; ACanvas: TCanvas;
ARect: TRect; Selected: Boolean);
begin
DrawItem(TMenuItem(Sender),ACanvas,ARect,Selected,'Caption5');
end;

procedure TForm1.caption6DrawItem(Sender: TObject; ACanvas: TCanvas;
ARect: TRect; Selected: Boolean);
begin
DrawItem(TMenuItem(Sender),ACanvas,ARect,Selected,'Caption6');
end;

procedure TForm1.caption61DrawItem(Sender: TObject; ACanvas: TCanvas;
ARect: TRect; Selected: Boolean);
begin
DrawItem(TMenuItem(Sender),ACanvas,ARect,Selected,'Caption7');
end;

procedure TForm1.caption81DrawItem(Sender: TObject; ACanvas: TCanvas;
ARect: TRect; Selected: Boolean);
begin
DrawItem(TMenuItem(Sender),ACanvas,ARect,Selected,'Caption8');
end;

procedure TForm1.caption62DrawItem(Sender: TObject; ACanvas: TCanvas;
ARect: TRect; Selected: Boolean);
begin
DrawItem(TMenuItem(Sender),ACanvas,ARect,Selected,'Caption9');
end;

procedure TForm1.caption64DrawItem(Sender: TObject; ACanvas: TCanvas;
ARect: TRect; Selected: Boolean);
begin
DrawItem(TMenuItem(Sender),ACanvas,ARect,Selected,'Caption10');
end;

procedure TForm1.caption63DrawItem(Sender: TObject; ACanvas: TCanvas;
ARect: TRect; Selected: Boolean);
begin
DrawItem(TMenuItem(Sender),ACanvas,ARect,Selected,'Caption11');
end;

procedure TForm1.caption66DrawItem(Sender: TObject; ACanvas: TCanvas;
ARect: TRect; Selected: Boolean);
begin
DrawItem(TMenuItem(Sender),ACanvas,ARect,Selected,'Caption12');
end;

procedure TForm1.caption65DrawItem(Sender: TObject; ACanvas: TCanvas;
ARect: TRect; Selected: Boolean);
begin
DrawItem(TMenuItem(Sender),ACanvas,ARect,Selected,'Caption13');
end;

procedure TForm1.caption61MeasureItem(Sender: TObject; ACanvas: TCanvas;
var Width, Height: Integer);
begin
height:=acanvas.TextHeight('caption1')+5;
width:=acanvas.TextWidth('caption1')+5;
irate:=round(image1.height/(height*13));
iw:=round(image1.width/irate);
width:=width+iw;
end;

procedure TForm1.caption81MeasureItem(Sender: TObject; ACanvas: TCanvas;
var Width, Height: Integer);
begin
height:=acanvas.TextHeight('caption1')+5;
width:=acanvas.TextWidth('caption1')+5;
irate:=round(image1.height/(height*13));
iw:=round(image1.width/irate);
width:=width+iw;
end;

procedure TForm1.caption62MeasureItem(Sender: TObject; ACanvas: TCanvas;
var Width, Height: Integer);
begin
height:=acanvas.TextHeight('caption1')+5;
width:=acanvas.TextWidth('caption1')+5;
irate:=round(image1.height/(height*13));
iw:=round(image1.width/irate);
width:=width+iw;
end;

procedure TForm1.caption64MeasureItem(Sender: TObject; ACanvas: TCanvas;
var Width, Height: Integer);
begin
height:=acanvas.TextHeight('caption1')+5;
width:=acanvas.TextWidth('caption1')+5;
irate:=round(image1.height/(height*13));
iw:=round(image1.width/irate);
width:=width+iw;
end;

procedure TForm1.caption63MeasureItem(Sender: TObject; ACanvas: TCanvas;
var Width, Height: Integer);
begin
height:=acanvas.TextHeight('caption1')+5;
width:=acanvas.TextWidth('caption1')+5;
irate:=round(image1.height/(height*13));
iw:=round(image1.width/irate);
width:=width+iw;
end;

procedure TForm1.caption66MeasureItem(Sender: TObject; ACanvas: TCanvas;
var Width, Height: Integer);
begin
height:=acanvas.TextHeight('caption1')+5;
width:=acanvas.TextWidth('caption1')+5;
irate:=round(image1.height/(height*13));
iw:=round(image1.width/irate);
width:=width+iw;
end;

procedure TForm1.caption65MeasureItem(Sender: TObject; ACanvas: TCanvas;
var Width, Height: Integer);
begin
height:=acanvas.TextHeight('caption1')+5;
width:=acanvas.TextWidth('caption1')+5;
irate:=round(image1.height/(height*13));
iw:=round(image1.width/irate);
width:=width+iw;
end;
end.
 
感觉可能跟你的图片有关,你将图片的格式、大小和你的部分关键代码贴出来大家帮你调一调!
 
sfply@sfply.net
兄弟,来一份
 
我做了一个修改Delphi IDE主菜单的东东,是一个控件包,安装后可以改变IDE的控件面板
为多行显示,同时增加一个菜单项用来设置菜单的背景图片,可以在Delphi的IDE的主菜单
中画出图片出来,源码在http://aizb.6to23.com有下载!
 
看看菜单的源代码机就明白啦,受那个自画的cliprect限制,重载菜单的绘图事件
 
各位大侠,我想w12345678说的对,自画菜单一定受一个区域限制,我的Email是
zhaodongxu@yahoo.com.cn,麻烦给发个Demo,小弟不胜感谢.
 
经各位指点,现在效果好多了.但MenuAnimation必须设成[maNone],否则
WindowFromDC得不到Handle,请写过类似程序的大虾再指点一下.
 
问题解决了,多谢各位.
 
多人接受答案了。
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
I
回复
0
查看
692
import
I
后退
顶部