Solved

Mouse hovering

Posted on 2000-05-14
10
227 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
 
LVL 5

Expert Comment

by:Gwena
Comment Utility
listening
0
 
LVL 5

Expert Comment

by:Gwena
Comment Utility
listening
0
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 27

Expert Comment

by:kretzschmar
Comment Utility
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
Comment Utility
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
Comment Utility
H := WindowFromPoint(P);
while GetParent(H) <> 0 do
  H := GetParent(H);

Regards, Madshi.
0
 
LVL 17

Expert Comment

by:inthe
Comment Utility
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
Comment Utility
Okey-Dokey.
Thanx.
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

728 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now