VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



This code is s function that determines if the mouse is over a specific form. (This corrects the fa

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

This code is s function that determines if the mouse is over a specific form. (This corrects the faulty example I previously uploaded.)

API Declarations


' a specific form. Note the function uses a loop to get the parent
' window. For example, if you draw five frames, each inside the last
' drawn, the parent window for the last frame drawn would be the
' previous frame. The loop keeps looking for a parent until it finds
' the form on which all objects have been drawn. All the Declarations
' below pertain to the function IsMouseOverForm.
'
' Open a project with a form.
' Add a timer named Timer1.
' Add a checkbox named Check1.
' Copy the code below to the form.


Rate This code is s function that determines if the mouse is over a specific form. (This corrects the fa




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(Me.hwnd) Then Check1.Value = 1 Else Check1.Value = 0
End Sub

Private Function IsMouseOverForm(ByVal lFrmHndl As Long) As Boolean
Dim rv As Long, mXY As POINTAPI
Dim lWH As Long, lWP As Long
    rv = GetCursorPos(mXY) 'get mouse position
    lWP = WindowFromPoint(mXY.X, mXY.Y) 'handle to window under mouse
    Do While lWP
        lWH = lWP 'keep last handle found
        lWP = GetParent(lWP) 'test for another parent
    Loop
    If lWH = lFrmHndl Then IsMouseOverForm = True
End Function


Download this snippet    Add to My Saved Code

This code is s function that determines if the mouse is over a specific form. (This corrects the fa Comments

No comments have been posted about This code is s function that determines if the mouse is over a specific form. (This corrects the fa. Why not be the first to post a comment about This code is s function that determines if the mouse is over a specific form. (This corrects the fa.

Post your comment

Subject:
Message:
0/1000 characters