如何建立 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);
}
相關主題