?
Solved

Button on the Desktop!

Posted on 2000-04-06
9
Medium Priority
?
178 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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 200 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Suggested Courses
Course of the Month13 days, 13 hours left to enroll

801 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