unit Unit4;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs,ComCtrls,ExtCtrls,StdCtrls,ToolWin,ShellApi,Menus, jpeg;
//define the consts
const
WM_MY_Notify=WM_USER+100;
type
TForm4 = class(TForm)
Image1: TImage;
PopupMenu1: TPopupMenu;
S1: TMenuItem;
H1: TMenuItem;
N1: TMenuItem;
E1: TMenuItem;
procedure E1Click(Sender: TObject);
procedure H1Click(Sender: TObject);
procedure S1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
{ Private declarations }
//the icon data structure...
TrayIcon:PNOTIFYICONDATA;
//icon 图像
Icon:TIcon;
public
{ Public declarations }
//自定义消息函数..
procedure NotifyIconClick(var msg:TMessage);Message WM_MY_Notify;
end;
var
Form4: TForm4;
implementation
{$R *.dfm}
procedure TForm4.FormClose(Sender: TObject; var Action: TCloseAction);
begin
///**** 释放对象
Dispose(TrayIcon);
Icon.free;
end;
procedure TForm4.FormCreate(Sender: TObject);
begin
//******** 创建对象
New(TrayIcon);
TrayIcon.cbSize:=SizeOf(TrayIcon^);
TrayIcon.uID:=200;
TrayIcon.wnd:=Handle;
TrayIcon.uCallbackMessage:=WM_MY_Notify;
TrayIcon.uFlags:=NIF_ICON+NIF_Tip+NIF_MESSAGE;
TrayIcon.szTip:='任务栏图标';
//creat icon...
Icon:=TIcon.Create;
Icon.Assign(Image1.Picture);
TrayIcon.hIcon:=Icon.Handle;
//生成任务栏图标
Shell_NotifyIcon(NIM_ADD,TrayIcon);
end;
Procedure TForm4.NotifyIconClick(var msg:TMessage);
var
p:TPoint;
begin
try
case msg.LParam of
WM_RBUTTONDOWN:
begin
GetCursorPos(p);
PopupMenu1.Popup(p.X,p.Y);
end;
//WM_LBUTTONDOWM:左键按下消息
end;
except
end;
end;
procedure TForm4.S1Click(Sender: TObject);
begin
//****** file
Show;
end;
procedure TForm4.H1Click(Sender: TObject);
begin
//********** edit
hide;
{
s1.Enabled:=false;
h1.Enabled:=true;
}
end;
procedure TForm4.E1Click(Sender: TObject);
begin
//*********** hejp
close;
{//更改菜单项的有效性
h1.Enabled:=false;
s1.Enabled:=true;
}
end;
end.