开发者

WinApi -> How to create a ComboBox (without resources)

Can anyone tell me how to create a ComboBox with a DropDownList (like the C# ComboBox Control with DropDownStyle = DropDownList) without resources and without MFC? I googled around 20 minutes but all codessamples I found created strange Controls for me (for example a plain area with a checkbox which cant be checked...). My c开发者_JS百科ode looks like this:

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);


You have to call CreateWindow() again, specifying lpClassName = combobox and dwStyle = CBS_DROPDOWNLIST.
You can edit its content by sending messages to it, using SendMessage()

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