PRB: CScrollView Scroll Range Limited to 32K

Last reviewed: June 16, 1997
Article ID: Q166473
The information in this article applies to:
  • The Microsoft Foundation Classes (MFC) included with: - Microsoft Visual C++, 32-bit Editions, versions 4.0, 4.1, 4.2, 5.0

SYMPTOMS

If the scroll range exceeds 32K when you are using the Scroll Thumb to scroll, CScrollView does not handle scrolling correctly. Unusual behavior occurs when you try to scroll beyond 32K.

CAUSE

This behavior is by design. The code to handle ranges greater than 32K was not added to CScrollView because it could fail if a WM_xSCROLL message is sent to the view to programatically scroll the contents.

RESOLUTION

You can work around the problem easily by adding support to handle scroll ranges greater than 32K to a CScrollView derived class. Override the function as follows:

   BOOL CMyScrollView::OnScroll(UINT nScrollCode, UINT nPos, BOOL
                                bDoScroll)
   {
      SCROLLINFO info;
      info.cbSize = sizeof(SCROLLINFO);
      info.fMask = SIF_TRACKPOS;

      if (LOBYTE(nScrollCode) == SB_THUMBTRACK)
      {
         GetScrollInfo(SB_HORZ, &info);
         nPos = info.nTrackPos;
      }

      if (HIBYTE(nScrollCode) == SB_THUMBTRACK)
      {
         GetScrollInfo(SB_VERT, &info);
         nPos = info.nTrackPos;
      }

      return CScrollView::OnScroll(nScrollCode, nPos, bDoScroll);
   }


NOTE: If you are trying to programatically scroll the contents in CscrollView, use the SetScrollInfo to correctly set the scroll bar information and then send or post the WM_xSCROLL message.

NOTE: Windows 95 and Win32s only support logical and device coordinates up to 32K. Since CScrollView uses logical units in SetScrollSizes(), you should specify a scroll range < 32K on when using CSrollView derived classes on these operating systems.

(c) Microsoft Corporation 1997, All Rights Reserved. Contributions by Sridhar S. Madhugiri, Microsoft Corporation


Additional query words: CScrollView scrolling
Keywords : kbprg kbusage MfcUI kbfasttip
Technology : kbmfc
Version : 4.0 4.1 4.2 5.0
Platform : NT WINDOWS
Issue type : kbprb


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: June 16, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.