CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 10 of 10
  1. #1
    Join Date
    Sep 2009
    Posts
    32

    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");

  2. #2
    Join Date
    Feb 2005
    Posts
    2,160

    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.

  3. #3
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,234

    Re: Noob problem with group box

    Just to clarify this:
    Quote Originally Posted by hoxsiew View Post
    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.
    Ovidiu
    "When in Rome, do as Romans do."
    My latest articles: https://codexpertro.wordpress.com/

  4. #4
    Join Date
    Sep 2009
    Posts
    32

    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.
    Last edited by Waterfox; September 28th, 2009 at 09:20 PM.

  5. #5
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,234

    Re: Noob problem with group box

    Quote Originally Posted by Waterfox View Post
    [...]
    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 View Post
    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.
    Ovidiu
    "When in Rome, do as Romans do."
    My latest articles: https://codexpertro.wordpress.com/

  6. #6
    Join Date
    Sep 2009
    Posts
    32

    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?

  7. #7
    Join Date
    Feb 2005
    Posts
    2,160

    Re: Noob problem with group box

    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?

  8. #8
    Join Date
    Sep 2009
    Posts
    32

    Re: Noob problem with group box

    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
    Attached Images Attached Images  
    Last edited by Waterfox; September 29th, 2009 at 06:39 PM.

  9. #9
    Join Date
    Feb 2005
    Posts
    2,160

    Re: Noob problem with group box

    It's not tall enough. Make that "21" in CreateWindow() something like 200.

  10. #10
    Join Date
    Sep 2009
    Posts
    32

    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!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured