Scrolling using Window's Messages / Win32 API

hymced

New Member
Joined
Sep 25, 2017
Messages
42
Hi all,

I have recently attempted to use the DetectScroll method developed by CPearson: http://www.cpearson.com/excel/DetectScroll.htm

It no longer works because it is based on the "WM_VSCROLL" messages, which I cannot find in any window's message stream using Spy++.

From this observation, I tried scrolling with Window's Messages and Window's API functions only

Let's assume we have these handles:

Code:
mainHwnd = Application.hWnd
dskHwnd = FindWindowEx(mainHwnd, 0, "XLDESK", vbNullString)
wbkHwnd = FindWindowEx(dskHwnd, 0, "EXCEL7", vbNullString)
sbVHwnd = FindWindowEx(wbkHwnd, 0, "NUIScrollbar", "Vertical")

The following does not work:

Code:
Private Type SCROLLINFO
    cbSize As Long
    fMask As Long
    nMin As Long
    nMax As Long
    nPage As Long
    nPos As Long
    nTrackPos As Long
End Type

Private Const SIF_RANGE = &H1
Private Const SIF_PAGE = &H2
Private Const SIF_POS = &H4
Private Const SIF_DISABLENOSCROLL = &H8
Private Const SIF_TRACKPOS = &H10
Private Const SIF_ALL = (SIF_RANGE Or SIF_PAGE Or SIF_POS Or SIF_TRACKPOS)

Private Const SB_HORZ = 0
Private Const SB_VERT = 1
Private Const SB_CTL = 2


Private Const SB_LINEUP = 0
Private Const SB_LINEDOWN = 1
Private Const SB_THUMBPOSITION = 4

    Dim lngRet As Long
    Dim si As SCROLLINFO
    With si
        .cbSize = Len(si)
        .fMask = SIF_ALL
        
        lngRet = GetScrollInfo(wbkHwnd, SB_VERT, si)
        .nPos = .nPos + 1
        lngRet = SetScrollInfo(wbkHwnd, SB_VERT, si, True)
        UpdateWindow wbkHwnd

    End With

The following messages have not effect either:

Code:
    SendMessage mainHwnd, WM_VSCROLL, SB_LINEDOWN, ByVal 0
    SendMessage wbkHwnd, WM_VSCROLL, SB_LINEDOWN, ByVal 0

the "Workbook" window appears to no longer be responding to WM_VSCROLL messages. Spy++ also shows a child window of EXCEL7 of class "NUIScrollbar", which makes me think that the EXCEL7 window no longer uses a standard vertical scroll bar, but a custom control.

Now if I use the following, I get to successfully scroll the scrollbox of the scrollbar, but I fail to update the window's scroll based on the new position of the scrollbar:

Code:
    lngRet = GetScrollInfo(sbVHwnd, SB_CTL, si)
    .nPos = .nPos + 1
    lngRet = SetScrollInfo(sbVHwnd, SB_CTL, si, True)
    UpdateWindow wbkHwnd

I also noticed this message successfully moves the scrollbox AND the window:

Code:
    'SendMessage wbkHwnd, WM_VSCROLL, SB_LINEDOWN, ByVal sbVHwnd

But I do not really like this last method since I cannot see this message in Spy++, so it is not how the system works natively...

I have also tried using the ScrollWindow and ScrollWindowEx functions to scroll the contents of the "Workbook" window, but I fail to see the cells moving.

So i need some help on :
- how to update the window scroll position based on the scroll bar position ?
- how to use ScrollWindow / ScrollWindowEx to scroll the contents of the window (cells...) ?


Thanks !
 
Last edited:

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top