interface
uses
ShellAPI,ShlObj;
const
WM_BARICON = WM_USER + 200;
cm_Exit = 100;
cm_About = 101;
private
procedure WMSysCommand(var Message:TMessage);
message WM_SYSCOMMAND;
procedure WMBarIcon(var Message:TMessage);
message WM_BARICON;
type
_NOTIFYICONDATAW = record
cbSize: DWORD;
Wnd: HWND;
uID: UINT;
uFlags: UINT;
uCallbackMessage: UINT;
hIcon: HICON;
szTip: array [0..63] of WideChar;
end;
var
TNotifyIconData: _NOTIFYICONDATAW;
procedure TfrmMain.WMSysCommand(var Message: TMessage);// message WM_SYSCOMMAND;
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 := 'GPS信息';
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);//message WM_BARICON;
var
lpData:PNotifyIconData;
begin
if (Message.LParam = WM_LBUTTONDOWN) 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 := 'GPS信息';
lpData.uFlags := NIF_ICON or NIF_MESSAGE or NIF_TIP;
Shell_NotifyIcon(NIM_DELETE,lpData);
dispose(lpData);
frmMain.Visible := True;
end;
end;
uses
ShellAPI,ShlObj;
const
WM_BARICON = WM_USER + 200;
cm_Exit = 100;
cm_About = 101;
private
procedure WMSysCommand(var Message:TMessage);
message WM_SYSCOMMAND;
procedure WMBarIcon(var Message:TMessage);
message WM_BARICON;
type
_NOTIFYICONDATAW = record
cbSize: DWORD;
Wnd: HWND;
uID: UINT;
uFlags: UINT;
uCallbackMessage: UINT;
hIcon: HICON;
szTip: array [0..63] of WideChar;
end;
var
TNotifyIconData: _NOTIFYICONDATAW;
procedure TfrmMain.WMSysCommand(var Message: TMessage);// message WM_SYSCOMMAND;
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 := 'GPS信息';
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);//message WM_BARICON;
var
lpData:PNotifyIconData;
begin
if (Message.LParam = WM_LBUTTONDOWN) 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 := 'GPS信息';
lpData.uFlags := NIF_ICON or NIF_MESSAGE or NIF_TIP;
Shell_NotifyIcon(NIM_DELETE,lpData);
dispose(lpData);
frmMain.Visible := True;
end;
end;