BUG: Scrollbar Notifications Report Incorrect Position

ID: Q197411

The information in this article applies to:

SYMPTOMS

The scroll position may be reported incorrectly when SB_THUMBPOSITION and SB_THUMBTRACK scroll notifications are received.

CAUSE

Windows CE maps the scroll position into the range 0 - (nMax - nMin) where 0 is the minimum scroll position and (nMax - nMin) is the maximum scroll position. nMin and nMax are the minimum and maximum scroll positions set by calling SetScrollRange or SetScrollInfo.

RESOLUTION

When handling SB_THUMBPOSITION and SB_THUMBTRACK notifications, add the minimum scroll position to the position reported in the WM_HSCROLL or WM_VSCROLL message (nPos) to obtain the actual position.

Sample Code

   case WM_VSCROLL:
   {
      int nScrollCode = (int)LOWORD(wParam);
      int nPos = (short int)HIWORD(wParam);

      SCROLLINFO si = {sizeof(SCROLLINFO),
                       SIF_PAGE|SIF_POS|SIF_RANGE|SIF_TRACKPOS,
                       0, 0, 0, 0, 0};
      GetScrollInfo (hWnd, SB_VERT, &si);

      int nNewPos = si.nPos;

      switch (nScrollCode)
      {
         [ ... ]

         case SB_THUMBPOSITION:
            nNewPos = nPos + si.nMin;  // Adding si.nMin here
                                       // is the workaround.
            break;
      }

      si.fMask = SIF_POS;
      si.nPos = nNewPos;
      SetScrollInfo (hWnd, SB_VERT, &si, TRUE);
      return TRUE;
   }

STATUS

Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article.

Additional query words:

Keywords          : kbcode kbCtrl kbSDKPlatform kbGrpUser kbWinCE100bug kbWinCE200bug kbWinCE210bug 
Version           : WINDOWS:1.0,2.0,2.1
Platform          : WINDOWS
Issue type        : kbbug
Solution Type     : kbnofix

Last Reviewed: December 18, 1998