>>超级解霸肯定不是用timer,如果用线程的话能否给出源代码?
不要把问题复杂化,解霸为什么不是用Timer???这里用得上线程吗?
就算是用线程,也不就是这样用:
While true do
NotifyIcon1.ModifyIcon(IconArray[i]);
YourThread.Sleep(xxx);
Repeat;
比用Timer复杂多了,又没有什么实际的好处
const
WM_MY_Notify=WM_USER+100;
type
ECreateError=class(Exception);
TPopupStyle=Set of (Left_Click,Right_Click,Left_DbClick,Right_DbClick);
TWhoButton=(b_Left,b_Right);
TMouseEvent=
procedure(Sender:TObject;x,y:Word;WhoButton:TWhoButton)
of Object;
implementation
procedure Register;
begin
RegisterComponents('Custom', [TNotifyIcon]);
RegisterComponentEditor(TNotifyIcon,TNotifyIconEditor);
end;
procedure TNotifyIcon.Paint;
begin
if (csDesigning in ComponentState) then
begin
inherited;
Width:=32;
Height:=32;
With Canvas do
begin
if Assigned(FIcon) then
begin
Draw(0,0,FIcon);
end;
{
else
begin
Brush.Color:=clInfoBk;
Ellipse(0,0,Self.Width,Self.Height);
Font.Color:=clBlue;
Brush.Style:=bsClear;
FloodFill(5,5,clInfoBk,fsBorder);
Brush.Color:=clInfoBk;
TextOut(3,Self.Height div 2-6,'Notify');
end;
}
end;
end;
end;
procedure TNotifyIcon.NotifyIconClick(var msg : TMessage);
var p:TPoint;
begin
case msg.LParam of
WM_LBUTTONDOWN:
begin
GetCursorPos(p);
if Left_Click in FPopupStyle then
begin
SetForegroundWindow(FParentHandle);
FPopupMenu.Popup(p.x,p.y);
end;
if Assigned(FOnIconMouseDown) then
begin
FOnIconMouseDown(Self,p.x,p.y,b_Left);
end;
end;
WM_RBUTTONDOWN:
begin
GetCursorPos(p);
if Right_Click in FPopupStyle then
begin
SetForegroundWindow(FParentHandle);
FPopupMenu.Popup(p.x,p.y);
end;
if Assigned(FOnIconMouseDown) then
begin
FOnIconMouseDown(Self,p.x,p.y,b_Right);
end;
end;
WM_LBUTTONDBLCLK:
begin
GetCursorPos(p);
if Left_DbClick in FPopupStyle then
begin
SetForegroundWindow(FParentHandle);
FPopupMenu.Popup(p.x,p.y);
end;
if Assigned(FOnIconDoubleClick) then
begin
FOnIconDoubleClick(Self,p.x,p.y,b_Left);
end;
end;
WM_RBUTTONDBLCLk:
begin
GetCursorPos(p);
if Right_Click in FPopupStyle then
begin
SetForegroundWindow(FParentHandle);
FPopupMenu.Popup(p.x,p.y);
end;
if Assigned(FOnIconDoubleClick) then
begin
FOnIconDoubleClick(Self,p.x,p.y,b_Right);
end;
end;
end;
end;
constructor TNotifyIcon.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FIcon:=TIcon.Create;
Height:=32;
Width:=32;
Visible:=false;
FTitle:='Welcome';
FIconVisible:=false;
//-------------set tray info---------
try
if AOwner is TForm then
FParentHandle:=TForm(AOwner).Handle
else
FParentHandle:=GetParentForm(Self).Handle;
except
raise ECreateError.Create('创建NotifyIcon控件时发生了错误!');
end;
New(Fpda);
With FPda^ do
begin
uCallbackMessage:=WM_MY_Notify;
cbsize:=SizeOf(FPda^);
uID:=200;
wnd:=FParentHandle;
uFlags:=NIF_ICON+NIF_Tip+NIF_MESSAGE;
end;
end;
procedure TNotifyIcon.ShowIt(Accept:boolean);
begin
if Accept=true then ShowIcon
else HideIcon;
end;
procedure TNotifyIcon.SetIcon(Icon:TICON);
begin
FIcon.Assign(Icon);
if csDesigning in ComponentState then
Self.Refresh ;
end;
procedure TNotifyIcon.ShowIcon;
begin
if (Assigned(FIcon)) and (not FIconVisible) then
begin
if FIcon.Handle<>FPda^.hIcon then
HideIcon; //如果Icon改变了,先隐藏它
FPda^.hIcon:=FIcon.handle;
FIconVisible:=true;
Shell_NotifyIcon(NiM_ADD,FPda); //显示
end;
end;
procedure TNotifyIcon.HideIcon;
begin
if FIconVisible then
begin
FIconVisible:=false;
Shell_NotifyIcon(NiM_DELETE,FPda);
end;
end;
procedure TNotifyIcon.SetTitle(NewTitle:string);
begin
FTitle:=NewTitle;
StrCopy(FPda^.szTip,PChar(FTitle));
if FIconVisible then
begin
ModifyIcon(FIcon);
end;
end;
procedure TNotifyIcon.ModifyIcon(NewIcon:TIcon);
begin
SetIcon(NewIcon);
FPda^.hIcon:=FIcon.handle;
if FIconVisible then
Shell_NotifyIcon(NiM_Modify,FPda);
end;
function TNotifyIcon.IsShowing:boolean;
begin
Result:=FIconVisible;
end;
yes,with a timer,regularly change you window's icon,the icon in task bar will also changes.But I don't know how to make the shortcut on desktop icon also changes like the dialup link in w2k.