PDA

View Full Version : How would one make something like this?



EvilChicken!
08-22-2010, 09:06 PM
(Sorry for stupid title.)

Basically, this (http://www.megaupload.com/?d=ITTFK3N0) is an example of a program I want to be able to make.
Main thing I'm wondering about, is how do I make the background transparent -- and how do I make it draggable?

Short: Need to make an app that displays a draggable image on my desktop with a transparent background, i.ex. some sort of mascot. Preferably animated.

nielsie95
08-22-2010, 09:10 PM
type
TForm1 = class(TForm)
procedure CreateParams(var Params:TCreateParams); override;
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.CreateParams(var Params:TCreateParams);
Begin
inherited CreateParams(Params);
Params.ExStyle:=WS_EX_TRANSPARENT;
End;

procedure TForm1.FormCreate(Sender: TObject);
begin
Form1.Brush.Style:=bsClear;
Form1.BorderStyle:=bsNone;
end;

Source (http://1www.scriptmania.com/delphi.htm#dtnt4)

You'll have to handle the moving yourself.

I couldn't download your program, but I think this is what you want?

EvilChicken!
09-05-2010, 01:33 PM
Ah, thanks a lot, Niels. Sorry for ignoring this for so long, but as I really am not any good with Delphi, motivation hasn't been on top.. Anyway, this is what I have so far:

unit Unit1;

interface

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

type
TForm1 = class(TForm)
Image1: TImage;
procedure CreateParams(var Params:TCreateParams); override;
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
procedure WMNCHitTest(var M: TWMNCHitTest);
message wm_NCHitTest;
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.CreateParams(var Params:TCreateParams);
begin
inherited CreateParams(Params);
Params.ExStyle:=WS_EX_TRANSPARENT;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
BorderStyle:=bsNone;
Brush.Style:=bsClear;
Width:=Image1.Width;
Height:=Image1.Width;
end;

procedure TForm1.WMNCHitTest(var M: TWMNCHitTest);
begin
inherited;
if (M.Result = htClient) then
M.Result := htCaption;
end;

end.


Thing is, whenever I move the form around, the background of the form doesn't refresh. Any tips?

Rick
09-05-2010, 03:09 PM
Shouldn't



Height:=Image1.Width;


be



Height:=Image1.Height;


Also, I think you should be able to refresh it with:



Self.Refresh;
Image1.Refresh;

EvilChicken!
09-05-2010, 07:48 PM
Thanks for pointing out the width/height thingy.
As for refreshing, it didn't help. Neither did Repaint;

Daniel
09-06-2010, 11:24 AM
Thing is, whenever I move the form around, the background of the form doesn't refresh. Any tips?
What do you mean it "doesn't refresh"?


Shouldn't
Also, I think you should be able to refresh it with:



Self.Refresh;
Image1.Refresh;


The statement, Image1.Refresh is unnecessary, as when you call Self.Refresh it forces and invalidates its client area, redraws itself and likewise for its' child components.

EvilChicken!
09-06-2010, 03:19 PM
@^: the supposedly "bsClear" area stays the same as to what it was at FormCreate, so the form background is simply a segment of the compiler in the background.

Sorry for not being able to post any screens, I'm at my girlfriend's place at the moment.