The information in this article applies to:
SUMMARYThe Windows combo box contains a list box (of the ComboLBox class) within it. In the standard combo box, this list box has exactly the same width as the combo box. However, you can make the width of the list box wider or narrower than the width of the combo box. You may have seen combo box lists like this in Microsoft Word and Microsoft Excel. This article shows by example how to subclass a standard combo box class to achieve this functionality. MORE INFORMATIONThe combo box in Windows is actually a combination of two or more controls; that's why it's called a "combo" box. For more information about the parts of a combo box and how they relate to each other, please see the following article in the Microsoft Knowledge Base: Q65881 The Parts of a Windows Combo Box and How They RelateTo make the combo box list wider or narrower, you need the handle of the list box control within the combo box. This task is difficult because the list box is actually a child of the desktop window (for CBS_DROPDOWN and CBS_DROPDOWNLIST styles). If it were a child of the ComboBox control, dropping down the list box would clip it to the parent, and it wouldn't display. A combo box receives WM_CTLCOLOR messages for its component controls when they need to be painted. This allows the combo box to specify a color for these controls. The HIWORD of the lParam in this message is the type of the control. In case of the combo box, Windows sends it a WM_CTLCOLOR message with the HIWORD set to CTLCOLOR_LISTBOX when the list box control needs to be painted. The LOWORD of the lParam contains the handle of the list box control. In 32-bit Windows, the WM_CTLCOLOR message has been replaced with multiple messages, one for each type of control (WM_CTLCOLORBTN). For more information about this, please see the following article in the Microsoft Knowledge Base: Q81707 WM_CTLCOLOR Processing for Combo Boxes of All StylesOnce you obtain the handle to the list box control window, you can resize the control by using the MoveWindow API. The following code sample demonstrates how to do this. This sample assumes that you have placed the combo box control in a dialog box. Sample Code
Additional query words:
Keywords : kbcode kbComboBox kbCtrl kbNTOS kbNTOS351 kbWinOS2000 kbSDKWin32 kbGrpUser kbWinOS kbWinOS95 |
Last Reviewed: February 1, 2000 © 2000 Microsoft Corporation. All rights reserved. Terms of Use. |