message mi_iconevent;
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
function setkeyhook:bool;
external ''keyspy.dll'';
function endkeyhook:bool;
external ''keyspy.dll'';
procedure tform1.icontray(var msg:tmessage);
var
pt:tpoint;
begin
if msg.lparam=wm_lbuttondown then
sethook1click(self);
if msg.LParam=wm_rbuttondown then
begin
getcursorpos(pt);
setforegroundwindow(handle);
popupmenu1.popup(pt.x
pt.y);
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
normalicon:=ticon.create;
application.title:=caption;
nid.cbsize:=sizeof(nid);
nid.wnd:=handle;
nid.uid:=icon_id;
nid.uflags:=nif_icon or nif_message or nif_tip;
nid.ucallbackmessage:=mi_iconevent;
nid.hIcon :=normalicon.handle;
strcopy(nid.sztip
pchar(caption));
nid.uFlags:=nif_message or nif_icon or nif_tip; shell_notifyicon(nim_add
@nid);
SetWindowLong(Application.Handle
GWL_EXSTYLE
WS_EX_TOOLWINDOW);
end;
procedure TForm1.sethook1Click(Sender: TObject);
begin setkeyhook;
end;
procedure TForm1.endhook1Click(Sender: TObject);
begin endkeyhook;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin nid.uFlags :=0;
shell_notifyicon(nim_delete
@nid);
end;
procedure TForm1.Close1Click(Sender: TObject);
begin application.terminate;
end;
该程序虽然只用了几个shellai函数,但是它涉及到了在Delphi中对DLL的引用、钩子实现、对指示区的操作、用户定义消息的处理、文件的读写等比较重要的内容,我相信这篇文章能对许多Delphi的初学者有所帮助。
该程序在Win98、Delphi4.0中正常运行。