谁要自画菜单边框的代码?(论坛至今还没有答案,XPMenu没有解决的问题) ( 积分: 0 )

  • 主题发起人 主题发起人 xuxiaohan
  • 开始时间 开始时间
X

xuxiaohan

Unregistered / Unconfirmed
GUEST, unregistred user!
等齐10个人,我就将代码贴在这里。
 
等齐10个人,我就将代码贴在这里。
 
[?][?][?][?]
 
那我也来充个数吧。
 
要发就发,不想发就算了
 
?没有够10人
 
在加一个
 
楼主在玩大家啊
 
对不起,少上网,有时间我会详细解释。。。

const
CM_MENUPOP = WM_USER+1;

procedure SubItemDraw(Sender: TObject; ACanvas: TCanvas; ARect: TRect;
State: TOwnerDrawState);
....
procedure cmMenuPop(var msg: Tmessage); message CM_MENUPOP;
...



procedure SubMenuItemDraw(Sender: TObject; ACanvas: TCanvas; ARect: TRect;
State: TOwnerDrawState);
var
s: string;
R: TRect;
Item: TMenuitem;
x, y: integer;
mWnd: Thandle;
DC: HDC;
pt1, pt2: Tpoint;
mm: TMenu;
begin
item:=TMenuitem(sender);
mm:=item.GetParentMenu;
s:=Item.Caption;
if (odSelected in State) and not item.Enabled then exit;
R:=ARect;
if (odSelected in State) and Item.Enabled then
ACanvas.Brush.Color:=clSelected
else
ACanvas.Brush.Color:=clMenuitem;
ACAnvas.FillRect(ARect);
if (odSelected in State) and Item.Enabled then
ACanvas.Brush.Color:=clmsSelect
else
ACanvas.Brush.Color:=clMenuSide;
R.Right:=R.Left+22;
ACAnvas.FillRect(R);
x:=R.Left+2;
y:=R.Top+(R.Bottom-R.Top-dm.mm.height) div 2;
if (mm.Images<>nil) and (Item.ImageIndex<>-1) then
begin
if Item.Enabled then
mm.Images.Draw(ACanvas, x, y, Item.imageIndex)
else
DrawDisabledImage(Acanvas, Bounds(x, y, 18, 18), TMenu(item.Owner).Images,
item.ImageIndex, false);
end;
if item.Checked then dm.mm.Draw(ACanvas, x, y, 7);

R:=ARect;
R.Left:=R.Left+28;
if Item.IsLine then
begin
ACanvas.Pen.Color:=clEnd;
ACanvas.MoveTo(22, R.Top+(R.Bottom-R.Top) div 2);
ACanvas.LineTo(R.Right, R.Top+(R.Bottom-R.Top) div 2);
exit;
end;
ACanvas.Brush.Style:=bsClear;
if Item.Enabled then
ACanvas.Font.Color:=clBlack
else
ACanvas.Font.Color:=clGrayText;
drawText(ACAnvas.Handle, pchar(s), length(s), R, DT_SINGLELINE or DT_VCENTER);
if (odSelected in State) and Item.Enabled then
begin
ACanvas.Pen.Color:=clslEnd;
ACanvas.Rectangle(Arect);
end;

//画菜单的边框;
Dc:=ACanvas.Handle;
mWnd:=WindowFromDc(DC);
if mWnd=0 then
[red]postmessage(application.MainForm.Handle, CM_MENUPOP, 0, integer(item))[/red]
else
begin
getWindowRect(mWnd, R);
Dc:=getWindowDC(mWnd);
MapWindowPoints(0, mWnd, R, 2);
offsetRect(R, 3, 3);
FrameRect(Dc, R, CreateSolidBrush(clDark));
inflateRect(R, -2, -2);
FrameRect(Dc, R, CreateSolidBrush(clEnd));
end;
end;

procedure TfmMain.SubItemDraw(Sender: TObject; ACanvas: TCanvas;
ARect: TRect; State: TOwnerDrawState);
begin
SubMenuItemDraw(sender, ACanvas, Arect, state);
end;

procedure TfmMain.cmMenuPop(var msg: Tmessage);
var
item: TmenuItem;
begin
item:=TMenuitem(msg.LParam);
if item.Count=0 then
with item do
begin
enabled:=not enabled;
enabled:=not enabled;
end;
end;
 
还是老样子,我只见过VCLSkin的源码中解决了这个问题,以前的笔记中发过个VC的。要处理WM_Print和WM_PrintClient消息,好象是这个吧。
 
omvm, 时间:2005-8-22 22:09:13, ID:3176392
还是老样子

晕倒!!!!, omvm, 你有没有试过?
 
to:xuxiaohan 晕死,你帖的代码根本不全啊,这样还不如不要帖!
而且多处都编译不了,DrawDisabledImage应该是个自定义函数吧?你也没帖出来!
郁闷!
 
micronet, 你不懂看我也没有办法? 关键的是那句? 我匆匆忙忙贴出来,就想考考你有没有耐心。
 
关键代码在下面, 其他可以不要。

if mWnd=0 then
postmessage(application.MainForm.Handle, CM_MENUPOP, 0, integer(item))
else
begin
getWindowRect(mWnd, R);
Dc:=getWindowDC(mWnd);
MapWindowPoints(0, mWnd, R, 2);
offsetRect(R, 3, 3);
FrameRect(Dc, R, CreateSolidBrush(clRed));
inflateRect(R, -2, -2);
FrameRect(Dc, R, CreateSolidBrush(clBlue));
end;
end;

procedure TfmMain.cmMenuPop(var msg: Tmessage);
var
item: TmenuItem;
begin
item:=TMenuitem(msg.LParam);
if item.Count=0 then
with item do
begin
enabled:=not enabled;
enabled:=not enabled;
end;
end;
 

Similar threads

D
回复
0
查看
1K
DelphiTeacher的专栏
D
D
回复
0
查看
2K
DelphiTeacher的专栏
D
I
回复
0
查看
705
import
I
S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
后退
顶部