时间: 2021-07-31 作者:daque
不妨像qq一律实行最小化窗口时窗口到体例栏的动画功效。 unit main; interface uses windows, messages, sysutils, classes, graphics, controls, forms, dialogs, rxshell, stdctrls; type tzoomdirection = (zoomformopen, zoomformclosed);//列举典型 type tformmain = class(tform) trayicon1: trxtrayicon;//rx组件里的体例栏图标控件 label1: tlabel; procedure formshow(sender: tobject); procedure trayicon1dblclick(sender: tobject); private procedure onmincmd(var message: tmessage); message wm_syscommand; //捕捉动静 procedure frmzoomtotray(frm: tform; direction: tzoomdirection); //爆发窗体从体例处事区中加入或出来的动静功效子进程 public { public declarations } end; var formmain: tformmain; implementation {$r *.dfm} procedure tformmain.formshow(sender: tobject); begin showwindow(application.handle, sw_hide);//取消工作栏表露 end; procedure tformmain.onmincmd(var message: tmessage); begin if (message.wparam = sc_minimize) then //即使是最小化动静 begin trayicon1.active := true; //表露图标 frmzoomtotray(formmain,zoomformclosed); formmain.hide; //湮没窗体 exit; end; inherited; //让窗体处置其它动静 end; procedure tformmain.frmzoomtotray(frm: tform; direction: tzoomdirection); var traywnd: hwnd; sclassname: array[0..255] of char; xfrom, xto: trect; begin if (direction = zoomformclosed) and (frm.visible = false) then exit; if (direction = zoomformopen) and (frm.visible = true) then exit; traywnd := findwindow('shell_traywnd', nil); traywnd := getwindow(traywnd, gw_child); repeat getclassname(traywnd, @sclassname, 255); if strpas(sclassname) = 'traynotifywnd' then break; traywnd := getwindow(traywnd, gw_hwndnext); until traywnd = 0; case direction of zoomformopen: begin getwindowrect(traywnd, xfrom); xfrom.left := (xfrom.right - (xfrom.right - xfrom.left) div 2); xfrom.right := xfrom.left + 1; getwindowrect(frm.handle, xto); drawanimatedrects(frm.handle, idani_open or idani_caption, xfrom, xto); end; zoomformclosed: begin getwindowrect(frm.handle, xfrom); getwindowrect(traywnd, xto); xto.left := (xto.right - (xto.right - xto.left) div 2); xto.right := xto.left + 1; drawanimatedrects(frm.handle, idani_close or idani_caption, xfrom, xto); end; end; end; procedure tformmain.trayicon1dblclick(sender: tobject); begin trayicon1.active := false; frmzoomtotray(formmain,zoomformopen); formmain.show; end; end.