C# SCROLLINFO not working on Chrome window

Ankur Tripathi 1 Reputation point
2023-08-13T10:53:38.2166667+00:00

I am attempting to retrieve scroll information from the window handle, but I keep getting a value of 0. I am pursuing this approach because my goal is to capture a complete scrolling screenshot of the window. The intention is to enable automatic scrolling and image capture. While I have successfully implemented automatic window scrolling, I've encountered variations in the scrolling behaviour for different windows.

For instance, sending a mouse delta of 100 results in Chrome scrolling by around 70 pixels, whereas Visual Studio scrolls by approximately 110 pixels. Each window appears to exhibit distinct scrolling characteristics. Therefore, my current objective is to calculate the precise amount of pixel movement during scrolling using the scrollbar. However, I have encountered difficulties in achieving this functionality.

Basically, I want to scroll screenshots.. so I have 2 options 1) After scrolling automatically by code calculate how much pixel scroll moved and I will capture that part and attach it to the image 2) If I am able to scroll pre-define height so, in that case, I know I scrolled 100 pixels so capture a 100-pixel image only trying option 1 but no luck yet..

Getting "False" from GetScrollInfo and GetLastError() returns 1447 error code

Code:-

// get scrollbar info
SCROLLINFO scrollinfo = new SCROLLINFO();
scrollinfo.cbSize = (uint)Marshal.SizeOf(scrollinfo);
scrollinfo.fMask = SIF_ALL; // Get all the scroll bar information.
bool horBar = GetScrollInfo1(windowHandle, SB_HORZ, out scrollinfo);
Console.WriteLine(horBar);
bool vertBar = GetScrollInfo1(windowHandle, SB_VERT, out scrollinfo);
Console.WriteLine(vertBar);
Console.WriteLine(scrollinfo.nPage + ", " + scrollinfo.nPos);

[DllImport("user32.dll")]
public static extern bool GetScrollInfo(IntPtr hWnd, int fnBar, ref SCROLLINFO lpsi);
Windows development | Windows API - Win32
Developer technologies | .NET | Other
Developer technologies | C#
Developer technologies | C#

An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.

Locked Question. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

3 answers

Sort by: Most helpful
  1. Hadassa Goodman 0 Reputation points
    2026-09-21T18:29:58.39+00:00

    I ran into the same problem while building (removed by Moderator), a scrolling capture tool for Windows. Scroll distance per wheel delta really does vary between apps, and many windows don't expose reliable scroll info at all, so relying on the scrollbar is fragile.

    What worked better for me was ignoring scroll values entirely and measuring the offset from the images themselves: after each scroll, compare the new frame with the previous one to find how far the content actually moved, then append only the new part. A few things that helped:

    • Match on a horizontal strip rather than the full frame, it's faster and more stable.
    • Exclude sticky headers/footers from the comparison, or they'll confuse the match.
    • Treat "no movement detected" as the end of scrolling.

    This way the logic is the same for Chrome, Visual Studio or any other app.

    Was this answer helpful?

    0 comments No comments
  2. Castorix31 91,976 Reputation points
    2023-08-15T09:36:03.9833333+00:00

    my goal is to capture a complete scrolling screenshot of the window.

    You can use the same method as in ShareX : if GetScrollInfo fails, it compares the last 2 images to detect end of scrolling

    https://github.com/ShareX/ShareX/blob/51c471113d6f5a64acc00b542ad78a0f9783ce99/ShareX.ScreenCaptureLib/Helpers/ScrollingCaptureManager.cs

    (I tested with Chrome on Windows 10 22H2)

    Was this answer helpful?

    0 comments No comments
  3. Bruce (SqlWork.com) 85,456 Reputation points
    2023-08-13T15:31:58.7933333+00:00

    The scale of the scrollbar is typically based on the size of the offscreen content. As your code has no way to detect the offscreen size, you can not calculate the number of pixels the scroll moves. Take chrome for instance, the length of the html document will control movement of the scrollbar.

    Was this answer helpful?