VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



This is one way to determine if the mouse is over a form.

by Hugh Musser (8 Submissions)
Category: Windows API Call/Explanation
Compatability: Visual Basic 5.0
Difficulty: Unknown Difficulty
Originally Published: Wed 23rd October 2002
Date Added: Mon 8th February 2021
Rating: (1 Votes)

This is one way to determine if the mouse is over a form.

API Declarations


Add a check box named Check1.
Add a timer named Timer1.
Add the code below to your form.

Rate This is one way to determine if the mouse is over a form.




Private Type POINTAPI
    X As Long
    Y As Long
End Type

Private Declare Function GetParent Lib "user32.dll" (ByVal hwnd As Long) As Long
Private Declare Function WindowFromPoint Lib "user32.dll" (ByVal xPoint As Long, ByVal yPoint As Long) As Long

Private Declare Function GetCursorPos Lib "USER32" (lpPoint As POINTAPI) As Long


Private Sub Form_Load()
Check1.Left = 0: Check1.Top = 0
Timer1.Interval = 1
Check1.Value = 0
End Sub

Private Sub Timer1_Timer()
If IsMouseOverForm Then
    Check1.Value = 1
Else
    Check1.Value = 0
End If
End Sub

Private Function IsMouseOverForm() As Boolean
Dim rv As Long, mXY As POINTAPI
Dim hWP As Long, hPP As Long

    rv = GetCursorPos(mXY)
    hWP = WindowFromPoint(mXY.X, mXY.Y)
    hPP = GetParent(hWP)
    If hPP = 0 Then hPP = hWP
    If hPP <> Me.hwnd Then
        '--mouse is not over form
        IsMouseOverForm = False
    Else
        '--mouse is over form
        IsMouseOverForm = True
    End If
End Function


Download this snippet    Add to My Saved Code

This is one way to determine if the mouse is over a form. Comments

No comments have been posted about This is one way to determine if the mouse is over a form.. Why not be the first to post a comment about This is one way to determine if the mouse is over a form..

Post your comment

Subject:
Message:
0/1000 characters