Noob problem with group box
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?
Code:
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");
Re: Noob problem with group box
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.
Re: Noob problem with group box
Just to clarify this:
Quote:
Originally Posted by
hoxsiew
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.
Re: Noob problem with group box
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
Code:
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.
Re: Noob problem with group box
Quote:
Originally Posted by
Waterfox
[...]
I replaced the last part of the original code with this
Code:
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:
Quote:
Originally Posted by
ovidiucucu
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. [...]
Re: Noob problem with group box
Oops, sorry about that.
Any ideas on why it isn't working? How would you go about creating a combo box control?
Re: Noob problem with group box
The first line of my post above:
Quote:
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?
1 Attachment(s)
Re: Noob problem with group box
Quote:
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.
Code:
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
Re: Noob problem with group box
It's not tall enough. Make that "21" in CreateWindow() something like 200.
Re: Noob problem with group box
YES! Thank you so much hoxsiew! I can't believe my problem was that simple all this time!
Thanks!