Option Explicit
Private Declare Function GetWindowRect Lib "user32" (ByVal hWnd As Long, lpRect As Rect) 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 Type Rect
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Sub Form_Load()
Me.ScaleMode = 3
End Sub
Private Sub tmrMouseOver_Timer()
Dim blnMouseOver As Boolean
Dim MousePos As PointAPI
Dim wRect As Rect
blnMouseOver = IsMouseOver(Picture1.hWnd)
If blnMouseOver = True Then
GetCursorPos MousePos
GetWindowRect Me.hWnd, wRect
Picture2.Left = (MousePos.X - wRect.Left)
Picture2.Top = (MousePos.Y - wRect.Top)
Picture2.Visible = True
Else
Picture2.Visible = False
End If
End Sub
Private Function IsMouseOver(hWnd As Long) As Boolean
Dim wRect As Rect
Dim MousePos As PointAPI
GetCursorPos MousePos
GetWindowRect hWnd, wRect
IsMouseOver = IIf((MousePos.X <= wRect.Right And MousePos.X >= wRect.Left) And (MousePos.Y <= wRect.Bottom And MousePos.Y >= wRect.Top), True, False)
End Function