run the code bwlow<br><br>unit Unit1;<br><br>interface<br><br>uses<br> Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,<br> ExtCtrls, StdCtrls, GIFImage;<br><br>const<br>MAX_BUFFER =10;<br><br>type<br> TForm1 = class(TForm)<br> Button1: TButton;<br> Button2: TButton;<br> Timer1: TTimer;<br> Image1: TImage;<br> Edit1: TEdit;<br> procedure Button1Click(Sender: TObject);<br> procedure Button2Click(Sender: TObject);<br> procedure Timer1Timer(Sender: TObject);<br> procedure FormCreate(Sender: TObject);<br> procedure FormDestroy(Sender: TObject);<br> private<br> { Private declarations }<br> public<br> HW : HWND;<br> DC : HDC;<br> R : TRect;<br> FNumber : integer;<br> Buffer : array[1..MAX_BUFFER] of TBitmap;<br> procedure CreateFrames;<br> procedure DestroyFrames;<br> procedure BuildFrames;<br> { Public declarations }<br> end;<br><br>var<br> Form1: TForm1;<br><br>implementation<br><br>{$R *.DFM}<br><br><br><br><br>procedure TForm1.CreateFrames; <br>var <br>i : integer; <br>begin <br> for i:=1 to MAX_BUFFER do<br> begin <br> Buffer := TBitmap.Create; <br> Buffer.Height := R.Bottom-R.Top; <br> Buffer.Width := R.Right-R.Left; <br> Buffer.Canvas.Brush.Color := clBtnFace;<br> Buffer.Canvas.Pen.Color := clBtnFace; <br> Buffer.Canvas.Rectangle(0,0,Buffer.Width,Buffer.Height); <br> end; <br>end; <br><br>procedure TForm1.DestroyFrames; <br>var <br>i : integer; <br>begin <br> for i:=1 to MAX_BUFFER do<br> begin <br> Buffer.Destroy; <br> end; <br>end; <br><br>// Prepare animation segments/sprites <br>procedure TForm1.BuildFrames; <br>var <br>i,j,k,H,W : integer; <br>Y : double;<br>begin <br>H := R.Bottom-R.Top; <br>W := R.Right-R.Left;<br>Image1.Width := W;<br>Image1.Height:= H;<br>for i := 1 to MAX_BUFFER-1 do //Buffer[MAX_BUFFER] is used to hold the original bitmap <br> for j:= 1 to W do <br> for k:=1 to H do <br> begin <br> Y := 2*Sin((j*360/W)*(pi/180)-20*i);<br> Buffer.Canvas.Pixels[j,k-Round(Y)]:= Buffer[6].Canvas.Pixels[j,k]; <br> end; <br>end; <br><br><br><br><br> <br><br><br><br>procedure TForm1.Button1Click(Sender: TObject);<br>begin<br>//Get the original button face and will be used later to revert<br>//the start button when animation is done<br> BitBlt(Buffer[MAX_BUFFER].Canvas.Handle,0,0,R.Right-R.Left,R.Bottom-R.Top,<br> DC,0,0,SRCCOPY);<br> BuildFrames;<br> Image1.Canvas.Draw(0,0,Buffer[MAX_BUFFER]);<br> Button2.Enabled := true;<br> if Edit1.Text <> '' then<br> Timer1.Interval := StrToInt(Edit1.Text)<br> else<br> begin<br> Timer1.Interval := 100;<br> Edit1.Text := '100';<br> end;<br>end;<br><br>procedure TForm1.Button2Click(Sender: TObject);<br>begin<br> Timer1.Enabled := not Timer1.Enabled;<br> if not Timer1.Enabled then<br> begin<br> BitBlt(DC,0,0,R.Right-R.Left,R.Bottom-R.Top,<br> Buffer[MAX_BUFFER].Canvas.Handle,0,0,SRCCOPY);<br> Button2.Caption := '&Animate';<br> Button1.Enabled := true;<br> end<br> else<br> begin<br> Button2.Caption := '&Stop';<br> Button1.Enabled := false;<br> end;<br>end;<br><br>procedure TForm1.Timer1Timer(Sender: TObject);<br>begin<br> BitBlt(DC,0,0,R.Right-R.Left,R.Bottom-R.Top, <br> Buffer[FNumber].Canvas.Handle,0,0,SRCCOPY);<br> Inc(FNumber);<br> if (FNumber > MAX_BUFFER-1) then FNumber := 1;<br><br>end;<br><br>procedure TForm1.FormCreate(Sender: TObject);<br>begin<br> HW := FindWindowEx(FindWindow('Shell_TrayWnd',nil),0,'Button',nil);<br> GetWindowRect(HW,R);<br> DC := GetWindowDC(HW);<br> CreateFrames;<br> FNumber :=1;<br>end;<br><br>procedure TForm1.FormDestroy(Sender: TObject);<br>begin<br>Timer1.Enabled := false; <br> BitBlt(DC,0,0,R.Right-R.Left,R.Bottom-R.Top,<br> Buffer[MAX_BUFFER].Canvas.Handle,0,0,SRCCOPY);<br> ReleaseDC(HW,DC);<br> DestroyFrames; // don't ever forget to do this !<br>end;<br><br>end.<br><br>