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);