我在托盘图标出点击右键,就是不出现快捷菜单,一下是我的代码:
procedure TfrmAppMain.WMBarIcon(var Message:TMessage);
var
lpData:PNotifyIconData;
P : TPoint;
begin
if Message.LParam =WM_RBUTTONDOWN then
begin
self.PopupMenu:=sysMenu;
SetForegroundWindow(Handle);
GetCursorPos(P);
sysMenu.Popup(P.X,P.Y);
end;
procedure TfrmAppMain.WMBarIcon(var Message:TMessage);
var
lpData:PNotifyIconData;
P : TPoint;
begin
if Message.LParam =WM_RBUTTONDOWN then
begin
self.PopupMenu:=sysMenu;
SetForegroundWindow(Handle);
GetCursorPos(P);
sysMenu.Popup(P.X,P.Y);
end;
解决方案 »
- 请问如何将string转换成pansichar类型
- x的值怎么算出来的?
- 用idudpserver往外网发送数据,为什么外网没反应?
- 帮我看看这段程序,运行修改密码的时候总提示无法将Null插入Class(表中属性),改列不允许空值,Insert失败。我没用Insert啊
- 请各位谈谈Prepare和UnPrepare在Query中的作用和用法
- 菜鸟问~!
- 回答"能"或"不能",能的话,告诉我怎么做格外加分
- 怎么才能遍历注册表!
- 高手请了,我怎样用TADOQUERY控件同时对几个表中的数据查询后的结果进行更新
- 高分求解一个大家关注的问题!
- 如何知道应用程序使用了那个运行时包bpl?
- 如何减小程序占的内在的大小.
NotifyIcon.cbSize := Sizeof(TNotifyIconData);
NotifyIcon.Wnd := Handle;
NotifyIcon.uID := 1;
NotifyIcon.uFlags := NIF_ICON or NIF_Message or NIF_TIP;
NotifyIcon.uCallbackMessage := WM_Icon;
NotifyIcon.hIcon := Application.Icon.Handle;
NotifyIcon.szTip := '嘿嘿';
Shell_NotifyIcon(NIM_ADD, @NotifyIcon);
const
MYWM_NOTIFYICON = WM_USER + 100; //托盘栏图标消息
var
WM_TASKBARCREATED : LongWord; //防崩溃消息 protected
procedure WndProc(var MyMessage: TMessage); override;
procedure TfMain.WndProc(var MyMessage: TMessage);
var
pt: TPoint;
begin
case MyMessage.Msg of
WM_CLOSE: //关闭事件
begin
application.Minimize;
end;
WM_CREATE:
begin
WM_TASKBARCREATED := RegisterWindowMessage('TaskbarCreated');
//创建托盘栏图标类
TrayIcon := TTrayIcon.Create(self);
TrayIcon.ActiveIcon.Handle := LoadIcon(HInstance, 'Tray0');
TrayIcon.DeActiveIcon.Handle := LoadIcon(HInstance, 'Tray1');
end;
WM_DESTROY: // 窗体销毁消息
begin
//释放托盘栏图标
TrayIcon.NotifyDelete(self.Handle);
//释放托盘栏图标类
TrayIcon.Free;
end;
WM_SYSCOMMAND: begin
case MyMessage.WParam of
SC_MINIMIZE: // 窗体最小化
application.Minimize
else
inherited;
end;
end;
MYWM_NOTIFYICON:
case MyMessage.lParam of
WM_LBUTTONDBLCLK: //鼠标左键双击
begin
if self.Showing = true then
begin
application.Minimize;
self.Hide;
end
else
begin
self.Show;
application.Restore;
SetForegroundWindow(self.Handle);
end;
end;
WM_RBUTTONDOWN: //鼠标右键被按下
begin
GetCursorPos(pt);
SetForegroundWindow(self.Handle);
pmTrayIcon.Popup(pt.x,pt.y);
end
else
//调用父类的WndProc方法处理其它消息
inherited;
end;
else
if MyMessage.Msg = WM_TASKBARCREATED then //托盘栏防崩溃处理
begin
TrayIcon.NotifyDelete(self.Handle);
TrayIcon.NotifyAdd(self.Handle, self.Showing);
end
else
//调用父类的WndProc方法处理其它消息
inherited;
end;
end;