var icondata:TNOTIFYICONDATA; procedure TfrmSrvMain.FillDataStructure; begin with IconData do begin cbSize := sizeof(TNOTIFYICONDATA); wnd :=Self.Handle ; uID := 0; // is not passed in with message so make it 0 uFlags := NIF_MESSAGE + NIF_ICON + NIF_TIP; hIcon := Self.Icon.Handle; StrPCopy(szTip,'会员服务程序'); uCallbackMessage := WM_TOOLTRAYICON; end; end; Self.Hide; FillDataStructure; Shell_NotifyIcon(NIM_Add,@IconData); 还有在程序中加上uses shellapi
用abf_software在DELPHI6的Disk2里,那里有系统托盘的控件
我做了一个。 你去试试咯 procedure TForm1.FormCreate(Sender: TObject); begin //程序一启动先不显示主界面 visible := false; application.ShowMainForm := Visible; //创建tray MyTrayIcon.cbSize := sizeof(TNotifyIconData); //确定调用程序的窗体句柄 MyTrayIcon.Wnd := Handle; //确定tray的UID MyTrayIcon.uID := 1; //设定显示标记 mytrayicon.uFlags := nif_icon or nif_tip or nif_message; //用户自定义消息 mytrayicon.uCallbackMessage := WM_MYTRAYICONCALLBACK; mytrayicon.hIcon := loadicon(0,idi_winlogo); mytrayicon.szTip := 'Tray With POP Menu' ; //加入到系统托盘中去 shell_notifyicon(nim_add,@mytrayicon); end;procedure Tform1.WMMyTrayIconCallback (var Msg:TMessage); var CursorPos : TPoint; begin case msg.LParam of WM_LBUTTONDBLCLK:begin //左键双击 //取得光标当前的位置 GetCursorPos(cursorpos); //弹出菜单 popupmenu1.popup(CursorPos.x,CursorPos.y); end; WM_LBUTTONDOWN: begin //单击左键 getcursorpos(cursorpos); Popupmenu1.Popup (cursorpos.x,cursorpos.y); end; end;//end caseend;procedure TForm1.FormDestroy(Sender: TObject); begin Shell_NotifyIcon(NIM_DELETE, @MyTrayIcon); end;procedure TForm1.show1Click(Sender: TObject); begin visible := true; //application.ShowMainForm := visible; //setforegroundwindow(application.handle); end;procedure TForm1.hide1Click(Sender: TObject); begin visible := false; end; 以上代码就是
icondata:TNOTIFYICONDATA;
procedure TfrmSrvMain.FillDataStructure;
begin
with IconData do begin
cbSize := sizeof(TNOTIFYICONDATA);
wnd :=Self.Handle ;
uID := 0; // is not passed in with message so make it 0
uFlags := NIF_MESSAGE + NIF_ICON + NIF_TIP;
hIcon := Self.Icon.Handle;
StrPCopy(szTip,'会员服务程序');
uCallbackMessage := WM_TOOLTRAYICON;
end;
end;
Self.Hide;
FillDataStructure;
Shell_NotifyIcon(NIM_Add,@IconData);
还有在程序中加上uses shellapi
我做了一个。 你去试试咯 procedure TForm1.FormCreate(Sender: TObject);
begin
//程序一启动先不显示主界面
visible := false;
application.ShowMainForm := Visible; //创建tray
MyTrayIcon.cbSize := sizeof(TNotifyIconData);
//确定调用程序的窗体句柄
MyTrayIcon.Wnd := Handle;
//确定tray的UID
MyTrayIcon.uID := 1;
//设定显示标记
mytrayicon.uFlags := nif_icon or nif_tip or nif_message;
//用户自定义消息
mytrayicon.uCallbackMessage := WM_MYTRAYICONCALLBACK; mytrayicon.hIcon := loadicon(0,idi_winlogo); mytrayicon.szTip := 'Tray With POP Menu' ;
//加入到系统托盘中去
shell_notifyicon(nim_add,@mytrayicon);
end;procedure Tform1.WMMyTrayIconCallback (var Msg:TMessage);
var
CursorPos : TPoint;
begin
case msg.LParam of
WM_LBUTTONDBLCLK:begin //左键双击
//取得光标当前的位置
GetCursorPos(cursorpos);
//弹出菜单
popupmenu1.popup(CursorPos.x,CursorPos.y);
end;
WM_LBUTTONDOWN: begin //单击左键
getcursorpos(cursorpos);
Popupmenu1.Popup (cursorpos.x,cursorpos.y);
end;
end;//end caseend;procedure TForm1.FormDestroy(Sender: TObject);
begin
Shell_NotifyIcon(NIM_DELETE, @MyTrayIcon);
end;procedure TForm1.show1Click(Sender: TObject);
begin
visible := true;
//application.ShowMainForm := visible;
//setforegroundwindow(application.handle);
end;procedure TForm1.hide1Click(Sender: TObject);
begin
visible := false;
end; 以上代码就是
不是ole对象!