Hook Needed

I need a "What did I just left click on?" hook.

Cheers, Chris.
LVL 1
she3i3iAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

craig_capelCommented:
Well.. all i want to know is how do you catch a left mouse click? IE when it takes place... i wrote a program already (with out hooks) what you want to do....

var
  buffer: array[0..50] of char;
  p: trect;
  n: integer;
  result: byte;
  x,y,num,num1,num2: integer;
  wnd,wnd2: hwnd;
  p2: tpoint;
  i1 : integer;
   s1 : string;
begin
num:=getmessagepos();
 num1:=hiword(num);
 num2:=loword(num);
 p2.y:=num1;
p2.x:=num2;
wnd:=windowfrompoint(p2);
edit1.text:=inttostr(num2);
edit2.text:=inttostr(num1);
end;

sorry for all the vars, i couldent be bothered sorthing them out for this one snippet.....

See if that is what you need... put it in a timer, set to 1 (default 1000)...
0
craig_capelCommented:
and yes.... wnd = the handle of the button you pressed....
0
ckanetaCommented:
Here is one way to capture left button clicks:
add this to your class declaration(before all the private/public stuff)
procedure MessageLoop(var Msg:TMsg;var Handled:Boolean);

and here is what the function does
procedure Tmnfrm.MessageLoop(var Msg: TMsg; var Handled: Boolean);
 begin
  if (Msg.Message = WM_LBUTTONDOWN) or (Msg.Message = WM_LBUTTONUP) then
 {do some stuff}
 end;

hope I was at least a little helpful

Carl
0
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

craig_capelCommented:
dont kno about him.... but me, I owe you big time if that code works :) :) :) :) :) :) :)

It means one step close to writing Pcanywhere / Laplink (as if!)

Craig C.
0
rwilson032697Commented:
Listening
0
she3i3iAuthor Commented:
Adjusted points to 50
0
she3i3iAuthor Commented:
Craig, I have tried your code and cannot seem to figure what I must do with wnd in order to find which button was actually clicked.

Carl, my question is...
"WHAT did I just left click on?" and not "DID I just left click?".

Increasing points to 50.

Cheers, Chris.

P.S. I've spent a whole day on the subject and I'm still stuck.
0
craig_capelCommented:
well once you got the private  declaration to work, which i could not.... its easy, the handle from my code will give you the window once you catch the left mouse click....


Ok Put a timer on your form, then put *3* edit boxes on and set the timer to 1 from 1000 and just copy the code needed, dont copy and paste it all, just copy the bits out of it, so it looks more or less as yours...

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, ExtCtrls;

type
  TForm1 = class(TForm)
    Timer1: TTimer;
    Edit1: TEdit;
    Edit2: TEdit;
    Edit3: TEdit;
    procedure Timer1Timer(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
                     var
                     buffer: array[0..50] of char;
                     p: trect;
                     n: integer;
                     result: byte;
                     x,y,num,num1,num2: integer;
                     wnd,wnd2: hwnd;
                     p2: tpoint;
                     i1 : integer;
                      s1 : string;

implementation

{$R *.DFM}

procedure TForm1.Timer1Timer(Sender: TObject);
                   begin
                   num:=getmessagepos();
                    num1:=hiword(num);
                    num2:=loword(num);
                    p2.y:=num1;
                   p2.x:=num2;
                   wnd:=windowfrompoint(p2);
                   edit1.text:=inttostr(num2);
                   edit2.text:=inttostr(num1);
                   edit3.text:=inttostr(wnd);
                   end;
end.

Here is one way to capture left button clicks:
                   add this to your class declaration(before all the private/public stuff)
                   procedure MessageLoop(var Msg:TMsg;var Handled:Boolean);

                   and here is what the function does
                   procedure Tmnfrm.MessageLoop(var Msg: TMsg; var Handled: Boolean);
                    begin
                     if (Msg.Message = WM_LBUTTONDOWN) or (Msg.Message = WM_LBUTTONUP) then
                    {do some stuff}
                    end;

                   hope I was at least a little helpful

                   Carl

That when combined with carl's code, that should be it...... I have not been able to get his code to work yet....

Trying now at work....
0
craig_capelCommented:
Yeah same problem....

Carl, if you can post all the source code for example, new app then just fill in the code you have shown us... i will get this code to work together... then i will let you have all the points... i will do the hardwork? :)

Cos i am pretty low on points, is that ok?
0
ckanetaCommented:
left on minor thing out, to get my little code snippet to work, one must add this line in the Create function of the form:
application.OnMessage:=MessageLoop;

and I'm working on getting it to do what you want now...
0
ckanetaCommented:
and here it is ---------->

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls,OleCtrls, Menus;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Edit1: TEdit;
    Edit2: TEdit;
    Edit3: TEdit;
    Button2: TButton;
    Button3: TButton;
    Label1: TLabel;

    procedure MessageLoop(var Msg:TMsg;var Handled:Boolean);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  p : TPoint;
  num,num1,num2: integer;

implementation

{$R *.DFM}
{------------------------------------------------------------------------------}
procedure TForm1.MessageLoop(var Msg: TMsg; var Handled: Boolean);
var W : TWinControl;
 begin
  if (Msg.Message = WM_LBUTTONDOWN) or (Msg.Message = WM_LBUTTONUP) then begin
   num:=getmessagepos();
   num1:=hiword(num);   num2:=loword(num);
   p.y:=num1;           p.x:=num2;
   edit1.text:=inttostr(num2);
   edit2.text:=inttostr(num1);
   edit3.text:=inttostr(wnd);
   w:=FindVCLWindow( P );
   if w <> nil then label1.caption:=w.Name;
  end;
 end;
procedure TForm1.FormCreate(Sender: TObject);
 begin application.OnMessage:=MessageLoop; end;

end.

this actually puts the name of the component into the caption of label1.  so there ya have it.  
hope its what you needed!
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ckanetaCommented:
oh, yeah, get rid of that edit3:=inttostr(wnd); line.
0
she3i3iAuthor Commented:
Right on!
0
craig_capelCommented:
Well, i tried it, but it would only capture the clicks from the Form itself... i use getclassname to get the info you got with findvcl... Yep... major problem, it may be my delphi 4 that does it?...
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.