Derek Baker - 2002-12-11

In my first serious windows program, that I am writing as I work through Programming Windows by Petzold, I subcontracted setting of min, max and range
values of the scroll bars to case WM_SIZE: This on the basis that it had to update the scroll bars if the windows size is changed.

I call WM_SIZE with:

//SendMessage(hwnd, WM_SIZE, cxClient |
                                //            cyClient<<16, 0);

WM_SIZE looks like this:

case WM_SIZE:
                cxClient = LOWORD(lParam);
                cyClient = HIWORD(lParam);
                iHorzPage = cxClient / cxChar;
                iVertPage = cyClient / cyChar;
               
                    si.cbSize = sizeof(SCROLLINFO);
                    si.fMask = SIF_RANGE | SIF_PAGE;
                    si.nMin = 0;
                    si.nMax = maxstrlen+ 1;
                    si.nPage = iHorzPage;
                    SetScrollInfo(hwnd, SB_HORZ, &si, TRUE);
               
        si.cbSize = sizeof(SCROLLINFO);
                    si.fMask = SIF_RANGE | SIF_PAGE;
                    si.nMin = 0;
                    si.nMax = v.size()- 1;
                    si.nPage = iVertPage;
                    SetScrollInfo(hwnd, SB_VERT, &si, TRUE);
               
               
                return 0;
 
The problem is that after the line exceeds the horizontal size of the client area, and the screen scrolls, the values of cxClient, and cyClient go to 0. The only assignment of these value is in WM_SIZE.

Changing to setting the min, max and range values at the end of WM_CHAR works, but I would like to know why this way doesnt?

Thanks in advance

Derek