實際上我提問時換了一個提法﹐實際上是一樣的。
以下是我寫的一個控件﹐我想做一個能實現超級解霸那個不斷的更換ICON
unit HxAnimateIcon;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,extctrls;
type
tHxAnimateIcon = class(tcomponent)
private
FImageList: TImageList;
FAnimate: Boolean;
FSpeed: Integer;
CurImageId:Integer;
AnimateWindow:TForm;
FAbout: TCollection;
OldWindowIcon:TIcon;
OldApplicationIcon:TIcon;
FEnableAnimateAppIcon: Boolean;
procedure SetImageList(const Value: TImageList);
procedure SetAnimate(const Value: Boolean);
procedure SetSpeed(const Value: Integer);
procedure SetAbout(const Value: TCollection);
procedure SetEnableAnimateAppIcon(const Value: Boolean);
{ Private declarations }
protected
{ Protected declarations }
Timer:TTimer;
procedure Ontimer(Sender:TObject);
public
constructor Create(Owener:TComponent);override;
destructor Destory;
{ Public declarations }
published
{ Published declarations }
property ImageList:TImageList read FImageList write SetImageList;
property Animate:Boolean read FAnimate write SetAnimate;
property EnableAnimateAppIcon:Boolean read FEnableAnimateAppIcon write SetEnableAnimateAppIcon;
property Speed:Integer read FSpeed write SetSpeed;
property About:TCollection read FAbout write SetAbout;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('Holy Soft', [tHxAnimateIcon]);
end;
{ tHxAnimateIcon }
constructor tHxAnimateIcon.Create(Owener: TComponent);
var
I:Integer;
begin
if not (Owener is TForm) then
Begin
ShowMessage('This Component is only on a form!');
Abort;
Exit;
end;
for I:=0 to (Owener As TForm).ComponentCount-1 do
if (Owener As TForm).Components is tHxAnimateIcon then
Begin
ShowMessage('There is alredy have a tHxAnimateIcon on this form﹐'+#13+'Can''t have an other one!');
Abort;
Exit;
end;
inherited Create(Owener);
Self.AnimateWindow:=(Owener As TForm);
self.OldWindowIcon:=TIcon.create;
self.OldApplicationIcon:=TIcon.Create ;
self.OldWindowIcon.Assign(self.Animatewindow.Icon);
self.OldApplicationIcon.Assign(Application.Icon);
Self.CurImageId :=0;
Self.Speed :=1000;
Self.Animate :=True;
Self.ImageList:=TImageList.Create(Self);
Self.ImageList:=nil;
Timer:=TTimer.Create(Self);
Timer.Interval :=Self.Speed ;
Timer.Enabled :=Self.Animate ;
Timer.OnTimer:=Self.Ontimer ;
end;
destructor tHxAnimateIcon.Destory;
begin
Timer.Free;
ImageList.Free;
showMessage('asfasfd');
self.AnimateWindow.icon.assign(self.OldWindowIcon);
application.Icon.Assign(self.oldApplicationIcon);
self.OldWindowIcon.free;
self.OldApplicationIcon.free;
end;
procedure tHxAnimateIcon.Ontimer(Sender: TObject);
var
temIcon:TIcon;
begin
if Self.FImageList<>nil then
begin
Self.CurImageId:=Self.CurImageId+1;
if Self.CurImageId>FImageList.Count-1 then
Self.CurImageId:=0;
temIcon:=TIcon.Create ;
FImageList.GetIcon(CurImageId,temIcon);
Self.AnimateWindow.Icon.Assign(temIcon);
if self.EnableAnimateAppIcon then
application.Icon.Assign(temIcon);
temIcon.Free;
end;
end;
procedure tHxAnimateIcon.SetAbout(const Value: TCollection);
begin
end;
procedure tHxAnimateIcon.SetAnimate(const Value: Boolean);
begin
FAnimate := Value;
If Not Value then
begin
self.AnimateWindow.Icon.Assign(self.OldWindowIcon );
application.Icon.Assign(self.oldApplicationIcon);
end;
if Timer<>nil then
Timer.Enabled :=Value;
end;
procedure tHxAnimateIcon.SetEnableAnimateAppIcon(const Value: Boolean);
begin
FEnableAnimateAppIcon := Value;
If Not Value then
Application.Icon.Assign(self.OldApplicationIcon );
end;
procedure tHxAnimateIcon.SetImageList(const Value: TImageList);
begin
FImageList := Value;
end;
procedure tHxAnimateIcon.SetSpeed(const Value: Integer);
begin
FSpeed := Value;
if Timer<>nil then
Timer.Interval :=Value;
end;
end.