Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Animate an image around the desktop

Posted on 2001-07-26
17
Medium Priority
?
200 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 600 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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
 
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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

916 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