Microsoft KB Archive/148533

= PRB: No ANSI Notifications from Control Created in OnCreate =

Article ID: 148533

Article Last Modified on 11/21/2006

-

APPLIES TO

 Microsoft Foundation Class Library 4.2, when used with:  Microsoft Visual C++ 2.1

 Microsoft Visual C++ 2.2

 Microsoft Visual C++ 4.0 Standard Edition

 Microsoft Visual C++ 4.1 Subscription</li></ul> </li></ul>

-

<div class="notice_section">

This article was previously published under Q148533

<div class="notice_section">

<div class="symptoms_section">

SYMPTOMS
No notification messages are received from a common control that is created in the OnCreate function (the WM_CREATE handler) of a CFormView or CDialog. Closer inspection reveals that notifications are being sent, but they are the UNICODE versions of the notifications.

<div class="cause_section">

CAUSE
The common controls send a WM_NOTIFYFORMAT message when they are first created to determine if they should send ANSI or UNICODE notifications to the parent window.

The default processing of WM_NOTIFYFORMAT for a dialog box returns NFR_UNICODE until after the dialog box window has been created. At the point when the WM_CREATE message is sent, the dialog box still returns NFR_UNICODE in response to a WM_NOTIFYFORMAT message.

A CFormView is really a dialog box, so this is a problem for the CFormView class as well as the CDialog class.

<div class="resolution_section">

RESOLUTION
Here are two ways to work around this problem:

 Don't create the control in the WM_CREATE handler. If the control is created at a later point, this problem won't occur. For a CDialog- derived class, create the control in the OnInitDialog function. For a CFormView-derived class, create the control in the OnInitialUpdate function.

-or-</li>  Handle the WM_NOTIFYFORMAT message in the CDialog- or CFormView-derived class and respond with the NFR_ANSI code. The WM_NOTIFYFORMAT message is not available in ClassWizard, so you'll need to manually enter the ON_MESSAGE macro for the message as follows: BEGIN_MESSAGE_MAP(CMyDialog, CDialog) //AFX_MSG_MAP ... other manually created message map entries ON_MESSAGE(WM_NOTIFYFORMAT, OnNotifyFormat) // ADD THIS LINE END_MESSAGE_MAP Add the prototype for this function to the class definition: class CMyDialog : public CDialog {         ... other class members protected: afx_msg LRESULT OnNotifyFormat(WPARAM wParam,LPARAM lParam); }; For more information on how to do this, please see the following article in the Microsoft Knowledge Base: ARTICLE-ID: Q99848 TITLE : Use ON_MESSAGE Macro to Map Less-Common Messages The OnNotifyFormat function should be implemented as follows: LRESULT CMyDialog::OnNotifyFormat(WPARAM wParam,LPARAM lParam) {       #ifdef _UNICODE return NFR_UNICODE; #else return NFR_ANSI; #endif } </li></ul>

<div class="status_section">

STATUS
Microsoft has confirmed this to be a bug in Microsoft Windows NT. It is not a bug in MFC. We are researching this problem and will post new information here in the Microsoft Knowledge Base as it becomes available.

Additional query words: CAnimateCtrl CHeaderCtrl CHotKeyCtrl CImageList CListCtrl CProgressCtrl CRichEditCtrl CSliderCtrl CSpinButtonCtrl CStatusBarCtrl CTabCtrl CToolBarCtrl CToolTipCtrl CTreeCtrl 2.10 2.20 4.00 4.10 3.10 3.20 NF_QUERY NF_REQUERY

Keywords: kbctrl kbdlg kbdocview kbprb kbuidesign kbunicode KB148533

-

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

© Microsoft Corporation. All rights reserved.