Click to See Complete Forum and Search --> : Noob problem with group box


Waterfox
September 26th, 2009, 11:11 PM
This is most likely a really simple fix. I have the code below in my main windows WM_CREATE case but for some reason there's no options in the combo box, it's just blank, but I'm hoping to see "test1" and "test2" in it. I'm sure I'm missing something really simple, what am I doing wrong?
HWND Test;
Test = CreateWindow( L"COMBOBOX", L"",
WS_CHILD | WS_VISIBLE | CBS_DROPDOWNLIST,
8, 176, 105, 21, Panel1, (HMENU)GROUPBOX_TEST, GetModuleHandle(NULL), NULL);
SendMessage(Test, CB_ADDSTRING, 0, (LPARAM) "test1");
SendMessage(Test, CB_ADDSTRING, 0, (LPARAM) "test2");

hoxsiew
September 27th, 2009, 08:55 AM
Is HWND Test; inside your loop (on the stack)? Does it go out of scope?

Is SendMessage() returning TRUE? If not, try GetLastError().

Try L"test1" and L"test2" as it looks like this is a UNICODE build.

I tried your code and it worked for me but put garbage strings into the combobox because of the aforementioned UNICODE issues.

ovidiucucu
September 27th, 2009, 11:02 AM
Just to clarify this:
Is SendMessage() returning TRUE? If not, try GetLastError().
SendMessage return value depends on the message sent. In case of CB_ADDSTRING the returning value is, in case of success, the zero-based index to the string in the list box or, in case of failure, CB_ERR (which is usually defined as (-1) and not FALSE (0)). Zero means, first index and not failure.
Additionally, GetLastError gives not any valuable info in this case.

Waterfox
September 28th, 2009, 09:13 PM
Interesting, I did the whole make error message box if it equals nothing thing, and seems to be returning nothing.
I replaced the last part of the original code with this if(!(SendMessage(Test, CB_ADDSTRING, 0, (LPARAM) "test1"))){
MessageBox(hwnd, L"Fail", L"Oh no!", 0);
}And the message popped up.
So why is it doing that? I'm using the express edition of visual studio 2008 with sp1 and my windows sdk is up to date.
All I have is a combo box with no options in it :(
I'm not sure if that was the right way to do it but if that code's working for you guys then why not for me?

And I also tried (LPARAM) L"test" as the last argument, still didn't work.

ovidiucucu
September 28th, 2009, 11:54 PM
[...]
I replaced the last part of the original code with this if(!(SendMessage(Test, CB_ADDSTRING, 0, (LPARAM) "test1"))){
MessageBox(hwnd, L"Fail", L"Oh no!", 0);
}And the message popped up.
So why is it doing that?
Because:

SendMessage return value depends on the message sent. In case of CB_ADDSTRING the returning value is, in case of success, the zero-based index to the string in the list box or, in case of failure, CB_ERR (which is usually defined as (-1) and not FALSE (0)). Zero means, first index and not failure. [...]

Waterfox
September 29th, 2009, 01:19 AM
Oops, sorry about that.
Any ideas on why it isn't working? How would you go about creating a combo box control?

hoxsiew
September 29th, 2009, 07:54 AM
The first line of my post above:

Is HWND Test; inside your loop (on the stack)? Does it go out of scope?


Otherwise, I don't know. It all worked for me with the UNICODE string correction. How about posting your whole message loop function?

Waterfox
September 29th, 2009, 06:29 PM
Is HWND Test; inside your loop (on the stack)? Does it go out of scope?
Yes and no.
Here is my whole message loop function. LRESULT CALLBACK WindowProc(HWND hwnd, UINT Msg, WPARAM wParam, LPARAM lParam)
{
switch(Msg)
{
case WM_CREATE:
HWND Test;
Test = CreateWindow( L"COMBOBOX", L"",
WS_CHILD | WS_VISIBLE | CBS_DROPDOWNLIST,
8, 176, 105, 21, hwnd, (HMENU)GROUPBOX_TEST, GetModuleHandle(NULL), NULL);;
SendMessage(Test, CB_ADDSTRING, 0, (LPARAM) L"test1");
SendMessage(Test, CB_ADDSTRING, 0, (LPARAM) L"test2");
break;
case WM_PAINT:
PAINTSTRUCT ps;
HDC hdc;
//nothing here yet
hdc = BeginPaint(hwnd, &ps);
EndPaint(hwnd, &ps);
break;
// If the user wants to close the application
case WM_DESTROY:
// then close it
PostQuitMessage(WM_QUIT);
break;
default:
// Process the left-over messages
return DefWindowProc(hwnd, Msg, wParam, lParam);
}
// If something was not done, let it go
return 0;
}
and here is what it look like

hoxsiew
September 29th, 2009, 09:14 PM
It's not tall enough. Make that "21" in CreateWindow() something like 200.

Waterfox
September 29th, 2009, 10:05 PM
YES! Thank you so much hoxsiew! I can't believe my problem was that simple all this time!
Thanks!