unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;
const
NIM_ADD=0;
NIM_MODIFY=1;
NIM_DELETE=2;
NIF_ICON = 2;
NIF_MESSAGE = 1;
NIF_TIP = 4;
WM_USER = $400;
MYWM_NOTIFYICON=WM_USER+109;
type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
{ Private declarations }
procedure OnTaskBarMsg(var Msg: TMessage); message MYWM_NOTIFYICON;
public
{ Public declarations }
end;
NOTIFYICONDATA=record
cbSize : Longint;
hwnd : Longint;
uID : Longint;
uFlags : Longint;
uCallbackMessage : Longint;
hIcon : Longint;
szTip :array[0..63]of char;
End ;
var
Form1: TForm1;
tnid:NOTIFYICONDATA;
Function Shell_NotifyIcon (dwMessage :Longint; var lpData: NOTIFYICONDATA) : Longint;
stdcall;external 'shell32.dll';
implementation
{$R *.DFM}
procedure TForm1.OnTaskBarMsg(var Msg: TMessage);
begin
IF (msg.LParam =514) then
if form1.WindowState =wsMinimized then
form1.WindowState :=wsNormal
else
form1.WindowState :=wsMinimized;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
tnid.cbSize :=sizeof(NOTIFYICONDATA);
tnid.hwnd:=form1.Handle;
tnid.uID :=100;
tnid.hIcon :=application.Icon.Handle ;
tnid.uFlags :=nif_icon or NIF_TIP or NIF_MESSAGE;
tnid.szTip :='我的任务栏图标';
tnid.uCallbackMessage :=MYWM_NOTIFYICON;
Shell_NotifyIcon(NIM_ADD,tnid);
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
shell_notifyicon(NIM_DELETE,tnid);
end;
end.