PRB: MFC ActiveX Control with Subclassed ComboBox Does Not Drop Down Correctly in a VB Container
ID: Q243454
|
The information in this article applies to:
-
The Microsoft Foundation Classes (MFC), included with:
-
Microsoft Visual C++, 32-bit Editions, version 6.0
-
Microsoft Visual Basic Learning, Professional, and Enterprise Editions for Windows, versions 5.0, 6.0
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.
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.
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);
}
MORE INFORMATION
Steps to Reproduce Behavior
- Use the AppWizard to create a new MFC ActiveX ControlWizard, and at step 2 of 2 click COMBOBOX where it says "Which window class, if any, should this control subclass?" and then click Finish.
- 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);
}
- Open Visual Basic and select a new Standard EXE project.
- Add a TextBox to the form.
- On the Project menu, click Components, and then select the subclassed ComboBox control from the list. Click OK.
- From the Controls toolbar, drop the control on the form below the edit control.
- Run the sample and try to drop down the combo box by clicking the down arrow of the combo box.
The control will not drop down unless you double-click it with the mouse.
© Microsoft Corporation 1999, All Rights Reserved.
Contributions by Vidyanand Rajpathak, Microsoft Corporation
Additional query words:
Keywords : kbComboBox kbContainer kbCtrl kbMFC kbVBp kbVC kbVC600 kbDSupport kbVB500 kbGrpMFCATL
Version : WINDOWS:5.0,6.0; winnt:6.0
Platform : WINDOWS winnt
Issue type : kbprb