Results 1 to 7 of 7

Thread: How would one make something like this?

  1. #1
    Join Date
    Jul 2007
    Location
    Norway.
    Posts
    1,938
    Mentioned
    3 Post(s)
    Quoted
    0 Post(s)

    Default How would one make something like this?

    (Sorry for stupid title.)

    Basically, this 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.

  2. #2
    Join Date
    Sep 2006
    Posts
    6,089
    Mentioned
    77 Post(s)
    Quoted
    43 Post(s)

    Default

    delphi Code:
    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

    You'll have to handle the moving yourself.

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

  3. #3
    Join Date
    Jul 2007
    Location
    Norway.
    Posts
    1,938
    Mentioned
    3 Post(s)
    Quoted
    0 Post(s)

    Default

    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:

    delphi Code:
    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?

  4. #4
    Join Date
    Oct 2006
    Posts
    500
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Shouldn't

    Code:
      Height:=Image1.Width;
    be

    Code:
      Height:=Image1.Height;
    Also, I think you should be able to refresh it with:

    Code:
      Self.Refresh;
      Image1.Refresh;

  5. #5
    Join Date
    Jul 2007
    Location
    Norway.
    Posts
    1,938
    Mentioned
    3 Post(s)
    Quoted
    0 Post(s)

    Default

    Thanks for pointing out the width/height thingy.
    As for refreshing, it didn't help. Neither did Repaint;

  6. #6
    Join Date
    Dec 2006
    Location
    Sydney, New South Wales, Australia
    Posts
    4,603
    Mentioned
    15 Post(s)
    Quoted
    42 Post(s)

    Default

    Quote Originally Posted by EvilChicken! View Post
    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"?

    Quote Originally Posted by r!ch!e View Post
    Shouldn't
    Also, I think you should be able to refresh it with:

    Code:
      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.
    You may contact me with any concerns you have.
    Are you a victim of harassment? Please notify me or any other staff member.

    | SRL Community Rules | SRL Live Help & Chat | Setting up Simba | F.A.Q's |

  7. #7
    Join Date
    Jul 2007
    Location
    Norway.
    Posts
    1,938
    Mentioned
    3 Post(s)
    Quoted
    0 Post(s)

    Default

    @^: 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.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •