怎么样创建任务样图标(100分)

  • 主题发起人 主题发起人 爱自由
  • 开始时间 开始时间

爱自由

Unregistered / Unconfirmed
GUEST, unregistred user!
我想做的三层结构中,中间层服务器想在运行的时候让它的图标进入任务栏中,且要
在右键菜单中,加入系统设置与退出.在系统设置中出现界面.
 
//建立任务栏图标
procedure CreateTrayIcon(Wnd:hwnd);
var NotifyIcon : TNotifyIconData;
begin
NotifyIcon.cbSize := SizeOf(NotifyIcon);
NotifyIcon.Wnd := Wnd;
NotifyIcon.uID := 1;
NotifyIcon.uFlags := nif_Message or nif_Icon or nif_Tip;
NotifyIcon.uCallbackMessage := wm_User;
NotifyIcon.hIcon := LoadIcon(hInstance, 'TRAYICON1');
lstrcpy(NotifyIcon.szTip,'mini go');
Shell_NotifyIcon(nim_ADD, @NotifyIcon);
end;
 
procedure TForm1.ModifyTrayIcon(Action: DWORD);
var
NIData: TNotifyIconData;
begin
with NIData do
begin
cbSize := sizeof(TNotifyIconData);
UID := 0;
uFlags := NIF_MESSAGE or NIF_ICON or NIF_TIP;
Wnd := Handle;
uCallBackMessage := WM_TRAYICON;
HICON := Application.Icon.Handle;
StrPCopy(szTip, Application.Title);
end;
Shell_NotifyIcon(Action, @NIData);
end;

procedure TForm1.WMTrayIcon(var message: TMessage);
var
MousePos: TPoint;
begin
if message.LPARAM = WM_RBUTTONDOWN then
begin
SetActiveWindow(Handle);
GetCursorPos(MousePos);
PopupMenu.Popup(MousePos.X, MousePos.Y);
end;
end;
 
ModifyTrayIcon(NIM_DELETE,Application.Icon.Handle );//删除
ModifyTrayIcon(NIM_ADD,Application.Icon.Handle );//添加
ModifyTrayIcon(NIM_MODIFY,Application.Icon.Handle );//修改
procedure TForm1.ModifyTrayIcon(Action: DWORD;ico:THandle);
var
NIData: TNotifyIconData;
begin
with NIData do
begin
cbSize := sizeof(TNotifyIconData);
UID := 0;
uFlags := NIF_MESSAGE or NIF_ICON or NIF_TIP;
uCallBackMessage := WM_TRAYICON;
Wnd := Handle;
HICON := ico;
StrPCopy(szTip, Application.Title);
end;
Shell_NotifyIcon(Action, @NIData);
end;

//响应鼠标事件。
procedure WMTrayIcon(var message: TMessage); message WM_TRAYICON;
procedure TForm1.WMTrayIcon(var message: TMessage);
var
MousePos: TPoint;
begin
if message.LPARAM = WM_RBUTTONDOWN then //鼠标右键单击图标
begin
SetActiveWindow(Handle);
GetCursorPos(MousePos);
PopupMenu1.Popup(MousePos.X, MousePos.Y);
end;
if message.LPARAM = WM_LBUTTONDBLCLK then //鼠标左键双击图标
begin
Form1.Show;
Form1.BringToFront ;
end;
end;


 
多人接受答案了。
 

Similar threads

D
回复
0
查看
814
DelphiTeacher的专栏
D
D
回复
0
查看
818
DelphiTeacher的专栏
D
后退
顶部