Microsoft KB Archive/183218

= How to subclass a dialog item in ATL =

Article ID: 183218

Article Last Modified on 5/26/2005

-

APPLIES TO

 Microsoft ActiveX Template Library 2.0, when used with:  Microsoft Visual C++ 4.0 Standard Edition

 Microsoft Visual C++ 4.1 Subscription

 Microsoft Visual C++ 4.2 Enterprise Edition

 Microsoft Visual C++ 5.0 Enterprise Edition</li></ul>

 Microsoft Visual C++ 6.0 Enterprise Edition</li></ul>

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

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

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

 Microsoft Visual C++ 6.0 Standard Edition</li></ul>

 Microsoft Visual C++ .NET 2002 Standard Edition</li></ul>

 Microsoft Visual C++ .NET 2003 Standard Edition</li></ul> </li> Microsoft ActiveX Template Library 2.1, when used with:  <li>Microsoft Visual C++ 4.0 Standard Edition</li></ul>

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

<ul> <li>Microsoft Visual C++ 4.2 Enterprise Edition</li></ul>

<ul> <li>Microsoft Visual C++ 5.0 Enterprise Edition</li></ul>

<ul> <li>Microsoft Visual C++ 6.0 Enterprise Edition</li></ul>

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

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

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

<ul> <li>Microsoft Visual C++ 6.0 Standard Edition</li></ul>

<ul> <li>Microsoft Visual C++ .NET 2002 Standard Edition</li></ul>

<ul> <li>Microsoft Visual C++ .NET 2003 Standard Edition</li></ul> </li> <li>Microsoft ActiveX Template Library 3.0, when used with: <ul> <li>Microsoft Visual C++ 4.0 Standard Edition</li></ul>

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

<ul> <li>Microsoft Visual C++ 4.2 Enterprise Edition</li></ul>

<ul> <li>Microsoft Visual C++ 5.0 Enterprise Edition</li></ul>

<ul> <li>Microsoft Visual C++ 6.0 Enterprise Edition</li></ul>

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

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

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

<ul> <li>Microsoft Visual C++ 6.0 Standard Edition</li></ul>

<ul> <li>Microsoft Visual C++ .NET 2002 Standard Edition</li></ul>

<ul> <li>Microsoft Visual C++ .NET 2003 Standard Edition</li></ul> </li></ul>

-

<div class="notice_section">

This article was previously published under Q183218

<div class="notice_section">

NOTE: Microsoft Visual C++ .NET (2002) and Microsoft Visual C++ .NET (2003) support both the managed code model that is provided by the .NET Framework and the unmanaged native Windows code model. The information in this article applies to unmanaged Visual C++ code only.

<div class="summary_section">

SUMMARY
This article describes how to subclass a control on the dialog box resource template using ATL.

<div class="moreinformation_section">

MORE INFORMATION
You need to perform the following steps to subclass a control, such as the ComboBox, on the dialog template in an ATL project: <ol> <li> Declare a member of type CContainedWindow in the CDialogImpl-derived class for the Dialog Template as: <pre class="fixed_text">     CContainedWindow   m_ComboBox; </li> <li> Initialize the CContainedWindow member in the constructor of the CDialogImpl-derived class (CMyDialog class) with the appropriate class name as: <pre class="fixed_text">     CMyDialog::CMyDialog : m_ComboBox(_T("COMBOBOX"), this, 1) </li> <li> Add WM_INITDIALOG and WM_DESTROY message handlers, and an Altered Message Map (ALT_MSG_MAP), to the default Message Map of the CDialogImpl-derived class. The Altered Message Map is used to trap messages that are sent to the subclassed control, as in the following example:

Sample Code
BEGIN_MSG_MAP(CMyDialog) MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog) MESSAGE_HANDLER(WM_DESTROY, OnDestroy)

ALT_MSG_MAP(1)  // Handlers for the subclassed combo box. MESSAGE_HANDLER(WM_RBUTTONDOWN, OnRBtnDown) // Trap a right[ASCII 150]click. END_MSG_MAP </li> <li> In the WM_INITDIALOG handler of the CDialogImpl-derived class, subclass the ComboBox as: <pre class="fixed_text">     m_ComboBox.SubclassWindow(::GetDlgItem(m_hWnd,IDC_SUB_COMBOBOX)); </li> <li> In the WM_DESTROY handler of the CDialogImpl derived class unsubclass the ComboBox as: <pre class="fixed_text">     m_ComboBox.UnsubclassWindow; </li></ol>

The previous steps ensure that the ALT_MSG_MAP traps the messages meant for the subclassed control. They also work for a property page in an ATL control instead of a standard dialog box.

Additional query words: ocx kbATL200 kbATL210 kbATL300 kbvc400 kbvc410 kbvc420 kbvc500 kbvc600 kbserver kbctrl

Keywords: kbhowto kbarchitecture kbdlg kbctrl KB183218

-

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

© Microsoft Corporation. All rights reserved.