Implements ISubclass
Private Type POINTAPI
x As Long
y As Long
End Type
Private Const WM_USER = &H400
Private Const WM_MOUSEWHEEL = &H20A
Private Const WM_VSCROLL = &H115
Private Const EM_GETSCROLLPOS = (WM_USER + 221)
Private Const EM_SETSCROLLPOS = (WM_USER + 222)
Private Const WM_LBUTTONDOWN = &H201
Private Declare Function SendMessage Lib "USER32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (pDest As Any, pSrc As Any, ByVal ByteLen As Long)
Private Declare Function GetScrollPos Lib "USER32" (ByVal hwnd As Long, ByVal nBar As Long) As Long
Private lPixelsPerLine As Long
Private bResizingTriggered As Boolean
Private Property Let ISubclass_MsgResponse(ByVal RHS As EMsgResponse)
End Property
Private Property Get ISubclass_MsgResponse() As EMsgResponse
Select Case CurrentMessage
Case WM_VSCROLL, WM_MOUSEWHEEL
ISubclass_MsgResponse = emrConsume
Case Else
ISubclass_MsgResponse = emrPreprocess
End Select
End Property
Private Function ISubclass_WindowProc(ByVal hwnd As Long, ByVal iMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Dim iScrollPos As Long
Dim bScrolling As Boolean
Dim tp As POINTAPI
' scroll events
Select Case iMsg
Case WM_MOUSEWHEEL
'go up or down 3 lines...
SendMessage hwnd, EM_GETSCROLLPOS, 0, tp
If wParam > 0 Then
tp.y = tp.y - (lPixelsPerLine * 5)
Else
tp.y = tp.y + (lPixelsPerLine * 5)
End If
SendMessage hwnd, EM_SETSCROLLPOS, 0, tp
DrawLines picLines, txtDocument
Case WM_VSCROLL
'are we scrolling, or scrolled?
bScrolling = (LoWord(wParam) = 4 Or LoWord(wParam) = 5)
If bScrolling Then
'get info using wparam
iScrollPos = HiWord(wParam)
Else
'call api
iScrollPos = GetScrollPos(hwnd, 1)
End If
'update lines
If Int(iScrollPos / lPixelsPerLine) <> (iScrollPos / lPixelsPerLine) Then
'not divisible by 16
'we are showing half a line...
If bScrolling Then
wParam = MakeDWord(LoWord(wParam), Int(iScrollPos / lPixelsPerLine) * lPixelsPerLine)
Else
'hmm...
End If
End If
'send message to rtf for processing
ISubclass_WindowProc = CallOldWindowProc(hwnd, iMsg, wParam, lParam)
'update the lines
DrawLines picLines, txtDocument
'reset flags
bResizingTriggered = False
If wParam = 8 Then '8=SB_END... scroll end
ElseIf wParam > 1 Then 'not up/down button
End If
Case WM_LBUTTONDOWN
Debug.Print lParam
End Select
End Function
Private Function LoWord(dwValue As Long) As Integer
CopyMemory LoWord, dwValue, 2
End Function
Private Function MakeDWord(LoWord As Integer, HiWord As Integer) As Long
MakeDWord = (HiWord * &H10000) Or (LoWord And &HFFFF&)
End Function
Private Function HiWord(dwValue As Long) As Integer
CopyMemory HiWord, ByVal VarPtr(dwValue) + 2, 2
End Function