我想把现有的程序做成运行后自动以一个图标出现在任务栏的右下角,在图标上使用右键菜单来退出程序,请高手们指教,有没有现在成的代码提供以参考??
解决方案 »
- list index out of bounds(0) 为什么?
- 急需DELPHI线程池代码,准备做完成端口
- 关于ADOconnection
- Delphi2005中TTreeView节点Data挂的指针释放问题?
- delphi消息处理中,是怎么把消息的窗口hwnd转换成窗口对像的。
- 这个问题我两个礼拜都没解决,你想看看吗?帮帮我吧!!!
- 请问 在Internet面板上找不到TClientSocked 和 TServerSocked这两个控件,怎么办?
- 各位大虾有空的过来看看
- 咨询!咨询!咨询!
- 关于快速像素替换问题?
- 为什么我在使用LeftStr()函数的时候报错“undecleared identifier 'LeftStr'”
- 如何取得年份和月份?
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Menus, StdCtrls, Buttons, ExtCtrls, ShellApi,ImgList,inifiles;const
menuMsg=WM_USER+1;...
private
{ Private declarations }
nid:TNotifyIconData;
procedure WmSysCommand(var Msg:TWMSysCommand);message WM_SYSCOMMAND;
procedure addIcon;
procedure delIcon;
procedure IconTray(var Msg:TMessage);message menuMsg; ...
procedure TfrmMain.FormClose(Sender: TObject; var Action: TCloseAction);
begin
nid.cbSize:=sizeof(TNotifyIconData);
nid.Wnd:=Handle;
nid.uID:=0;
shell_NotifyIcon(NIM_DELETE,@nid);
end;procedure TfrmMain.WmSysCommand(var Msg: TWMSysCommand);
begin
if Msg.CmdType=SC_MINIMIZE then
begin
addIcon;
self.Hide;
end
else
inherited;
end;procedure TfrmMain.addIcon;
begin
nid.cbSize:=sizeof(TNotifyIconData);
nid.Wnd:=handle;
nid.uID:=0;
nid.uFlags:=NIF_MESSAGE or NIF_ICON or NIF_TIP;
nid.uCallbackMessage:=menuMsg;
nid.hIcon:=Application.Icon.Handle;
nid.szTip:='AutoMouse Clicked';
shell_NotifyIcon(NIM_ADD,@nid);
end;procedure TfrmMain.delIcon;
begin
ShowWindow(Application.Handle,SW_SHOW);
Application.Restore;
self.Show;
SetForegroundWindow(Handle);
shell_NotifyIcon(NIM_DELETE,@nid);
end;//处理托盘区域消息
procedure TfrmMain.IconTray(var Msg: TMessage);
var
p:TPoint;
begin
if Msg.LParam=WM_RBUTTONUP then
begin
GetCursorPos(p);
SetForegroundWindow(Handle);
pm.Popup(p.X,p.Y);
end;
if Msg.LParam=WM_LBUTTONUP then
delIcon;
inherited;
end;
undeclared indentifier 'pprogamversion'
undeclared indentifier 'ucallbackmessage'
undeclared indentifier 'WM_ICONMESSAGE'
unsafe code'@ operator'
procedure TFrmmain.WMSysCommand(var Message:TMessage);
var
lpData:PNotifyIconData;
begin
if Message.WParam = SC_ICON then
begin
//如果用户最小化窗口则将窗口隐藏并在任务栏上添加图标
lpData := new(PNotifyIconDataA);
lpData.cbSize := 88;
//SizeOf(PNotifyIconDataA);
lpData.Wnd := Frmmain.Handle;
lpData.hIcon := Frmmain.Icon.Handle;
lpData.uCallbackMessage := WM_BARICON;
lpData.uID :=0;
lpData.szTip := 'EDISvr1.0';
lpData.uFlags := NIF_ICON or NIF_MESSAGE or NIF_TIP;
Shell_NotifyIcon(NIM_ADD,lpData);
dispose(lpData);
Frmmain.Visible := False;
end
else
begin
//如果是其它的SystemCommand消息则调用系统缺省处理函数处理之。
DefWindowProc(Frmmain.Handle,Message.Msg,Message.WParam,Message.LParam);
end;
end;procedure TFrmmain.WMBarIcon(var Message:TMessage);
var
lpData:PNotifyIconData;
Pt: TPoint;
begin
case Message.LParam of
WM_LBUTTONDOWN:
begin
//如果用户点击任务栏图标则将图标删除并回复窗口。
lpData := new(PNotifyIconDataA);
lpData.cbSize := 88;//SizeOf(PNotifyIconDataA);
lpData.Wnd := Frmmain.Handle;
lpData.hIcon := Frmmain.Icon.Handle;
lpData.uCallbackMessage := WM_BARICON;
lpData.uID :=0;
lpData.szTip :='sdffsd';
lpData.uFlags := NIF_ICON or NIF_MESSAGE or NIF_TIP;
Shell_NotifyIcon(NIM_DELETE,lpData);
dispose(lpData);
Frmmain.Visible := True;
end;
WM_RBUTTONDOWN: //当点击右键时,弹出快捷菜单
begin
lpData := new(PNotifyIconDataA);
SetForeGroundWindow(lpData.Wnd);
GetCursorPos(Pt);
Popupmenu.Popup(pt.x, pt.y);
end;
end;
end; 判断消息就可以了
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs,shellapi, Menus;
const
WM_TrayMessage=WM_User+100;
type
TForm1 = class(TForm)
PopupMenu1: TPopupMenu;
N11: TMenuItem;
N21: TMenuItem;
procedure FormCreate(Sender: TObject);
protected
procedure AppMinimized(Sender: TObject);
procedure WMTrayMessage(var msg:TMessage);message WM_TrayMessage;
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;
NID:TNotifyIconData;
implementation{$R *.dfm}
procedure TForm1.AppMinimized(Sender: TObject);
begin
NID.cbSize:=SizeOf(TNotifyIconData);
NID.hIcon:=Application.Icon.Handle;
NID.szTip:= '工程一 ';
NID.uCallbackMessage:=WM_TrayMessage;
NID.uFlags:=NIF_ICON or NIF_MESSAGE or NIF_TIP;
NID.uID:=0;
NID.Wnd:=Handle;
Shell_NotifyIcon(NIM_ADD,@NID);
ShowWindow(Application.Handle,SW_Hide);
end;
procedure TForm1.WMTrayMessage(var msg: TMessage);
var
p:TPoint;
begin
if msg.LParam=WM_LButtonDown then
begin
ShowWindow(Application.Handle,SW_Show);
Application.Restore;
end
else if msg.LParam=WM_RButtonDown then
begin
GetCursorPos(p);
PopupMenu1.Popup(p.x,p.y);
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
Application.OnMinimize:=AppMinimized;
AppMinimized(nil);
end;end.
procedure TForm1.FormDestroy(Sender: TObject);
begin
Shell_NotifyIcon(NIM_DELETE,@NID);
end;