Microsoft KB Archive/150574

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

Article ID: 150574

Article Last Modified on 11/21/2006

-

APPLIES TO

 Microsoft Foundation Class Library 4.2, when used with:  Microsoft Visual C++ 1.5 Professional Edition

 Microsoft Visual C++ 1.51

 Microsoft Visual C++ 1.52 Professional Edition

 Microsoft Visual C++ 2.0 Professional Edition</li></ul>

 Microsoft Visual C++ 2.1</li></ul>

 Microsoft Visual C++ 2.2</li></ul> </li></ul>

-

<div class="notice_section">

This article was previously published under Q150574

<div class="symptoms_section">

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

<div class="cause_section">

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

<div class="resolution_section">

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 ...  }

<div class="status_section">

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.

<div class="moreinformation_section">

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:

133034 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.

<div class="references_section">