Private Type POINTAPI
X As Long
Y As Long
End Type
Private Declare Function GetCursorPos Lib "user32" ( _
lpPoint As POINTAPI) As Long
Private Declare Function ClientToScreen Lib "user32" ( _
ByVal hwnd As Long, lpPoint As POINTAPI) As Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" ( _
ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private bRunning As Boolean
Private lhWnd As Long
Private Sub UserForm_Initialize()
lhWnd = FindWindow(vbNullString, Me.Caption)
End Sub
Private Sub UserForm_Activate()
If Not bRunning Then
bRunning = True
TimerLoop
End If
End Sub
Private Sub TimerLoop()
Dim ptCursor As POINTAPI, ptClient As POINTAPI, ptBlank As POINTAPI
Dim lX As Long, lY As Long
Do While bRunning
DoEvents
GetCursorPos ptCursor
ClientToScreen lhWnd, ptClient
lX = (ptCursor.X - ptClient.X) * 0.75
lY = (ptCursor.Y - ptClient.Y) * 0.75
If lX > -1 And lY > -1 Then GenericMouseOver lX, lY
ptClient = ptBlank
Loop
Unload Me
End Sub
Private Sub GenericMouseOver(ByVal lX As Long, lY As Long)
Dim ctl As Control
For Each ctl In Me.Controls
If TypeOf ctl Is CommandButton Then
If lX > ctl.Left And lX < (ctl.Left + ctl.Width) And _
lY > ctl.Top And lY < (ctl.Top + ctl.Height) Then
If Not Me.Controls(ctl.Tag).Visible Then Me.Controls(ctl.Tag).Visible = True
Else
If Me.Controls(ctl.Tag).Visible Then Me.Controls(ctl.Tag).Visible = False
End If
End If
Next ctl
End Sub
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
If bRunning Then
Cancel = True
bRunning = False
End If
End Sub