Microsoft KB Archive/148703

= FIX: CWnd::SubclassDlgItem Returns FALSE for OLE Controls =

Article ID: 148703

Article Last Modified on 11/21/2006

-

APPLIES TO


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

-



This article was previously published under Q148703



SYMPTOMS
Using CWnd::SubclassDlgItem to subclass an OLE Control returns FALSE, after failing on the check for m_pCtrlCont != NULL in line 301 of Winctrl1.cpp.



CAUSE
The MFC framework's implementation of CWnd::SubclassDlgItem checks and uses the CWnd::m_pCtrlCont member of the OLE control, instead of the control container, which is the parent of the control. The source code should use pParent->m_pCtrlCont in order to access the container.



RESOLUTION
As a workaround, use CWnd::SubclassWindow instead of CWnd::SubclassDlgItem, which is illustrated in the sample code section in this article.



STATUS
Microsoft has confirmed this to be bug in the Microsoft products listed at the beginning of this article. This problem was corrected in Microsoft Visual C++, 32-bit Edition, version 4.1.



Steps to Help Reproduce Problem
 Generate a default SDI control container application using AppWizard. Insert the Grid OLE Control through the Component Gallery, which in turn generates the CGridCtrl wrapper class. Place the Grid control in the Application's About dialog box. Declare an embedded member variable called "m_gridctrl" in CAboutDlg of type CGridCtrl.  Generate an OnInitDialog handler for the CAboutDlg class and subclass the Grid control inside it as illustrated by this code: BOOL CAboutDlg::OnInitDialog {      // Call base class implementation CDialog::OnInitDialog;

// Try to subclass the Grid control by calling SubclassDlgItem m_gridctrl.SubclassDlgItem(IDC_GRID1, this);

return TRUE; // set focus to first control of the dialog } NOTE: In this code, IDC_GRID1 is the ID of the Grid control. </li> When running the container application through the debugger, notice that CWnd::SubclassDlgItem returns FALSE after failing on the check for m_pCtrlCont != NULL in line 301 of Winctrl1.cpp.</li></ol>

Sample Code to Work Around Problem
BOOL CAboutDlg::OnInitDialog {   CDialog::OnInitDialog;

// Try to Subclass the Grid control by calling SubclassWindow CWnd* pWnd = GetDlgItem(IDC_GRID1); m_gridctrl.SubclassWindow(pWnd->m_hWnd);

return TRUE; // set focus to first control of the dialog // Exception: OCX Property Pages should return FALSE }

Additional query words: 4.00 ocx ole control

Keywords: kbbug kbctrl kbfix kbnoupdate kbvc410fix KB148703

-

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

© Microsoft Corporation. All rights reserved.