How to Create a ComboBoxEx Control
This topic demonstrates how to create a ComboBoxEx control.
What you need to know
Technologies
Prerequisites
- C/C++
- Windows User Interface Programming
Instructions
To create a ComboBoxEx control, call the CreateWindowEx function, using WC_COMBOBOXEX as the window class. You must first register the window class by calling the InitCommonControlsEx function, while specifying the ICC_USEREX_CLASSES bit in the accompanying INITCOMMONCONTROLSEX structure.
Complete example
The following application-defined function creates a ComboBoxEx control with the CBS_DROPDOWN style in the main window.
// CreateComboEx - Registers the ComboBoxEx window class and creates
// a ComboBoxEx control in the client area of the main window.
//
// g_hwndMain - A handle to the main window.
// g_hinst - A handle to the program instance.
HWND WINAPI CreateComboEx(void)
{
HWND hwnd;
INITCOMMONCONTROLSEX icex;
icex.dwSize = sizeof(INITCOMMONCONTROLSEX);
icex.dwICC = ICC_USEREX_CLASSES;
InitCommonControlsEx(&icex);
hwnd = CreateWindowEx(0, WC_COMBOBOXEX, NULL,
WS_BORDER | WS_VISIBLE |
WS_CHILD | CBS_DROPDOWN,
// No size yet--resize after setting image list.
0, // Vertical position of Combobox
0, // Horizontal position of Combobox
0, // Sets the width of Combobox
100, // Sets the height of Combobox
g_hwndMain,
NULL,
g_hinst,
NULL);
return (hwnd);
}
Related topics