This is to know whether the user has the mouse over your form or outside of it...Might be useful for people so... Enjoy
VB Code:
'API AND DECLARATIONS Private Type POINTAPI x As Long y As Long End Type Private Declare Function GetCursorPos Lib "user32.dll" (ByRef lpPoint As POINTAPI) As Long '========================================================== Private Function MouseInForm(pForm As Form) As Boolean Dim iRight As Long Dim iLeft As Long Dim iBottom As Long Dim iTop As Long Dim PT As POINTAPI 'Lets convert everything to pixels since that's what GetCursorPos returns... iRight = (pForm.Left + pForm.Width) / Screen.TwipsPerPixelX iBottom = (pForm.Top + pForm.Height) / Screen.TwipsPerPixelY iLeft = pForm.Left / Screen.TwipsPerPixelX iTop = pForm.Top / Screen.TwipsPerPixelY GetCursorPos PT If (PT.x <= iRight) And (PT.x >= iLeft) _ And (PT.y >= iTop) And (PT.y <= iBottom) Then MouseInForm = True Else MouseInForm = False End If End Function 'USAGE: 'Can be used in Form_Mousemove or a Timer or anywhere you want to check if mouse is in your form If MouseInForm(frmMain) Then MsgBox "Mouse currently over frmMain" Else MsgBox "Mouse is not over frmMain" End If







Reply With Quote