Solved

Mouse hovering

Posted on 2000-05-14
10
228 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
HTML text in the body of an email (delphi code) 12 120
TEMBEDDEDWB how can i change its user agent ? 8 58
RESTRequest Parameter 4 31
Twebbrowser add css to the header 3 25
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…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

810 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