Scroll bar problem

I'm readig <Programming Windows 5th>, chapter 4 , scroll bar, and there's some code puzzles me, I use /** **/ make my problem out.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
 
     case WM_PAINT :
          hdc = BeginPaint (hwnd, &ps) ;

               // Get vertical scroll bar position

          si.cbSize = sizeof (si) ;    
          si.fMask  = SIF_POS ; 
/** why each time use GetScrollInfo have to initialize SCROLLINFO, and only initialize part of the struct ?**/
          
          GetScrollInfo (hwnd, SB_VERT, &si) ;
          iVertPos = si.nPos ;

               // Get horizontal scroll bar position

          GetScrollInfo (hwnd, SB_HORZ, &si) ;
          iHorzPos = si.nPos ;

               // Find painting limits

          iPaintBeg = max (0, iVertPos + ps.rcPaint.top / cyChar) ;
          iPaintEnd = min (NUMLINES - 1,
                           iVertPos + ps.rcPaint.botto/m / cyChar) ;
   /**how tot compute the iPaintBeg and iPaintEnd, what does the formuals mean? doesn't ps.rcPaint.top equal 0? **/      
          for (i = iPaintBeg ; i <= iPaintEnd ; i++)
          {
               x = cxChar * (1 - iHorzPos) ;
               y = cyChar * (i - iVertPos) ;
    /**what does these to formular mean? I can't understand the position,**/
               TextOut (hdc, x, y,
                        sysmetrics[i].szLabel,
                        lstrlen (sysmetrics[i].szLabel)) ;
               
               TextOut (hdc, x + 22 * cxCaps, y,
                        sysmetrics[i].szDesc,
                        lstrlen (sysmetrics[i].szDesc)) ;
               
               SetTextAlign (hdc, TA_RIGHT | TA_TOP) ;
               
               TextOut (hdc, x + 22 * cxCaps + 40 * cxChar, y, szBuffer,
                        wsprintf (szBuffer, TEXT ("%5d"),
                             GetSystemMetrics (sysmetrics[i].iIndex))) ;
               
               SetTextAlign (hdc, TA_LEFT | TA_TOP) ;
          }

          EndPaint (hwnd, &ps) ;
          return 0 ;


/**why some variable use the qualifier static, and otehrs not?**/
ylxin1993 wrote:
/**why some variable use the qualifier static, and otehrs not?**/
The window procedure needs to be reentrant -- meaning that due to the way Windows messages work, the variables defined therein will require to be static in order to be retained (and not be destroyed due to being out of scope) during message handling, as control passes out and back into the window procedure (see "The Windows Programming Hurdles", in chapter 3).
Topic archived. No new replies allowed.