If you have mnay controls on your Form and do not want to add the same code to all their MouseMove events, simply use the following instead.
Add it to a Form with a Timer and a CommandButton.
Code:Private Declare Function WindowFromPoint Lib "user32" (ByVal xPoint As Long, ByVal yPoint As Long) As Long Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long Private Type POINTAPI x As Long y As Long End Type Private Sub Form_Load() Timer1.Interval = 1 End Sub Private Sub Timer1_Timer() Dim PT As POINTAPI Dim WND As Long 'Get the Cursor postion and the hWnd it's on GetCursorPos PT WND = WindowFromPoint(PT.x, PT.y) 'Check if the hWnd the mouse is over is Command1 If WND = Command1.hWnd Then Command1.Caption = "Mouse is on Command1" Else Command1.Caption = "Mouse is not on Command1" End Sub




Reply With Quote