windows_programming_notes.nbk: Home | Index | Next Page: GetScrollPos | Previous Page: GetSaveFileName


 GetScrollInfo

The GetScrollInfo function retrieves the parameters of a scroll bar, including the minimum and maximum scrolling positions, the page size, and the position of the scroll box (thumb).

Syntax

    BOOL GetScrollInfo(  
        HWND hwnd,
        int fnBar,
        LPSCROLLINFO lpsi
    );

Parameters

Return Value

If the function retrieved any values, the return value is nonzero.

If the function does not retrieve any values, the return value is zero. To get extended error information, call GetLastError.

Remarks

The GetScrollInfo function enables applications to use 32-bit scroll positions. Although the messages that indicate scroll-bar position, WM_HSCROLL and WM_VSCROLL, provide only 16 bits of position data, the functions SetScrollInfo and GetScrollInfo provide 32 bits of scroll-bar position data. Thus, an application can call GetScrollInfo while processing either the WM_HSCROLL or WM_VSCROLL messages to obtain 32-bit scroll-bar position data.

To get the 32-bit position of the scroll box (thumb) during a SB_THUMBTRACK request code in a WM_HSCROLL or WM_VSCROLL message, call GetScrollInfo with the SIF_TRACKPOS value in the fMask member of the SCROLLINFO structure. The function returns the tracking position of the scroll box in the nTrackPos member of the SCROLLINFO structure. This allows you to get the position of the scroll box as the user moves it. The following sample code illustrates the technique.

SCROLLINFO si;
case WM_HSCROLL:
    switch(LOWORD(wparam)) {
        case SB_THUMBTRACK:
          // Initialize SCROLLINFO structure
 
            ZeroMemory(&si, sizeof(si));
            si.cbSize = sizeof(si);
            si.fMask = SIF_TRACKPOS;
 
          // Call GetScrollInfo to get current tracking 
          //    position in si.nTrackPos
 
            if (!GetScrollInfo(hwnd, SB_HORZ, &si) )
                return 1; // GetScrollInfo failed
            break;
        .
        .
        .
    }

If the fnBar parameter is SB_CTL and the window specified by the hwnd parameter is not a system scroll bar control, the system sends the SBM_GETSCROLLINFO message to the window to obtain scroll bar information. This allows GetScrollInfo to operate on a custom control that mimics a scroll bar. If the window does not handle the SBM_GETSCROLLINFO message, the GetScrollInfo function fails.

Function Information


windows_programming_notes.nbk: Home | Index | Next Page: GetScrollPos | Previous Page: GetSaveFileName


Notebook exported on Monday, 7 July 2008, 18:56:50 PM Eastern Daylight Time