Solved

Mouse hovering

Posted on 2000-05-14
10
230 Views
Last Modified: 2010-04-04
How to detect the handle of a window that the mouse is hovering over?
0
Comment
Question by:duke_n
  • 3
  • 3
  • 2
  • +2
10 Comments
 
LVL 17

Expert Comment

by:inthe
ID: 2809658
hi,
to get the handle and classname of control/window under mouse you can use :

var
classname: array[0..254] of char;
h : hwnd;
begin
h := WindowFromPoint(TControl(Sender).ClientToScreen(Point(X, Y)));
GetClassName(h, classname, 254);

Regards Barry

0
 
LVL 1

Author Comment

by:duke_n
ID: 2811156
That's nice.

But I need it to give me the window handle even If I'm pointing on a button in that window.
0
 
LVL 17

Expert Comment

by:inthe
ID: 2811746
well you could put something like this on a timer(set to 100)

procedure TForm1.Timer1Timer(Sender: TObject);
var
mp,i1,i2: integer;
p: tpoint;
h : hwnd;
begin
 mp:=getmessagepos();
  i1:=hiword(mp);
  i2:=loword(mp);
    p.y:=i1;
    p.x:=i2;
   h:=windowfrompoint(p);
  edit1.text :=
'mouse is over handle ' +inttostr(h);
end;
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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.

 
LVL 5

Expert Comment

by:Gwena
ID: 2811831
listening
0
 
LVL 5

Expert Comment

by:Gwena
ID: 2811835
listening
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 2813339
hi all,

what about

var
  P : TPoint;
  H : THandle;
begin
  GetCursorpos(P);      //Get MousePos
  H := WindowFromPoint(P); //Get WindowHandle
end;

meikl
0
 
LVL 1

Author Comment

by:duke_n
ID: 2813993
Barry, your [second] solution is kinda strange.
It detects mouse position change from control to control on my app window, yet doesn't always detect mouse pos change from WINDOW to WINDOW.

And Meikl, your solution looks a whole lot like barry's first one. And I repeat what I didn't like there: it detects mouse pos change from control to control(windowed controls in the same "big" window).
0
 
LVL 20

Accepted Solution

by:
Madshi earned 100 total points
ID: 2814018
H := WindowFromPoint(P);
while GetParent(H) <> 0 do
  H := GetParent(H);

Regards, Madshi.
0
 
LVL 17

Expert Comment

by:inthe
ID: 2814978
oh i misunderstood duke_n's comment.
you want no matter what control the cursor is over it tells you the window handle.
{i thought you wanted to know the handle of whatever control the cursor was over..}
my mistake.
madshis last commment should sort it out .
cheers Barry
0
 
LVL 1

Author Comment

by:duke_n
ID: 2817506
Okey-Dokey.
Thanx.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

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…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

828 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