I am getting myself confused. I have a program that has multiple tabs, and on one particular tab I would like to add a combo box. Inside my WinProc() during msg WM_CREATE, I check to see which tab I am in and create the combo box like so...
case WM_CREATE:
#pragma region "CREATE"
{
LRESULT result;
if (tabSelected == 9)
{
// Create an edit box
hwndByte1 = CreateWindow("COMBOBOX", "",
CBS_DROPDOWN | WS_CHILD | WS_VISIBLE,
10,
20,
100,
100,
hwndStatic10,
(HMENU)COMBO_BOX_1,
GetModuleHandle(NULL), NULL);
//Text for first edit box (from 00 -> FF)
for (int i = 0; i < 256; i++)
{
// Add string to combobox.
result = SendMessage(hwndByte1, CB_ADDSTRING, (WPARAM)0, (LPARAM)_T(List[i]));
}
//Initialize Combobox
SendMessage(hwndByte1, CB_SETCURSEL, (WPARAM)2, (LPARAM)0);
}
}
#pragma endregion
When I go to that particular tab, the combo box is created but it is empty :( How do I correctly add an item to the combo box? Is this even the correct spot to initialize the combo box (inside WM_CREATE)?
From a quick look you seem to be doing everything OK, and if the combo box is showing up on your window/form/dialog that proves the thing is being created. A WM_CREATE handler is a satisfactory place to add strings to a combo box.
Since your code doesn't show just what the array List[] is, its impossible to answer your question as to why the strings aren't showing up. If you examine the syntax of the SendMessage() function however, you'll note that for the CB_ADDSTRING message, the 4th parameter needs to be a pointer to a NULL terminated string cast to a LPARAM. Further, it needs apparently, judging from the context of the rest of your code, to be an ansi string. I'm assumming that from the fact that you are using SendMessage() instead of SendMessageA(), and CreateWindow() instead of CreateWindowA(), and your code is compiling without errors with strings like so ...
"COMBOBOX"
It has been my experience that new C++ coders coming into 1st contact with the Windows Api are weak on NULL terminated strings and handling them correctly. So My guess is that your problem involves your array List[].