using GetScrollBarInfo win32 API


Tsahi Asher

i'm trying to get the width of the vertical scroll bar for some third party
component* i'm using. so i called the GetScrollBarInfo API like so:
[DllImport("user32.dll", SetLastError = true, EntryPoint =
private static extern int GetScrollBarInfo(IntPtr hWnd,
uint idObject, ref SCROLLBARINFO psbi);
with these structs:

public struct SCROLLBARINFO


public int cbSize;

public RECT rcScrollBar;

public int dxyLineButton;

public int xyThumbTop;

public int xyThumbBottom;

public int reserved;

[MarshalAs(UnmanagedType.ByValArray, SizeConst = 6)]

public int[] rgstate;


public struct RECT


public int Left;

public int Top;

public int Right;

public int Bottom;


the call is:

private const uint OBJID_VSCROLL = 0xFFFFFFFB;


info.cbSize = Marshal.SizeOf(info);

int res = GetScrollBarInfo(gridCtrl.Handle, OBJID_VSCROLL, ref info);

the problem is that the numbers i get in SCROLLBARINFO.rcScrollBar don't
make sense. i get this:

buttom = -2141498754; left = -2141498499; right = 69528148; top
= -1460105884

how do i get the scroll bar width from these numbers?

*DevXpress's VerticalGridControl, if it's familiar to you.

Tsahi Asher

i figured this out by myself, but just for the record (because i really
searched hard and came up with nothing before posing this): for a vertical
scrollbar, the width is the difference between the left and bottom members
of the RECT struct. this measure, however, is in Twips, so you have to
convert it to pixels for it to have a meaning in .net. i devided it by 15,
but it is possible that it depends on your DPI settings in Windows.


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question