Solved

Button on the Desktop!

Posted on 2000-04-06
9
167 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
 
LVL 1

Expert Comment

by:drnadeem
Comment Utility
listening
0
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 2

Expert Comment

by:craig_capel
Comment Utility
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
Comment Utility
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
Comment Utility
listenning
0
 
LVL 1

Expert Comment

by:fulg0re
Comment Utility
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
Comment Utility
Hope this helped

GL
Mike
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

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…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

763 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

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now