2011-04-13 73 views
0

任何人都可以告訴我如何使用DropDownList(如C#組合框控件DropDownStyle = DropDownList)創建一個ComboBox沒有資源和沒有MFC?我搜索了大約20分鐘,但是我發現的所有代碼樣本都爲我創建了奇怪的控件(例如,帶有複選框的平原區域,無法檢查...)。我的代碼如下所示:WinApi - >如何創建一個組合框(沒有資源)

WNDCLASSEX wcex; 
HWND hwnd; 
HWND button; 
HDC hDC; 
HGLRC hRC; 
MSG msg; 
BOOL bQuit = FALSE; 
float theta = 0.0f; 

/* register window class */ 
wcex.cbSize = sizeof(WNDCLASSEX); 
wcex.style = CS_OWNDC; 
wcex.lpfnWndProc = WindowProc; 
wcex.cbClsExtra = 0; 
wcex.cbWndExtra = 0; 
wcex.hInstance = hInstance; 
wcex.hIcon = LoadIcon(NULL, IDI_APPLICATION); 
wcex.hCursor = LoadCursor(NULL, IDC_ARROW); 
wcex.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH); 
wcex.lpszMenuName = NULL; 
wcex.lpszClassName = "GLSample"; 
wcex.hIconSm = LoadIcon(NULL, IDI_APPLICATION);; 


if (!RegisterClassEx(&wcex)) 
    return 0; 

/* create main window */ 
hwnd = CreateWindowEx(0, 
         "GLSample", 
         "OpenGL Sample", 
         WS_OVERLAPPEDWINDOW, 
         CW_USEDEFAULT, 
         CW_USEDEFAULT, 
         256, 
         256, 
         NULL, 
         NULL, 
         hInstance, 
         NULL); 
ShowWindow(hwnd, nCmdShow); 

button = CreateWindow("GLSample", "knopf", WS_CHILD | WS_VISIBLE, 200, 200, 150, 60, hwnd, NULL, hInstance, NULL); 

回答

2

您必須再次調用CreateWindow(),指定lpClassName = comboboxdwStyle = CBS_DROPDOWNLIST
您可以通過編輯發送messages它的內容,使用SendMessage()

+0

@BlackBear:再次感謝,也許你能告訴我如何獲得當前選定的項目嗎?那麼今天我很高興^^ – 2011-04-13 12:33:16

+0

@Alex Kruger:WM_SETTEXT和WM_GETTEXT應該讓你設置/獲取選擇的項目文本我認爲(從來沒有使用過:)) – BlackBear 2011-04-13 12:41:16