unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ShellAPI;
const
WM_BARICON = WM_USER+200;
type
TForm1 = class(TForm)
private
procedure WMSysCommand(var Message: TMessage);message
WM_SYSCOMMAND;
procedure WMBarIcon(var Message: TMessage);message
WM_BARICON;
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure Tform1.WMSysCommand(var Message: TMessage);
var
lpData: PNotifyIconData;
begin
if Message.WParam = SC_ICON then
begin
lpData := new(PNotifyIconDataA);
lpData.cbSize := 88;
lpData.Wnd := form1.Handle;
lpData.hIcon := form1.Icon.Handle;
lpData.uCallbackMessage := WM_BARICON;
lpData.uID := 0;
lpData.szTip := 'Sample';
lpData.uFlags := NIF_ICON or NIF_MESSAGE or NIF_TIP;
shell_NotifyIcon(NIM_ADD,lpData);
dispose(lpData);
form1.Visible := false;
end else
begin
DefWindowProc(Form1.Handle,message.Msg,message.WParam,message.LParam);
end;
end;
procedure TForm1.WMBarIcon(var Message: TMessage);
var
lpData : PNotifyIconData ;
begin
if (Message.LParam = WM_LBUTTONDOWN) then
begin
lpData := new(PNotifyIconDataA);
lpData.cbSize := 88;
lpdata.Wnd := form1.Handle;
lpdata.hIcon := form1.Icon.Handle;
lpdata.uCallbackMessage := WM_BARICON;
lpdata.uID := 0;
lpdata.szTip := 'Samples';
lpdata.uFlags := NIF_ICON or NIF_MESSAGE or NIF_TIP;
shell_NotifyIcon(NIM_DELETE,lpData);
dispose(lpdata);
form1.Visible := true;
end;
end;
end.
功能:实现程序最小化成一个小图标!需要事先找一个*.ico图标