Option Explicit
Private Declare PtrSafe Function IUnknown_GetWindow Lib "shlwapi" Alias "#172" (ByVal pIUnk As IUnknown, ByVal hWnd As LongPtr) As Long
Private Declare PtrSafe Function GetWindow Lib "user32" (ByVal hWnd As LongPtr, ByVal wCmd As Long) As LongPtr
Private Declare PtrSafe Function SetFocus Lib "user32" (ByVal hWnd As LongPtr) As Long
#Else
Private Enum LongPtr
[_]
End Enum
Private Declare Function IUnknown_GetWindow Lib "shlwapi" Alias "#172" (ByVal pIUnk As IUnknown, ByVal hWnd As LongPtr) As Long
Private Declare Function GetWindow Lib "user32" (ByVal hWnd As LongPtr, ByVal wCmd As Long) As LongPtr
Private Declare Function SetFocus Lib "user32" (ByVal hWnd As Long) As Long
Private WithEvents IC As MSINKAUTLib.InkCollector
Private TargetControl As MSForms.Control
Private Sub UserForm_Initialize()
Label1.Picture = New StdPicture
Me.TextBox1.SelStart = 0
ListBox1.List = Evaluate("row(1:30)")
ComboBox1.List = Evaluate("row(1:30)")
End Sub
Private Sub SetupMouseWheel(Optional HandL As Long = 0)
Set IC = Nothing
If HandL = 0 Then
Dim hWnd As LongPtr, TemphWnd As LongPtr
Call IUnknown_GetWindow(Me, VarPtr(hWnd))
Const GW_CHILD = 5
TemphWnd = GetWindow(hWnd, GW_CHILD)
Else
TemphWnd = HandL
End If
Set IC = New MSINKAUTLib.InkCollector
With IC
SetFocus TemphWnd
.hWnd = TemphWnd
.SetEventInterest ICEI_MouseWheel, True
.MousePointer = IMP_Arrow
.DynamicRendering = False
.DefaultDrawingAttributes.Transparency = 255
.Enabled = True
End With
End Sub
Private Sub Label1_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
If Not Label1 Is TargetControl Then
Set TargetControl = Label1
SetupMouseWheel
End If
End Sub
Private Sub TextBox1_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
TextBox1.SetFocus
If Not TextBox1 Is TargetControl Then
Set TargetControl = TextBox1
SetupMouseWheel
End If
TargetControl.SetFocus
End Sub
Private Sub ListBox1_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
If Not ListBox1 Is TargetControl Then
Set TargetControl = ListBox1
SetupMouseWheel ListBox1.[_GethWnd]
End If
End Sub
Private Sub Frame1_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
If Not Frame1 Is TargetControl Then
Set TargetControl = Frame1
SetupMouseWheel Frame1.[_GethWnd]
End If
End Sub
Private Sub MultiPage1_MouseMove(ByVal Index As Long, ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
If Not MultiPage1 Is TargetControl Then
Set TargetControl = MultiPage1
SetupMouseWheel MultiPage1.[_GethWnd]
End If
End Sub
Private Sub ComboBox1_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
If Not ComboBox1 Is TargetControl Then
Set TargetControl = ComboBox1
SetupMouseWheel
End If
End Sub
Private Sub IC_MouseWheel(ByVal Button As MSINKAUTLib.InkMouseButton, ByVal Shift As MSINKAUTLib.InkShiftKeyModifierFlags, ByVal Delta As Long, ByVal X As Long, ByVal Y As Long, Cancel As Boolean)
Dim ctrl As Control
Set ctrl = TargetControl
Select Case TypeName(TargetControl)
Case "Label"
CallByName TargetControl, "Caption", VbLet, "Delta: " & Delta
Case "TextBox"
Dim CurrentLine As Long
CurrentLine = CallByName(TargetControl, "CurLine", VbGet)
If CurrentLine = TextBox1.LineCount - 1 And Delta < 0 Then Exit Sub
If CurrentLine = 0 And Delta > 0 Then Exit Sub
CallByName TargetControl, "CurLine", VbLet, IIf(Delta > 0, CurrentLine - 1, CurrentLine + 1)
Case "ListBox"
CallByName TargetControl, "TopIndex", VbLet, IIf(Delta > 0, ctrl.TopIndex - 1, ctrl.TopIndex + 1)
Case "ComboBox"
CallByName TargetControl, "TopIndex", VbLet, IIf(Delta > 0, ctrl.TopIndex - 1, ctrl.TopIndex + 1)
Case "Frame"
CallByName TargetControl, "ScrollTop", VbLet, IIf(Delta > 0, ctrl.ScrollTop - 8, ctrl.ScrollTop + 8)
Case "MultiPage"
CallByName TargetControl.Pages(TargetControl.Value), "ScrollTop", VbLet, _
IIf(Delta > 0, TargetControl.Pages(TargetControl.Value).ScrollTop - 8, TargetControl.Pages(TargetControl.Value).ScrollTop + 8)
End Select
End Sub
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
Set IC = Nothing
End Sub