FIX: CSpinButtonCtrl Causes Assertion in viewscrl.cpp line 698Last reviewed: September 18, 1997Article ID: Q133034 |
2.10 2.20
WINDOWS NT
kbprg kbfixlist kbcode
The information in this article applies to:
SYMPTOMSWhen 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.
CAUSEA 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.
STATUSMicrosoft 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.
RESOLUTIONAdd 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
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |