Can't get SendMessage with WM_VSCROLL and SB_THUMBPOSITION and/or B_THUMBTRACK to work
Posted on 2009-12-28
I am wanting to create and application which sends the smoothest possible scrolling command to another application. This target application is projected on a screen and loads of people will sit in a meeting and read text there for a long time.
My goal is that the user should not have to constantly sit and manually scroll with the mouse, and to have the automatic scrolling more smooth and consistent. The smoothest scrolling I know is made when pushing the middle button which gives the arrow group icon and then panning the mouse down below. Scrolling is down on pixel level then, and using the mouse wheel (not an option) is per line.
The application waits a couple of seconds after a click, then grabs the hWnd of the active window and sends the signals to it.
Here's an extract of my code, which doesn't work.
What needs to be changed/added for it to work? Other solutions with a smooth
Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal Wparam As Long, ByRef Lparam As Any) As Long
Public Declare Function GetForegroundWindow Lib "user32" () As Long
Public Const WM_VSCROLL As Integer = &H115
Public Const SB_THUMBPOSITION = 4
Public Const SB_THUMBTRACK = 5
Public Const SB_ENDSCROLL = 8
Public Const WM_MOUSEWHEEL = &H20A 'Works but not used...
Private Sub Send_Click()
Dim lCurHwnd As Long
Dim lResult As Long
' Wait 2 seconds and then grab window
lCurHwnd = GetForegroundWindow
'This works but is undesired:
'SendMessage lCurHwnd, WM_MOUSEWHEEL, WHEEL_DELTA * &H10000, 50
lResult = SendMessage(lCurHwnd, WM_VSCROLL, MakeLong(SB_THUMBPOSITION, 100), 0)
lResult = SendMessage(lCurHwnd, WM_VSCROLL, MakeLong(SB_THUMBTRACK, 300), 0)
lResult = SendMessage(lCurHwnd, WM_VSCROLL, MakeLong(SB_THUMBTRACK, 400), 0)
lResult = SendMessage(lCurHwnd, WM_VSCROLL, MakeLong(SB_THUMBTRACK, 500), 0)
lResult = SendMessage(lCurHwnd, WM_VSCROLL, SB_ENDSCROLL, 0)