Microsoft KB Archive/142274

= BUG: Assertion Failure When Handling xN_SETFOCUS in CFormView =

Article ID: 142274

Article Last Modified on 11/21/2006

-

APPLIES TO

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

 Microsoft Visual C++ 5.0 Learning Edition 

-



This article was previously published under Q142274



SYMPTOMS
Focus notifications (EN_SETFOCUS, BN_SETFOCUS, and so on) for controls in a CFormView are usually handled in the CFormView class. Calling a function that relies on the window handle of the control (m_hWnd) inside such a handler may cause an assertion failure in Afxwin2.inl. This happens only if the control is the first one in the tab order.



CAUSE
The assertion failure occurs because the focus handler for the control is being called before OnInitialUpdate is called for the CFormView.



RESOLUTION
To work around this problem, make sure that the m_hWnd member of the control is not NULL before calling any function that relies on it.

<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 bug was corrected in Visual C++ 4.1.

Sample Code
The following illustrates calling SetSel in the for an Edit control. void CSettestView::OnSetFocusEdit1 {       if(NULL != m_Edit.m_hWnd) m_Edit.SetSel( 0,1 ); }

Additional query words: kbVC400bug 4.00 4.10

Keywords: kbbug kbdocview kbfix kbnoupdate kbuidesign kbvc410fix KB142274

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.