office xp 界面的制作方法!(100分)

  • 主题发起人 主题发起人 guan25
  • 开始时间 开始时间
G

guan25

Unregistered / Unconfirmed
GUEST, unregistred user!
我是一个delphi的初学者!我现在有一段制作windows xp 界面的代码,但是我这个菜鸟不怎么看的懂,所以想请教一下各位大哥哥!能给我一点提示!最好是在各断代码加上注释,和相应的制作方法!
小弟在这里先谢过了!
改日有了成就以后定当重谢!

unit unit1;

interface

uses
windows, messages, sysutils, classes, graphics, controls, forms, dialogs,
menus, imglist;

type
tform1 = class(tform)
toolbarimages: timagelist;
mainmenu: tmainmenu;
filemenu: tmenuitem;
filenewitem: tmenuitem;
fileopenitem: tmenuitem;
filesaveitem: tmenuitem;
filesaveasitem: tmenuitem;
n1: tmenuitem;
fileexititem: tmenuitem;
editmenu: tmenuitem;
editundoitem: tmenuitem;
n2: tmenuitem;
editcutitem: tmenuitem;
editcopyitem: tmenuitem;
editpasteitem: tmenuitem;
n5: tmenuitem;
mieditfont: tmenuitem;
languagemenu: tmenuitem;
languageenglish: tmenuitem;
languagefrench: tmenuitem;
languagegerman: tmenuitem;
helpmenu: tmenuitem;
helpaboutitem: tmenuitem;
popupmenu1: tpopupmenu;
copy1: tmenuitem;
paste1: tmenuitem;
cut1: tmenuitem;
n3: tmenuitem;
selectall1: tmenuitem;
procedure drawitem(sender: tobject; acanvas: tcanvas; arect: trect;
selected: boolean);
procedure formcreate(sender: tobject);
private
procedure menuedrawitemx(xmenu: tmenu);
public
end;
procedure menuedrawitem(sender: tobject; acanvas: tcanvas; arect: trect;
selected: boolean);

var
form1: tform1;

implementation

{$r *.dfm}

procedure tform1.drawitem(sender: tobject; acanvas: tcanvas; arect: trect;
selected: boolean);
begin
menuedrawitem(sender, acanvas, arect, selected);
end;

procedure tform1.menuedrawitemx(xmenu: tmenu);
var
i: integer;
b: tbitmap;
fmenuitem: tmenuitem;
begin
b := tbitmap.create;
b.width := 1;
b.height := 1;
for i := 0 to componentcount - 1 do
if components is tmenuitem then
begin
fmenuitem := tmenuitem(components);
fmenuitem.ondrawitem := drawitem;
if (fmenuitem.imageindex = -1) and
(fmenuitem.bitmap.width = 0) and (xmenu <> nil) then
if fmenuitem.getparentcomponent.name <> xmenu.name then
fmenuitem.bitmap.assign(b);
end;
b.free;
drawmenubar(handle);
end;


procedure menuedrawitem(sender: tobject; acanvas: tcanvas; arect: trect;
selected: boolean);
var
txt: string;
b: tbitmap;

iconrect, textrect: trect;
fbackcolor, ficonbackcolor, fselectedbkcolor, ffontcolor, fselectedfontcolor,
fdisabledfontcolor, fseparatorcolor, fcheckedcolor: tcolor;

i, x1, x2: integer;
textformat: integer;
hasimglstbitmap: boolean;
fmenuitem: tmenuitem;
fmenu: tmenu;

begin
fmenuitem := tmenuitem(sender);
fmenu := fmenuitem.parent.getparentmenu;

fbackcolor := $00e1e1e1;
ficonbackcolor := $00d1d1d1;
fselectedbkcolor := $00dccfc7;

ffontcolor := clblack;
fselectedfontcolor := clnavy;
fdisabledfontcolor := clgray;
fseparatorcolor := $00d1d1d1;
fcheckedcolor := clgray;

if fmenu.isrighttoleft then
begin
x1 := arect.right - 20;
x2 := arect.right;
end
else
begin
x1 := arect.left;
x2 := arect.left + 20;
end;
iconrect := rect(x1, arect.top, x2, arect.bottom);

