• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 181
  • Last Modified:

Button on the Desktop!

Hi everyone!
I have a 1 form and 1 button on it! (It's a sample). By pressing on Button1 should be created Button2 on Windows Desktop (or somewhere else).

Procedure TForm1.Proc1(Sender : TObject);
begin
  ShowMessage('Cool');
end;

procedure TForm1.Button1Click(Sender: TObject);
var MyBut : TButton;
begin
  MyBut:=TButton.Create(nil);
(1)//MyBut.ParentWindow:=Form1.Handle;
(2)MyBut.ParentWindow:=GetDesktopWindow;
  MyBut.Caption:='MyBut';
  MyBut.onclick:=Proc1;
end;

Check this out - (1) is working properly - it is create MyButton and This button shows Message "COOL",
But... (2) I see the Button, I can change Caption but... OnClick doesn't work and also on task bar appear one more button(as for application)

What else? May be..... HEEEELP Please!!
0
Masonok
Asked:
Masonok
1 Solution
 
perkleyCommented:
Your right, very interesting, I will be checking into it and listening in case someone comes up with a good solution.
0
 
edeyCommented:
Can't seem to get any kind of control to accept focus.  You could, however just stick em on a form sized fit.

GL
Mike
0
 
DrDelphiCommented:
The problem is that you are not catching the mouse messages for the button created on the desktop. When you made the form the parent, the form handled the messaging. For the desktop button, you will need to use the SetCapture API to capture the mouse messages.


Good luck!!
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
drnadeemCommented:
listening
0
 
craig_capelCommented:
delphi, so you capture the mouse messages, and everytime someone clicks... you then do (manually) button.click; And simulate it?.... I have code to capture the mouse clicks, just that this code was given to me, but i could never use it due to stability...... ok heres the code.....

http://tenerife1.com/cjc/catchd4.zip  <<If you can get this more stable, this will help you.....
0
 
edeyCommented:
sorry craig, I haven't yet checked out your code.  The problem was really interesting though, and so I did some digging.  Started out with a TButton descendant that captured WM_NCHITTEST, just to see if the control recieved any mouse messages (couldn't btw get any control to recieve focus so thought I'd try this).  Seems the button gets all kinds of 'em :).  So tried capturing WM_LBUTTONUP (with a hack to avoid "double clicks") and, voila, it works!  I have attached the source:

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, stdCtrls;

type
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
    procedure setBtnToDeskTop(sender : TObject);
  end;
  TMyButton = class(TButton)
  private
     FForm : TForm;
     procedure doWMNCHITTEST(var msg : TWMNCHITTEST);message WM_NCHITTEST;
     procedure doLBUTTONUP(var msg : TWMLBUTTONUP);message WM_LBUTTONUP;
     procedure setForm(value : TForm);
  public
     constructor create(AOwner : TComponent);override;
  published
     property form : TForm read FForm write setForm;
  end;
var
  Form1: TForm1;
  btn : TMyButton;

implementation

{$R *.DFM}

constructor TMyButton.create(AOwner : TComponent);
begin
     inherited;
     FForm := nil;
end;

procedure TMyButton.setForm(value : TForm);
begin
     if value <> FForm then
        FForm := value;
end;

procedure TMyButton.doWMNCHITTEST(var msg : TWMNCHITTEST);
begin
     inherited;
     FForm.caption := intToStr(msg.XPos)+','+intToStr(msg.ypos);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
     btn := TMyButton.create(self);
     btn.parent := nil;
     btn.parentWindow := handle;
     btn.form := self;
     btn.caption := 'Click Me!';
     btn.OnClick := setBtnToDeskTop;
end;

procedure TForm1.setBtnToDeskTop(sender : TObject);
begin
     if btn.parentWindow = getDeskTopWindow then
        btn.parentWindow := handle
     else
         btn.parentWindow := getDeskTopWindow;
     btn.bringToFront;
     btn.tag := 1;
end;

procedure TMyButton.doLBUTTONUP(var msg : TWMLBUTTONUP);
begin
     inherited;
     if tag = 0 then
        click
     else
         tag := 0;
end;

end.




GL
Mike
0
 
bryan7Commented:
listenning
0
 
fulg0reCommented:
well, the simplest way of creating an 'alien' button in other application was well described by Alex Xacker from utilmind.com - he shows how to put tbutton in calc.exe... go there and check it out...
0
 
edeyCommented:
Hope this helped

GL
Mike
0

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now