Solved

Button on the Desktop!

Posted on 2000-04-06
9
171 Views
Last Modified: 2010-04-04
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
Comment
Question by:Masonok
9 Comments
 

Expert Comment

by:perkley
ID: 2692274
Your right, very interesting, I will be checking into it and listening in case someone comes up with a good solution.
0
 
LVL 6

Expert Comment

by:edey
ID: 2692299
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
 
LVL 6

Expert Comment

by:DrDelphi
ID: 2692304
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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
LVL 1

Expert Comment

by:drnadeem
ID: 2693056
listening
0
 
LVL 2

Expert Comment

by:craig_capel
ID: 2693166
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
 
LVL 6

Accepted Solution

by:
edey earned 50 total points
ID: 2693846
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
 
LVL 3

Expert Comment

by:bryan7
ID: 2694284
listenning
0
 
LVL 1

Expert Comment

by:fulg0re
ID: 2694642
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
 
LVL 6

Expert Comment

by:edey
ID: 2697171
Hope this helped

GL
Mike
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

825 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