Reputation: 209
i'm new in programming API with C++. I have a problem with create a ComboBox when adding new values in it. This is my code:
void inline createName(HWND hwnd) {
CreateWindow(TEXT("STATIC"), TEXT("Name"),
WS_VISIBLE | WS_CHILD,
10, 10, 100, 20,
hwnd, NULL, NULL, NULL
);
HWND comboBox = CreateWindow(TEXT("COMBOBOX"), NULL,
CBS_DROPDOWN | WS_CHILD | WS_VISIBLE,
120, 10, 200, 20,
hwnd, NULL, NULL, NULL
);
TCHAR Names[2][50] =
{
TEXT("FIRST VALUE"), TEXT("SECOND VALUE")
};
for (int index = 0; index < 2; index++) {
//Add string to combobox
SendMessage(comboBox, (UINT)CB_ADDSTRING, (WPARAM)0, (LPARAM)Names[index]);
}
SendMessage(comboBox, CB_SETCURSEL, (WPARAM)0, (LPARAM)0);
} When i run this code, it only show the value I put in CB_SETCURSEL but I can't select other values. Which means that the dropdown button doesn't work. I get that code from here: https://msdn.microsoft.com/en-us/library/windows/desktop/hh298364(v=vs.85).aspx
Thanks in advance!
EDIT: This is my WinProc function, I only finished the GUI part.
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
switch (msg) {
case WM_CREATE:
createMenuBar(hwnd);
createName(hwnd);
createSex(hwnd);
createLanguage(hwnd);
createAddress(hwnd);
createButton(hwnd);
break;
case WM_CLOSE:
DestroyWindow(hwnd);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, msg, wParam, lParam);
}
return 0;
}
Upvotes: 1
Views: 582
Reputation: 48019
This is a really common problem for new users of comboboxes. Comboboxes are weird in that the height must include the height of the drop-down list, not just the edit control at the top.
I'm glad to see in the comments that you've figured this out. I'm adding this so future readers have a better chance of spotting the answer.
Upvotes: 1