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?
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.
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
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.
Last edited by Waterfox; September 28th, 2009 at 09:20 PM.
And the message popped up.
So why is it doing that?
Because:
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. [...]
Last edited by ovidiucucu; September 29th, 2009 at 12:03 AM.
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
Last edited by Waterfox; September 29th, 2009 at 06:39 PM.
* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.