//算啦,各位啥也别说了,来点实在的----给你贴cooltrayicon代码,目前最cool的delphi系统托盘控件,比我写的那个可“冗长”多了!(别忘了赶紧结账阿:P):
/////////////////////////////////////////////////
{*****************************************************************}
{ This is a component for placing icons in the notification area }
{ of the Windows taskbar (aka. the traybar). }
{ }
{ The component is freeware. Feel free to use and improve it. }
{ I would be pleased to hear what you think. }
{ }
{ Troels Jakobsen - delphiuser@get2net.dk }
{ Copyright (c) 2001 }
{*****************************************************************}
const
{ Define user-defined message sent by the trayicon. We avoid low user-defined
messages that are used by Windows itself (eg. WM_USER+1 = DM_SETDEFID). }
WM_TRAYNOTIFY = WM_USER + 1024;
// Constant used for recreating trayicon on system traybar recover
IconID = 1;
// Constants used for balloon hint feature
WM_RESETTOOLTIP = WM_USER + 1025;
NIIF_NONE = $00000000;
NIIF_INFO = $00000001;
NIIF_WARNING = $00000002;
NIIF_ERROR = $00000003;
NIF_INFO = $00000010;
var
WM_TASKBARCREATED: Cardinal;
type
{ You can use the TNotifyIconData record structure defined in shellapi.pas.
However, WinME, Win2000, and WinXP have expanded this structure. We define
a similar structure, TNotifyIconDataEx. }
TNotifyIconDataEx = record
cbSize: DWORD;
Wnd: HWND;
uID: UINT;
uFlags: UINT;
uCallbackMessage: UINT;
hIcon: HICON;
// szTip: array[0..63] of AnsiChar;
szTip: array[0..127] of AnsiChar; // 0..63 of WideChar in stead?
dwState: DWORD;
dwStateMask: DWORD;
szInfo: array[0..255] of AnsiChar;
uTimeout: UINT; // union with uVersion: UINT;
szInfoTitle: array[0..63] of AnsiChar;
dwInfoFlags: DWORD;
end;
TBalloonHintIcon = (bitNone, bitInfo, bitWarning, bitError);
TBalloonHintTimeOut = 10..60; // Windows defines 10-60 secs. as min-max
TCycleEvent = procedure(Sender: TObject; NextIndex: Integer) of object;
function TSysTray_San.Showed: boolean;
begin
result:=added;
end;
procedure TSysTray_San.SysTrayIconMsgHandler(var Msg: TMessage);
var
p:tpoint;
begin
getcursorpos(p);
case Msg.LParam of
WM_MOUSEMOVE:
begin
if assigned(popupmenu)and (pomm in popupoptions)then
popupmenu.Popup(p.X,p.Y);
if assigned(onmousemove) then
self.OnMouseMove(self);
end;
WM_LBUTTONDOWN:
begin
if assigned(popupmenu)and (polbdown in popupoptions)then
popupmenu.Popup(p.X,p.Y);
if assigned(onleftmousedown) then
self.OnLeftMouseDown(self);
end;
WM_LBUTTONUP:
begin
if assigned(popupmenu)and (polbup in popupoptions)then
popupmenu.Popup(p.X,p.Y);
if assigned(onleftmouseup) then
self.OnLeftMouseUp(self);
end;
WM_LBUTTONDBLCLK:
begin
if assigned(popupmenu)and (polbdbc in popupoptions)then
popupmenu.Popup(p.X,p.Y);
if assigned(onleftmousedbclick) then
self.OnLeftMouseDbClick(self);
end;
WM_RBUTTONDOWN:
begin
if assigned(popupmenu)and (porbdown in popupoptions)then
popupmenu.Popup(p.X,p.Y);
if assigned(onrightmousedown) then
self.OnRightMouseDown(self);
end;
WM_RBUTTONUP:
begin
if assigned(popupmenu)and (porbup in popupoptions)then
popupmenu.Popup(p.X,p.Y);
if assigned(onrightmouseup) then
self.OnRightMouseUp(self);
end;
WM_RBUTTONDBLCLK:
begin
if assigned(popupmenu)and (porbdbc in popupoptions)then
popupmenu.Popup(p.X,p.Y);
if assigned(onrightmousedbclick) then
self.OnRightMouseDbClick(self);
end;
//以下为新加入的消息
NIN_BALLOONSHOW:
if assigned(onballoonshow) then {当 Balloon Tips 弹出时执行}
self.OnBalloonShow(self);// showmessage('NIN_BALLOONSHOW');
NIN_BALLOONHIDE:
if assigned(onballoonhide) then {当 Balloon Tips 消失时执行(例如 SysTrayIcon 被删除),但指定的 TimeOut 时间到或鼠标点击 Balloon Tips 后的消失不发送此消息}
self.OnBalloonHide(self);// showmessage('NIN_BALLOONHIDE');
NIN_BALLOONTIMEOUT:
if assigned(onballoontimeout) then {当 Balloon Tips 的 TimeOut 时间到时执行}
self.OnBalloonTimeOut(self);// showmessage('NIN_BALLOONTIMEOUT');
NIN_BALLOONUSERCLICK:
if assigned(onballoonclick) then
self.onballoonclick(self); {当鼠标点击 Balloon Tips 时执行。
注意:在XP下执行时 Balloon Tips 上有个关闭按钮,而且 Balloon Tips
一直显示(IconData.DUMMYUNIONNAME.uTimeout := 3000;
这句话设定的时间没有用,我的测试是这样的),
如果鼠标点在按钮上将接收到 NIN_BALLOONTIMEOUT 消息。}
//showmessage('NIN_BALLOONUSERCLICK');
else
//beep;
end;
end;
procedure TSysTray_San.OnTimer(sender: tobject);
begin
if iconlist<>nil then
begin
if currenticonindex>iconlist.Count-1 then
currenticonindex:=0;
changeiconbyindex(currenticonindex);
inc(currenticonindex);
end;
end;
function TSysTray_San.GetPopupMenu: TPopupMenu;
begin
result:=popupmenu;
end;
function TSysTray_San.GetHint: string;
begin
result:=trayhint;
end;
procedure TSysTray_San.SetHint(AStr: string);
begin
trayhint:=astr;
strPLCopy(IconData.sztip, astr, sizeof(IconData.szInfo) - 1);
IconData.uFlags := NIF_ICON or NIF_MESSAGE or NIF_TIP;
Shell_NotifyIcon(NIM_MODIFY, @IconData);
end;
procedure TSysTray_San.changeIconbyindex(Index: integer);
var
icn:ticon;
begin
if iconlist=nil then exit;
icn:=ticon.Create;
iconlist.GetIcon(index,icn);
changeiconhandle(icn.Handle);
icn.Free;
end;
procedure TSysTray_San.HideMainForm;
begin
showwindow(formhandle,sw_hide);
if hideonmin then
ShowWindow(Application.Handle, SW_HIDE);
end;
procedure TSysTray_San.ShowMainForm;
begin
showwindow(formhandle,sw_show);
end;