如何创建 ComboBoxEx 控件
本主题演示了如何创建 ComboBoxEx 控件。
需要了解的事项
技术
先决条件
- C/C++
- Windows 用户界面编程
说明
要创建 ComboBoxEx 控件,请使用 WC_COMBOBOXEX 作为窗口类,以便调用 CreateWindowEx 函数。 必须首先调用 InitCommonControlsEx 函数来注册窗口类,同时在随附的 INITCOMMONCONTROLSEX 结构中指定 ICC_USEREX_CLASSES 位。
完整示例
以下应用程序定义的函数将在主窗口中创建一个具有 CBS_DROPDOWN 样式的 ComboBoxEx 控件。
// 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);
}
相关主题