Solved

Mouse hovering

Posted on 2000-05-14
10
232 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
[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
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

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…
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

726 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