Option Explicit
Public WithEvents New_Label As MSFORMS.Label
Public WithEvents New_Textbox As MSFORMS.TextBox
Private Type POINTAPI
X As Long
Y As Long
End Type
#If VBA7 Then
Private Declare PtrSafe Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Declare PtrSafe Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As LongPtr)
#If Win64 Then
Private Declare PtrSafe Function AccessibleObjectFromPoint Lib "oleacc" (ByVal arg1 As LongPtr, ppacc As Any, pvarChild As Variant) As Long
#Else
Private Declare PtrSafe Function AccessibleObjectFromPoint Lib "oleacc" (ByVal lX As Long, ByVal lY As Long, ppacc As IAccessible, pvarChild As Variant) As Long
#End If
#Else
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
Private Declare Function AccessibleObjectFromPoint Lib "oleacc" (ByVal lX As Long, ByVal lY As Long, ppacc As IAccessible, pvarChild As Variant) As Long
#End If
Private Const CHILDID_BORDERSTYLE = 0
Private Const HOVER_BORDERSTYLE As Long = 1 'light grey
Private bClicked As Boolean
Private Sub New_Label_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
Dim tCurPos As POINTAPI
Dim oIA As IAccessible
Dim vKid As Variant
On Error Resume Next
With New_Label
If .Parent.Tag = "" Then
If NewControlsTag.item(New_Label.Name) = "" Then
NewControlsTag.Remove (New_Label.Name)
NewControlsTag.Add .BorderStyle, New_Label.Name
End If
If .BorderStyle <> HOVER_BORDERSTYLE Then .BorderStyle = HOVER_BORDERSTYLE
.Parent.Tag = "looping"
Do
GetCursorPos tCurPos
#If Win64 Then
Dim Ptr As LongPtr
CopyMemory Ptr, tCurPos, LenB(tCurPos)
Call AccessibleObjectFromPoint(Ptr, oIA, vKid)
#Else
Call AccessibleObjectFromPoint(tCurPos.X, tCurPos.Y, oIA, vKid)
#End If
DoEvents
Loop Until oIA.accName(CHILDID_SELF) <> .Caption Or bClicked
bClicked = False
Call OnMouseLeave(New_Label)
End If
End With
End Sub
Private Sub OnMouseLeave(ByVal Button As MSFORMS.Label)
Button.Parent.Tag = ""
Button.BORDESTYLE = NewControlsTag.item(Button.Name)
End Sub