Tech or Treat! Write an article about your scariest tech disaster to win gadgets!Learn more

x
?
Solved

Button on the Desktop!

Posted on 2000-04-06
9
Medium Priority
?
179 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Suggested Courses

647 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