by the book, i read that with WM_SIZE message i can get the client size instead use the GetClientRect() function:

case WM_SIZE:
            GetClientRect (hwnd, &rect) ;
            VerticalScrollSize=rect.bottom;
            si.cbSize = sizeof(si);
            si.fMask  = SIF_ALL;
            GetScrollInfo (hwnd, SB_VERT, &si);
            si.nMin = 0;
            si.nPos = VerticalScroll;
            si.nMax = VerticalScrollSize-2;
            si.nPage=2;
            SetScrollInfo (hwnd, SB_VERT, &si, TRUE);
            InvalidateRect(hwnd, NULL, TRUE);
            return 0;

but i continue confuse with nMax and nPage... and i belive the nMin is 0(zero).
can anyone explain better please?
because i'm getting wrong thumb size :(

Recommended Answers

All 4 Replies

si.nPage is the amount you should move when the user "pages" up or down. This also changes the scrollbar thumb size.
si.nMax is the maximum you can scroll to. This can be any value that makes sense in your application.
si.nMin is the minimum you can scroll to. Normally this is 0 but it doesn't have to be.

The scrollbar settings are not in any specific units, so you can interpret them any way you wish. So if you were scrolling a grid of 150 database records and you show 20 rows at a time, you might set nMin, nPage and nMax to be 0, 20 and 150 (or maybe 130). If you were scrolling a graph with an axis that ran from 100 to 1000 and you fit a range of 300 in your window, you might set nMin, nPage and nMax to 100, 300 and 1000 (or maybe 700).
So nPage relates to the amount to scroll by when you move in big chunks, or pages and nMax is the maximum you can move to.

In the code you posted your scrollbar settings seem to relate to the window size on your screen. I think you would do better if they related to the data to be displayed. I try to relate the scrollbar position to an offset from the start position to the first data to be visible and set nMax to relate to the maximum data value minus the amount of data that can be displayed in the client area, so that I never scroll past the end of the available data.

thank you very much. but i'm confused in anotherthing:

GetClientRect (hwnd, &rect) ;

give me the actual DC size or window size without scrollbars\menus\border\others?

GetClientRect returns the window size without scrollbars\menus\border\others. So when your scrollbar is visible your client area is smaller.

so i'm loking for the DC size, right?
(help me with right terms)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.