KnowledgeBase Archive

An Archive of Early Microsoft KnowledgeBase Articles

View on GitHub

Q150574: FIX:CScrollView::OnHScroll/OnVScroll Do Not Call OnChildNotify

Article: Q150574
Product(s): Microsoft C Compiler
Version(s): winnt:2.0,2.1,2.2
Operating System(s): 
Keyword(s): kbDocView kbMFC kbVC150bug kbVC151bug kbVC152bug kbVC200bug kbVC210bug kbVC220bug kbVC4
Last Modified: 03-AUG-2001

-------------------------------------------------------------------------------
The information in this article applies to:

- The Microsoft Foundation Classes (MFC), used with:
   - Microsoft Visual C++ for Windows, 16-bit edition, versions 1.5, 1.51, 1.52 
   - Microsoft Visual C++, 32-bit Editions, versions 2.0, 2.1, 2.2 
-------------------------------------------------------------------------------

SYMPTOMS
========

Scroll messages generated by scroll related controls in a CScrollView- derived
object fail to invoke the control's OnChildNotify function.

CAUSE
=====

CScrollView::OnVScroll and CScrollView::OnHScroll do not call
SendChildNotifyLastMsg, which is responsible for calling OnChildNotify.

RESOLUTION
==========

Override OnVScroll and/or OnHScroll for your CScrollView-derived class, and
implement this code:

     void CMyView::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar*
     pScrollBar)
     {
         if (pScrollBar != NULL && pScrollBar->SendChildNotifyLastMsg())
             return;     // eat it

         // ignore scroll bar msgs from other controls
         if (pScrollBar != GetScrollBarCtrl(SB_VERT))
             return;

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

     void CMyView::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar*
     pScrollBar)
     {
         // same as above
         ...
     }

STATUS
======

Microsoft has confirmed this to be a bug in the Microsoft products listed at the
beginning of this article. This problem is corrected in Microsoft Visual C++
version 4.0.

MORE INFORMATION
================

OnChildNotify is called by the control's parent window when the parent window
receives a notification message that applies to this control. Notification
messages include control notification messages such as WM_COMMAND sent by
controls, some specific Windows messages such as WM_HSCROLL, WM_VSCROLL, and
WM_CTLCOLOR, and a few others.

NOTE: For more information, see Tech note #21.

OnChildNotify allows a control an initial opportunity to view these messages
before the control reaches its parent.

The code reflects corrections for a bug reported in the following article in the
Microsoft Knowledge Base:

  Q133034 BUG: CSpinButtonCtrl Causes Assertion in Viewscrl.cpp line 698

The need for CScrollView to pass scroll messages correctly to OnChildNotify
arises from implementing a CSpinButtonCtrl control, or an additional CScrollbar
control in the view.

REFERENCES
==========

For additional information, please see the following article in the Microsoft
Knowledge Base:

  Q133034 BUG: CSpinButtonCtrl Causes Assertion in viewscrl.cpp line 698.

MFC Technical Note #21 - Command and Message Routine

Books Online - CWnd::OnChildNotify

Additional query words: 1.50 1.51 1.52 2.00 2.10 2.20

======================================================================
Keywords          : kbDocView kbMFC kbVC150bug kbVC151bug kbVC152bug kbVC200bug kbVC210bug kbVC220bug kbVC400fix kbGrpDSMFCATL kbNoUpdate kbbuglist kbfixlist
Technology        : kbAudDeveloper kbMFC
Version           : winnt:2.0,2.1,2.2
Issue type        : kbbug
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.

Copyright Microsoft Corporation 1986-2002.