textrect := arect;
txt := ' ' + fmenuitem.caption;

b := tbitmap.create;

b.transparent := true;
b.transparentmode := tmauto;

hasimglstbitmap := false;
if (fmenuitem.parent.getparentmenu.images <> nil) or
(fmenuitem.parent.submenuimages <> nil) then
begin
if fmenuitem.imageindex <> -1 then
hasimglstbitmap := true
else
hasimglstbitmap := false;
end;

if hasimglstbitmap then
begin
if fmenuitem.parent.submenuimages <> nil then
fmenuitem.parent.submenuimages.getbitmap(fmenuitem.imageindex, b)
else
fmenuitem.parent.getparentmenu.images.getbitmap(fmenuitem.imageindex, b)
end
else
if fmenuitem.bitmap.width > 0 then
b.assign(tbitmap(fmenuitem.bitmap));

if fmenu.isrighttoleft then
begin
x1 := arect.left;
x2 := arect.right - 20;
end
else
begin
x1 := arect.left + 20;
x2 := arect.right;
end;
textrect := rect(x1, arect.top, x2, arect.bottom);

acanvas.brush.color := fbackcolor;
acanvas.fillrect(textrect);

if fmenu is tmainmenu then
for i := 0 to fmenuitem.getparentmenu.items.count - 1 do
if fmenuitem.getparentmenu.items = fmenuitem then
begin
acanvas.brush.color := ficonbackcolor;
acanvas.fillrect(arect);
if (fmenuitem.imageindex = -1) and (fmenuitem.bitmap.width = 0) then
begin
textrect := arect;
break;
end;
end;

acanvas.brush.color := ficonbackcolor;
acanvas.fillrect(iconrect);

if fmenuitem.enabled then
acanvas.font.color := ffontcolor
else
acanvas.font.color := fdisabledfontcolor;

if selected then
begin
acanvas.brush.style := bssolid;
acanvas.brush.color := fselectedbkcolor;
acanvas.fillrect(textrect);

acanvas.pen.color := fselectedfontcolor;

acanvas.brush.style := bsclear;
acanvas.roundrect(textrect.left, textrect.top, textrect.right,
textrect.bottom, 6, 6);

if fmenuitem.enabled then
acanvas.font.color := fselectedfontcolor;
end;

x1 := iconrect.left + 2;
if b <> nil then
acanvas.draw(x1, iconrect.top + 1, b);

if fmenuitem.checked then
begin
acanvas.pen.color := fcheckedcolor;
acanvas.brush.style := bsclear;
acanvas.roundrect(iconrect.left, iconrect.top, iconrect.right,
iconrect.bottom, 3, 3);
end;

if not fmenuitem.isline then
begin
setbkmode(acanvas.handle, transparent);

acanvas.font.name := 'tahoma';
if fmenu.isrighttoleft then
acanvas.font.charset := arabic_charset;

if fmenu.isrighttoleft then
textformat := dt_right + dt_rtlreading
else
textformat := 0;


if fmenuitem.default then
begin
inc(textrect.left, 1);
inc(textrect.right, 1);
inc(textrect.top, 1);
acanvas.font.color := clgray;
drawtextex(acanvas.handle,
pchar(txt),
length(txt),
textrect, textformat, nil);

dec(textrect.left, 1);
dec(textrect.right, 1);
dec(textrect.top, 1);

acanvas.font.color := ffontcolor;
end;

drawtextex(acanvas.handle,
pchar(txt),
length(txt),
textrect, textformat, nil);

txt := shortcuttotext(fmenuitem.shortcut) + ' ';

if fmenu.isrighttoleft then
textformat := dt_left
else
textformat := dt_right;

drawtextex(acanvas.handle,
pchar(txt),
length(txt),
textrect, textformat, nil);
end
else
begin
acanvas.pen.color := fseparatorcolor;
acanvas.moveto(arect.left + 10,
textrect.top +
round((textrect.bottom - textrect.top) / 2));
acanvas.lineto(arect.right - 2,
textrect.top +
round((textrect.bottom - textrect.top) / 2))
end;


b.free;


end;

procedure tform1.formcreate(sender: tobject);
begin
menuedrawitemx(menu);
end;

end.

 
后退
顶部