Solved

Animate an image around the desktop

Posted on 2001-07-26
17
187 Views
Last Modified: 2013-11-19
Hi I want to animate an image around the desktop, it has to be the top most window, any ideas.
0
Comment
Question by:julianpointer
  • 4
  • 3
  • 3
  • +6
17 Comments
 
LVL 4

Accepted Solution

by:
StevenB earned 200 total points
ID: 6325081
 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
 
LVL 3

Expert Comment

by:lopem
ID: 6325301
listening...
0
 
LVL 6

Expert Comment

by:Stuart_Johnson
ID: 6325352
Same here..
0
 
LVL 4

Expert Comment

by:StevenB
ID: 6325540
 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
 
LVL 9

Expert Comment

by:ginsonic
ID: 6325574
Give me your address to send you a sample project .
0
 
LVL 3

Author Comment

by:julianpointer
ID: 6325579
julian_p@pegasus.org.nz
0
 
LVL 4

Expert Comment

by:StevenB
ID: 6325612
 How are you solving the problem ginsonic?
0
 
LVL 2

Expert Comment

by:DidierD
ID: 6326061
listening...
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 9

Expert Comment

by:ginsonic
ID: 6326253
I have found some time ago a sample on net named Xmas .
I just send it to Julian.
0
 
LVL 21

Expert Comment

by:gemarti
ID: 6326862
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
 
LVL 4

Expert Comment

by:jeurk
ID: 6327009
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
 
LVL 6

Expert Comment

by:edey
ID: 6328201
Or how about using the MS Agent SDK? - ie. the office "Clippy"

GL
Mike
0
 
LVL 3

Author Comment

by:julianpointer
ID: 6328497
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
 
LVL 4

Expert Comment

by:jeurk
ID: 6328639
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
 
LVL 9

Expert Comment

by:ginsonic
ID: 6329235
My small sample keep allways you graphic on top .
0
 
LVL 9

Expert Comment

by:ginsonic
ID: 6329449
julianpointer ,
I can't send you the project . I receive an error message from your pegasus server .
0
 
LVL 3

Author Comment

by:julianpointer
ID: 6332317
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Strange behavior when a form is closed 6 51
Select distinct 25 83
Base1 Encode/Decode 3 68
Moving (cutting/pasting) controls in a TTabbedNotebook... 7 27
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now