Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 201
  • Last Modified:

Animate an image around the desktop

Hi I want to animate an image around the desktop, it has to be the top most window, any ideas.
0
julianpointer
Asked:
julianpointer
  • 4
  • 3
  • 3
  • +6
1 Solution
 
StevenBCommented:
 You can use a component set from somebody like http://www.cooldev.com/ (CoolControls) which will allow you to set up shaped forms clipped to an animated set of regions.

  If you want to do the work yourself then you will be using the SetWindowRgn call which allows you to clip a window to any shaped region. by cycling an animated set of regions you can generate an animated shaped form.

  If you're interested in this approach then I can provide further information, and if I have time :o) I'll write you a small demonstration. It's not actually as much work to do what you want as it might first appear.

  Steven
0
 
lopemCommented:
listening...
0
 
Stuart_JohnsonCommented:
Same here..
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
StevenBCommented:
 Try this:

  1) Create a new application

  2) Place a TImageList and A TTimer on the form.

  3) Paste this as the forms code:

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  ExtCtrls, ImgList, StdCtrls;

type
  TForm1 = class(TForm)
    ImageList1: TImageList;
    Timer1: TTimer;
    procedure Timer1Timer(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure FormPaint(Sender: TObject);
  private
    fCurrentImage : Integer;
    fTransparentColour : TColor;
    procedure DoDraw;
    procedure ApplicationDeactivate(Sender: TObject);
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

function RegionFromBitmap(ABitmap : Graphics.TBitmap; TransparentColour : TColor): HRGN;
var
  x, y           : integer;
  Rgn1, Rgn2  : hrgn;
  Startx : integer;
  InTransparent : Boolean;
begin
  Rgn1 := 0;
  For y := 0 to ABitmap.Height-1 do begin
    Startx := 0;
    InTransparent := True;
    For x := 0 to ABitmap.Width do begin
      If (ABitmap.Canvas.Pixels[x, y] = TransparentColour) or (x = ABitmap.Width) then begin
        If Not InTransparent then begin
          if Rgn1 = 0 then begin
            Rgn1 := CreateRectRgn(Startx, y, x, y+1);
          end
          else begin
            Rgn2 := CreateRectRgn(Startx, y, x, y+1);
            if Rgn2 <> 0 then CombineRgn(Rgn1, Rgn1, Rgn2, RGN_OR);
            DeleteObject(Rgn2);
          end;
        end;
        InTransparent := True;
      end
      else begin
        If InTransparent then begin
          Startx := x;
        end;
        InTransparent := False;
      end;
    end;
  end;
  Result := Rgn1;
end;

procedure TForm1.DoDraw;
begin
  ImageList1.Draw(Canvas, 0, 0, fCurrentImage);
end;

procedure TForm1.ApplicationDeactivate(Sender: TObject);
begin
  Application.RestoreTopMosts
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  fCurrentImage := 0;
  fTransparentColour := RGB(255,0,255); // or whatever your transparent colour is
  ClientWidth := ImageList1.Width;
  ClientHeight := ImageList1.Height;
  BorderStyle := bsNone;
  FormStyle := fsStayOnTop;

  Timer1.OnTimer := Timer1Timer;
  OnPaint := FormPaint;

  Timer1Timer(Self);
  Application.OnDeactivate := ApplicationDeactivate;
end;

procedure TForm1.Timer1Timer(Sender: TObject);
var
  ABitmap : TBitmap;
  ARegion : HRGN;
begin
  ABitmap := TBitmap.Create;
  try
    Inc(fCurrentImage);
    If fCurrentImage > ImageList1.Count-1 then fCurrentImage := 0;

    ImageList1.GetBitmap(fCurrentImage, ABitmap);

    ARegion := RegionFromBitmap(ABitmap, fTransparentColour);
    SetWindowRgn(Handle, ARegion, True);
    DeleteObject(ARegion);
  finally
    ABitmap.Free;
  end;
end;

procedure TForm1.FormPaint(Sender: TObject);
begin
  DoDraw;
end;

end.


  4) Hook up the Timer's Timer event and the form's Create and Paint event to the appropriate procedures.

  5) Set the ImageList's Masked property to false and its width and height properties to the correct values for your animation frame Bitmaps.

  6) Load the animation frames into the ImageList

  7) Set the fTransparentColour variable to the correct value for your animation frames.

  8) Save and Run the project.


  Steven.
0
 
ginsonicCommented:
Give me your address to send you a sample project .
0
 
julianpointerAuthor Commented:
julian_p@pegasus.org.nz
0
 
StevenBCommented:
 How are you solving the problem ginsonic?
0
 
DidierDCommented:
listening...
0
 
ginsonicCommented:
I have found some time ago a sample on net named Xmas .
I just send it to Julian.
0
 
gemartiCommented:
Do you want the object to just float around the desktop randomly?
Do you want it to behave the same way the mouse cursor does?
Do you want it to be stationary?
Do you want to move to specific locations at specific times?


0
 
jeurkCommented:
Hi,
I have a perfect sample to show you how to do this...
go here:
http://www.cs.ust.hk/~cpegnel/desk_spr.html

Of course, there are problems with such a sample because drawing directly to the screen will avoid you
from interacting with the screen mate.

To make real transparent windows, not using the WS_EX_TRANSPARENT trick listen to StevenB :)

John.
0
 
edeyCommented:
Or how about using the MS Agent SDK? - ie. the office "Clippy"

GL
Mike
0
 
julianpointerAuthor Commented:
jeurk, I have that sample, The only problem with it is I need it to animate over the foreground window. With this sample I can't seem to get it to do this nicely when the user either scrolls or moves the window, sprites get left behind on the forground window. The sample works great behin the forground window
0
 
jeurkCommented:
Yes, that's the problem with it...
You could try to use a faster refresh rate...
If this does not satisfy you, you'll stuck to a component like coolform...
Those kind of components are transforming the rectangular shape of your windows to adapt to the form you want.

Now there is one solution left use layered forms. But this is only working under win2k...
Either use the TdfsLayeredForm component here:
ftp://ftp.delphifreestuff.com/pub/mine/dfslayeredform.zip

If you have D6, then you can just use the transparency options of your forms...

John.
0
 
ginsonicCommented:
My small sample keep allways you graphic on top .
0
 
ginsonicCommented:
julianpointer ,
I can't send you the project . I receive an error message from your pegasus server .
0
 
julianpointerAuthor Commented:
ginsonic
Thanks for the sample, this sample also has a similar problem, move notepad aroubd the edges, you get xmas lights on the page..

0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 4
  • 3
  • 3
  • +6
Tackle projects and never again get stuck behind a technical roadblock.
Join Now