Ugh, ComboBox Woes

This is a discussion on Ugh, ComboBox Woes within the Windows Programming forums, part of the Platform Specific Boards category; Ok, can anyone give me an example of a working default combo box? (By default i mean none user drawn)? ...

  1. #1
    #junkie
    Join Date
    Oct 2004
    Posts
    240

    Ugh, ComboBox Woes

    Ok, can anyone give me an example of a working default combo box? (By default i mean none user drawn)?

    I am very new to Win32, and have only taken a few tutorials (i'll take many, if i can find ones that explain things well lol).

    But with the Aid of MSDN, i am just getting lost.
    I am creating my window with 'CreateWindow' just like a button i would create, i set the styles the way MSDN used as an example.
    ...CBS_SIMPLE, CBS_SORT, WS_VSCROLL, and WS_TABSTOP...
    Now my problem.. or atleast i believe it to be so, is that i cannot add items to my ComboBox. I see nothing when i add my combo box, and i hope it is because there are no items held within it.

    Now on the main ComboBox Overview on MSDN ( http://msdn.microsoft.com/library/de...comboboxes.asp )
    it shows functions like CB_ADDSTRING.. or excuse me, "messages" (still not all together on that part, are they process by a ComboBox proc?), but beyond that i am still lost..


    Anyway, help would be much appreciated.. MSDN has been making me frusterated, the fact that on their using a combo box page ( http://msdn.microsoft.com/library/de...comboboxes.asp ) i cannot find a simple example of their "Creating a Simple Combo Box" section. The only things they seem to show are spell checkers and user drawn junk (which i would like to grasp the basic box before user drawn).

    Anyyway.. again.. please help, thanks!
    01110111011000010110110001100100011011110010000001 11000101110101011010010111010000100000011011000110 10010110011001100101001000000111100101101111011101 0100100000011011100111010101100010

  2. #2
    Registered User
    Join Date
    Feb 2002
    Posts
    329
    SendMessage(hWCombo, CB_ADDSTRING, 0, (long)TEXT("Item 1"));

  3. #3
    #junkie
    Join Date
    Oct 2004
    Posts
    240
    Now may i ask what the
    Code:
    (long)TEXT("Item 1")
    specifically means? I mean is that a C syntax? If so, can you briefly explain what it is about?
    01110111011000010110110001100100011011110010000001 11000101110101011010010111010000100000011011000110 10010110011001100101001000000111100101101111011101 0100100000011011100111010101100010

  4. #4
    Registered User
    Join Date
    Feb 2002
    Posts
    329
    TEXT("Item 1") adds an item with the text Item 1. Replace with the text you want to add.

  5. #5
    #junkie
    Join Date
    Oct 2004
    Posts
    240
    nono, i understand what it "does", but how it does it?

    Like is the (long) a data type defining "TEXT" as a long?

    I'm just at a lack of understanding the format of how that works?

    And in regards to my first post, i am wondering about a general aspect. I saw on MSDN the Send Message CB_ADDSTRING thing, but i'm wondering about it more as a whole.

    ie how do i handle the callbacks for a Combo box? (to get message returns such as user highlighted this string, so set this value to its string, ect..)
    01110111011000010110110001100100011011110010000001 11000101110101011010010111010000100000011011000110 10010110011001100101001000000111100101101111011101 0100100000011011100111010101100010

  6. #6
    Registered User
    Join Date
    Feb 2002
    Posts
    329
    WM_COMMAND, LOWORD(wParam) contains the control id, HIWORD(wParam) contains the message from the combo, i guess you need the CBN_SELCHANGE message..

    Edit:
    CBN=Combo box notification, CBM=combo box merssage

  7. #7
    #junkie
    Join Date
    Oct 2004
    Posts
    240
    Ya.. here is an example code of nothing happening, now keep in mind this is litterally all i have involving the Combo Box, and that all this is inside my windows WM_CREATE message.
    Code:
                HWND hEdit, hwndCombo1;
                hwndCombo1 = CreateWindow("COMBOBOX", "", 
                    CBS_SIMPLE | CBS_SORT | WS_VSCROLL | WS_TABSTOP, 
                    70, 
                    10, 
                    150, 
                    50, 
                    hwnd, NULL, (HINSTANCE) GetWindowLong(hwnd, GWL_HINSTANCE), NULL); 
                if(hwndCombo1 == NULL)
                    MessageBox(hwnd, "Could not create edit box.", "Error", MB_OK | MB_ICONERROR);
                SendMessage(
                    hwndCombo1,
                    CB_ADDSTRING,
                    0,
                    (long)TEXT("myString"));
    Any help on making this work? i see nothing.. (Note that hEdit is a button, i removed that part of this code because i assume it is irrelevant.)
    01110111011000010110110001100100011011110010000001 11000101110101011010010111010000100000011011000110 10010110011001100101001000000111100101101111011101 0100100000011011100111010101100010

  8. #8
    Registered User
    Join Date
    Dec 2004
    Posts
    38
    Maybe you should specify add WS_CHILD(speciefies it is a child window to hwnd) and WS_VISIBLE(specifies it is visible) to the style parameter. I have never worked with combobox specifically but thats a general windows programming thing.

  9. #9
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,856
    and specify the controls uneque ID number as the HMENU param (if using WS_CHILD style)
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  10. #10
    Registered User
    Join Date
    Dec 2004
    Posts
    38
    I have never used the HMENU parameter in CreateWindow() or CreateWindowEx(), what exactly is it for?Is this necessary for just comboboxes since it works without it on other controls such as edit or button.

  11. #11
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,856
    >>LOWORD(wParam) contains the control id

    MSDN
    "For a child window, hMenu specifies the child-window identifier, an integer value used by a dialog box control to notify its parent about events. The application determines the child-window identifier; it must be unique for all child windows with the same parent window. "

    ie
    #define IDC_COMBO 40001 //past those used by resource.h

    then in the createwindow use
    (HMENU)IDC_COMBO

    and in the parent's callback
    Code:
    switch(iMsg)
    {
    case WM_COMMAND:
          switch(LOWORD(wParam))
           {
           case IDC_COMBO: 
           if(HIWORD(wParam)==CBN_SELCHANGE)
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  12. #12
    #junkie
    Join Date
    Oct 2004
    Posts
    240
    Awesome! thanks
    01110111011000010110110001100100011011110010000001 11000101110101011010010111010000100000011011000110 10010110011001100101001000000111100101101111011101 0100100000011011100111010101100010

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Combobox Woes
    By swamprat in forum C# Programming
    Replies: 2
    Last Post: 09-05-2008, 12:51 AM
  2. textBox, comboBox
    By Coding in forum C# Programming
    Replies: 4
    Last Post: 02-16-2008, 08:53 PM
  3. Trouble Adding to ComboBox (*not* an LB_ issue..)
    By roblarky in forum Windows Programming
    Replies: 1
    Last Post: 07-18-2007, 11:27 AM
  4. combobox reacts strangely to a mouse
    By johny145 in forum Windows Programming
    Replies: 2
    Last Post: 03-07-2005, 04:32 PM
  5. Win32 COMBOBOX 'Enter' Key??
    By tdk_ratboy in forum Windows Programming
    Replies: 0
    Last Post: 04-17-2004, 05:52 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21