下列是实现系统托盘的代码,虽然能够在系统托盘出现图标,但是右键单击它,却未能
如意料中的弹出菜单,各位帮我看看有什么错误~~
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ShellAPI, Menus;type
TForm1 = class(TForm)
PopupMenu1: TPopupMenu;
N11: TMenuItem;
N12: TMenuItem;
N13: TMenuItem;
N14: TMenuItem;
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure WMTrayNotify(var Msg: TMessage);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;
nid: TNotifyIconData;
const
MY_TRAY_ICON = 1000;
WM_TRAYNOTIFY = 2000;implementation{$R *.dfm}procedure TForm1.FormCreate(Sender: TObject);
begin
nid.cbSize :=sizeof(TNotifyIconData);
nid.Wnd :=handle;
nid.uID :=MY_TRAY_ICON;
nid.uFlags :=NIF_MESSAGE or NIF_ICON or NIF_TIP;
nid.uCallbackMessage :=WM_TRAYNOTIFY;
nid.hIcon :=application.Icon.Handle ;
nid.szTip :='aaaa';
Shell_notifyicon(NIM_ADD,@nid);
showwindow(form1.Handle ,SW_HIDE);
end;procedure TForm1.FormDestroy(Sender: TObject);
begin
shell_notifyicon(NIM_DELETE,@nid);
end;procedure TForm1.WMTrayNotify(var Msg: TMessage);
var
p: TPoint;
begin
if msg.LParam =WM_RBUTTONDOWN then
begin
GetCursorPos(p);
PopupMenu1.Popup(p.X ,p.Y );
end;
end;end.
如意料中的弹出菜单,各位帮我看看有什么错误~~
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ShellAPI, Menus;type
TForm1 = class(TForm)
PopupMenu1: TPopupMenu;
N11: TMenuItem;
N12: TMenuItem;
N13: TMenuItem;
N14: TMenuItem;
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure WMTrayNotify(var Msg: TMessage);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;
nid: TNotifyIconData;
const
MY_TRAY_ICON = 1000;
WM_TRAYNOTIFY = 2000;implementation{$R *.dfm}procedure TForm1.FormCreate(Sender: TObject);
begin
nid.cbSize :=sizeof(TNotifyIconData);
nid.Wnd :=handle;
nid.uID :=MY_TRAY_ICON;
nid.uFlags :=NIF_MESSAGE or NIF_ICON or NIF_TIP;
nid.uCallbackMessage :=WM_TRAYNOTIFY;
nid.hIcon :=application.Icon.Handle ;
nid.szTip :='aaaa';
Shell_notifyicon(NIM_ADD,@nid);
showwindow(form1.Handle ,SW_HIDE);
end;procedure TForm1.FormDestroy(Sender: TObject);
begin
shell_notifyicon(NIM_DELETE,@nid);
end;procedure TForm1.WMTrayNotify(var Msg: TMessage);
var
p: TPoint;
begin
if msg.LParam =WM_RBUTTONDOWN then
begin
GetCursorPos(p);
PopupMenu1.Popup(p.X ,p.Y );
end;
end;end.
procedure WMSysCommand(var Msg: TWMSysCommand); message WM_SYSCOMMAND;
procedure TForm1.WMSysCommand(var Msg: TWMSysCommand);
begin
if (Msg.CmdType = SC_MINIMIZE) or (msg.CmdType =SC_CLOSE)then
showwindow(handle,SW_HIDE);
end;procedure TForm1.mousemessage(var message: tmessage);
var mousept:tpoint;
begin
inherited;
if message.LParam=wm_rbuttonup then
begin
getcursorpos(mousept);
pop1.Popup(mousept.x, mousept.Y);
end;
if message.LParam=wm_lbuttonup then
begin
showwindow(handle,sw_show);
exit; form1.FormStyle:=fsstayontop;
setwindowlong(application.Handle,gwl_exstyle,not(getwindowlong(application.Handle,gwl_exstyle)
or ws_ex_toolwindow and not ws_ex_appwindow));
end;
//message.Result:=0;
end;
procedure WMTrayNotify(var Msg: TMessage);
改为:
procedure WMTrayNotify(var Msg: TMessage);Message WM_TRAYNOTIFY;
可是我不知道这是为什么(具体说就是常数定义一般应该放在哪里)?
还有就是,为什么一定要定义这个消息?