I needed this in one of my project, so i thought it might be useful for others.

VB Code:
  1. 'Description : Tells if the cursor/mouse pointer is inside a form.
  2. 'Input : Form Name
  3. 'Output : Boolean (True/False)
  4. 'Requirements: Place a timer control inside the form.
  5.  
  6. 'Example Code:
  7.  
  8.  
  9. Option Explicit
  10.  
  11. Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
  12. Private Declare Function GetWindowRect Lib "user32" (ByVal hWnd As Long, lpRect As RECT) As Long
  13.  
  14. Private Type RECT
  15.     Left As Long
  16.     Top As Long
  17.     Right As Long
  18.     Bottom As Long
  19. End Type
  20.  
  21. Private Type POINTAPI
  22.     X As Long
  23.     Y As Long
  24. End Type
  25.  
  26. Private Const WM_USER As Long = &H400
  27. Private Const SB_GETRECT As Long = (WM_USER + 10)
  28.  
  29. Function IsInside(frmName As Form) As Boolean
  30.     Dim X As Long
  31.     Dim X1 As Long
  32.     Dim Y As Long
  33.     Dim Y1 As Long
  34.        
  35.     Dim Win As RECT
  36.     Dim Cur As POINTAPI
  37.    
  38.     GetWindowRect frmName.hWnd, Win
  39.    
  40.     GetCursorPos Cur
  41.        
  42.     If Cur.X > Win.Left And Cur.X < Win.Right And Cur.Y > Win.Top And Cur.Y < Win.Bottom Then
  43.         IsInside = True
  44.     Else
  45.         IsInside = False
  46.     End If
  47.    
  48. End Function
  49.  
  50. Private Sub Form_Load()
  51.     Timer1.Enabled = True
  52.     Timer1.Interval = 100
  53. End Sub
  54.  
  55. Private Sub Timer1_Timer()
  56.     If IsInside(Me) Then
  57.         Me.Cls
  58.         Print "The Cursor is Inside the form"
  59.     Else
  60.         Me.Cls
  61.         Print "The Cursor is Outside the form"
  62.     End If
  63.    
  64. End Sub