Search
Module:
Directory

   Desktop Functions:

   Smart Device Functions:


Show Recent Changes
Subscribe (RSS)
Misc. Pages
Comments
FAQ
Helpful Tools
Playground
Suggested Reading
Website TODO List
Support Forum
Download Visual Studio Add-In

Terms of Use
Privacy Policy
getscrollbarinfo (user32)
 
.
Summary

C# Signature:

[DllImport( "user32.dll", SetLastError=true,  EntryPoint="GetScrollBarInfo")]
private static extern int GetScrollBarInfo(IntPtr hWnd, uint idObject, ref SCROLLBARINFO psbi);

User-Defined Types:

[StructLayout(LayoutKind.Sequential)]
public struct SCROLLBARINFO
{
    public int cbSize;
    public Rectangle rcScrollBar;
    public int dxyLineButton;
    public int xyThumbTop;
    public int xyThumbBottom;
    public int reserved;
    [MarshalAs(UnmanagedType.ByValArray, SizeConst=6)]
    public int[] rgstate;
}

Notes:

This didn't work for me with the Rectangle type for SCROLLBARINFO.rcScrollBar. To rectify this I altered this declaration to type RECT using the following standard definition.

public struct RECT
{
    public int left;
    public int top;
    public int right;
    public int bottom;
}

This then worked for me!

Tips & Tricks:

for idObject, use one of these values (see the MSDN link at the bottom for their usage):

private const uint OBJID_HSCROLL = 0xFFFFFFFA;
private const uint OBJID_VSCROLL = 0xFFFFFFFB;
private const uint OBJID_CLIENT = 0xFFFFFFFC;

Sample Code:

SCROLLBARINFO psbi = new SCROLLBARINFO();
psbi.cbSize = Marshal.SizeOf(psbi);

int nResult = GetScrollBarInfo(this.Handle, OBJID_CLIENT, ref psbi); // "this" is a scrollbar

if (nResult == 0)
{
    int nLatError = GetLastError(); // in kernel32.dll
}

probably Marshal.GetLastWin32Error() is better here

Alternative Managed API:

if you have a reference to a System.Windows.Forms.ScrollBar, use it's properties. otherwise,

SystemInformation.HorizontalScrollbar*

and

SystemInformation.VerticalScrollbar*

can give you some of the data.

Documentation

http://msdn2.microsoft.com/en-us/library/ms651286.aspx

Please edit this page!

Do you have...

  • helpful tips or sample code to share for using this API in managed code?
  • corrections to the existing content?
  • variations of the signature you want to share?
  • additional languages you want to include?

Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing supporting types needed for this API (structures, delegates, and more).

 
Access PInvoke.net directly from VS:
Terms of Use
Edit This Page
Find References
Show Printable Version
Revisions