[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 208
  • Last Modified:

what Control is the mouse over?

what is the best way to find out which control the mouse is over (only one form)
Without having to fill the mousemove from every control
0
Mark_FreeSoftware
Asked:
Mark_FreeSoftware
1 Solution
 
iHadiCommented:
Hi Mark_FreeSoftware

To get the handle of the control the mouse is over, add a timer and any other controls on your form and past the following code:

Private Type RECT
    Left As Long
    Top As Long
    Right As Long
    Bottom As Long
End Type
Private Declare Function ChildWindowFromPoint Lib "user32" (ByVal hwnd As Long, ByVal xPoint As Long, ByVal yPoint As Long) As Long
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Declare Function ClientToScreen Lib "user32" (ByVal hwnd As Long, lpPoint As POINTAPI) As Long

Private Sub Timer1_Timer()
Dim CursorPos As POINTAPI
Dim pt As POINTAPI
Dim ChildHandle As Long
Dim ClientRect As RECT
Dim Res As Long

Res = GetCursorPos(CursorPos)
ClientToScreen Me.hwnd, pt
ChildHandle = ChildWindowFromPoint(Me.hwnd, CursorPos.X - pt.X, CursorPos.Y - pt.Y)
Label1 = pt.X & " " & pt.Y
End Sub
0
 
Mark_FreeSoftwareAuthor Commented:
sorry for my late reaction, was quite busy.


it works!
thank you very much






for future reference, here is the full code i used:


Option Explicit

Private Type RECT
    Left As Long
    Top As Long
    Right As Long
    Bottom As Long
End Type

Private Type POINTAPI
        x As Long
        y As Long
End Type

Private Declare Function ChildWindowFromPoint Lib "user32" (ByVal hwnd As Long, ByVal xPoint As Long, ByVal yPoint As Long) As Long
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Declare Function ClientToScreen Lib "user32" (ByVal hwnd As Long, lpPoint As POINTAPI) As Long

Private Sub Timer1_Timer()
Dim CursorPos As POINTAPI
Dim pt As POINTAPI
Dim ChildHandle As Long
Dim ClientRect As RECT
Dim Res As Long

Res = GetCursorPos(CursorPos)
ClientToScreen Me.hwnd, pt
ChildHandle = ChildWindowFromPoint(Me.hwnd, CursorPos.x - pt.x, CursorPos.y - pt.y)
Select Case ChildHandle
Case Command1.hwnd
   Label1 = Command1.Name
Case Command2.hwnd
   Label1 = Command2.Name
Case Command3.hwnd
   Label1 = Command3.Name
Case Command4.hwnd
   Label1 = Command4.Name
End Select
End Sub
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now