FIX: CSpinButtonCtrl Causes Assertion in viewscrl.cpp line 698

Last reviewed: September 18, 1997
Article ID: Q133034
2.10 2.20 WINDOWS NT kbprg kbfixlist kbcode

The information in this article applies to:

  • The Microsoft Foundation Classes included with: Microsoft Visual C++ for Windows, versions 2.1, 2.2

SYMPTOMS

When a CSpinButtonCtrl is created as a child of a view derived from CScrollView, user interaction (clicking with the mouse or pressing an arrow key) with the Up-Down Control's arrow buttons causes an assertion in the viewscrl.cpp file on line 698.

CAUSE

A WM_VSCROLL message (or a WM_HSCROLL message if the style is UDS_HORZ) is sent as a notification when the user interacts with the Up-Down Control's arrow buttons, either by clicking them or by pressing an arrow key.

The problem is that CScrollView has implemented handlers for messages sent by its own scrollbars, so even when CSpinButtonCtrl is the source of the message, the first opportunity to handle the message occurs in the parent's (CScrollView) implementation of the handler. CScrollView's handler makes sure the message was sent by its own scrollbars, or the assertion occurs.

Here is the code for default implementation of CScrollView::OnVScroll from viewscrl.cpp:

   void CScrollView::OnVScroll(UINT nSBCode, UINT nPos,
                                CScrollBar* pScrollBar)
   {
     ASSERT(pScrollBar == GetScrollBarCtrl(SB_VERT));

     UNUSED pScrollBar;  // unused in release builds

     OnScroll(MAKEWORD(-1, nSBCode), nPos);
   }

Because the message originated from the Up-Down Control and not the parent's scrollbar, the assertion in the first line fails.

STATUS

Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article. This problem was fixed in Microsoft Visual C++, 32-bit Edition, version 4.0.

RESOLUTION

Add a handler for the WM_VSCROLL or WM_HSCROLL message in the Up-Down control's parent class. Test to see if the message originated from the Up- Down control or the scrollbar of the parent. If it originated from the Up- Down control, perform operations intended for the control, otherwise, pass the call to the parent's default handler as in this example:

// Here CMyFormView is derived from CFormView, which itself is
// derived from CScrollView

void CMyFormView::OnVScroll(UINT nSBCode, UINT nPos,
                             CScrollBar* pScrollBar)
{
         // IDC_SPINCONTROL is the ID of the Up-Down Control
  if ((pScrollBar != NULL) &&
            (pScrollBar->GetDlgCtrlID() == IDC_SPINCONTROL))
  {
    // Do whatever you want to do when Up-Down control buttons are
    // pressed

      TRACE("spin button\r\n"); // for debugging..
      return;
  }

  CFormView::OnVScroll(nSBCode, nPos, pScrollBar);
}


Additional reference words: 2.10 2.20 3.10 3.20 spin control CFormView
KBCategory: kbprg kbfixlist kbbuglist kbcode
KBSubcategory: MfcMisc

Keywords : MfcMisc kbbuglist kbcode kbfixlist kbprg
Technology : kbMfc
Version : 2.10 2.20
Platform : NT WINDOWS
Solution Type : kbfix


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: September 18, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.