Microsoft KB Archive/243454

= PRB: MFC ActiveX Control with Subclassed ComboBox Does Not Drop Down Correctly in a VB Container =

Article ID: 243454

Article Last Modified on 11/21/2006

-

APPLIES TO

 Microsoft Foundation Class Library 4.2, when used with:  Microsoft Visual C++ 6.0 Service Pack 5

 Microsoft Visual C++ .NET 2002 Standard Edition  Microsoft Visual Basic 5.0 Learning Edition Microsoft Visual Basic 6.0 Learning Edition Microsoft Visual Basic 5.0 Professional Edition</li> Microsoft Visual Basic 6.0 Professional Edition</li> Microsoft Visual Basic 5.0 Enterprise Edition</li> Microsoft Visual Basic 6.0 Enterprise Edition</li> Microsoft Visual C++ .NET 2003 Standard Edition</li></ul>

-

<div class="notice_section">

This article was previously published under Q243454

<div class="notice_section">

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

<div class="symptoms_section">

SYMPTOMS
An MFC ActiveX control with a subclassed ComboBox with the CBS_DROPDOWNLIST style, does not drop down correctly in a Visual Basic container. The control drops down and immediately retracts; it drops down correctly only if it is double-clicked.

<div class="cause_section">

CAUSE
The COleControl handlers for WM_LBUTTONDOWN and WM_LBUTTONUP call the SetCapture and ReleaseCapture functions, respectively. The call to ReleaseCapture in turn sends WM_CAPTURECHANGED notification, which in turn causes the list box portion of the combo box to hide itself.

<div class="resolution_section">

RESOLUTION
Create a message handler for the WM_MOUSEACTIVATE message in your Control class. Call OnActivateInPlace in it: int CCustomComboCtrl::OnMouseActivate(CWnd* pDesktopWnd, UINT nHitTest, UINT message) {       OnActivateInPlace (TRUE, NULL); return COleControl::OnMouseActivate(pDesktopWnd, nHitTest, message); }

<div class="moreinformation_section">

Steps to Reproduce Behavior
<ol> Create a new MFC ActiveX Control project. In the MFC ActiveX Control Wizard, locate Control Settings. In the Create control based on drop-down list, click to select COMBOBOX to create a new control project that subclasses the ComboBox control. Click Finish to create the project.</li>  In the PreCreateWindow of the Control class, add the CBS_DROPDOWNLIST style bit as shown below: BOOL CMySubComboCtrl::PreCreateWindow(CREATESTRUCT& cs) {   cs.style |= CBS_DROPDOWNLIST; cs.lpszClass = _T("COMBOBOX"); return COleControl::PreCreateWindow(cs); }                   </li> Open Visual Basic and select a new Standard EXE project.</li> Add a TextBox to the form.</li> On the Project menu, click Components, and then select the subclassed ComboBox control from the list. Click OK.</li> From the Controls toolbar, drop the control on the form below the edit control.</li> Run the sample and try to drop down the combo box by clicking the down arrow of the combo box.</li></ol>

The control will not drop down unless you double-click it with the mouse.

Keywords: kbcombobox kbcontainer kbctrl kbprb KB243454

-

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

© Microsoft Corporation. All rights reserved.