Thread: Help with adding strings into ComboBox using Window Handle

  1. #1
    Registered User
    Join Date
    May 2009
    Posts
    37

    Question Help with adding strings into ComboBox using Window Handle

    I have no idea what's wrong with my code, please help!

    Code:
     
    BOOL CALLBACK FileDlgProc(HWND hwnd2, UINT Message, WPARAM wParam, LPARAM lParam){
        switch(Message){
            case WM_CREATE:{
               HWND handle;
               LRESULT l;
    
               handle = NULL;
               handle = GetDlgItem(hwnd2, ID_S_C);
               if (handle == NULL){
                  MessageBox(hwnd2, "handle == NULL", "........", MB_OK);
               }
               l = SendMessage(handle, CB_ADDSTRING, (WPARAM) 0, (LPARAM) "Name");
               l = SendMessage(handle, WM_SETTEXT, (WPARAM) 0, (LPARAM) "Name");
               l = SendMessage(handle, CB_ADDSTRING, 0, (LPARAM) "Telephone");
               l = SendMessage(handle, CB_ADDSTRING, 0, (LPARAM) "Email");
            }
            break;
            ... //omitted
       }
       ...//omitted
    }
    Assuming my control id is correct, can anyone help by telling me what's wrong with this? I just couldn't get this to work......

    Thanks in advance.

  2. #2
    Registered User
    Join Date
    Mar 2005
    Location
    Mountaintop, Pa
    Posts
    1,058
    Post a code snippet showing how you create your combobox.

  3. #3
    Registered User
    Join Date
    May 2009
    Posts
    37
    Code:
    IDD_FILE DIALOGEX DISCARDABLE  0, 17, 259, 300
    STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION
    FONT 8, "MS Sans Serif"
    BEGIN
        PUSHBUTTON      "&Search", ID_SEARCH, 200, 20, 50, 14
        COMBOBOX        ID_S_C, 13, 20, 120, 200, CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP
        PUSHBUTTON      "&Add", ID_ADD, 200, 65, 50, 14
        PUSHBUTTON      "&Edit", ID_EDIT, 200, 82, 50, 14
        PUSHBUTTON      "&Delete", ID_DELETE, 200, 99, 50, 14
        COMBOBOX        ID_GROUP, 13, 38, 60, 100, CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP
        LISTBOX         ID_LIST, 13, 65, 120, 150, LBS_NOTIFY | WS_BORDER | WS_VSCROLL
    END
    It was created from my .rc

  4. #4
    Registered User
    Join Date
    Mar 2005
    Location
    Mountaintop, Pa
    Posts
    1,058
    Change WM_CREATE to WM_INITDIALOG and give it a try.

    In other words use this
    case WM_INITDIALOG:
    instead of this
    case WM_CREATE:

  5. #5
    Registered User
    Join Date
    May 2009
    Posts
    37
    Thanks, now I can ADDSTRING, but SETTEXT doesn't seem working...

  6. #6
    Registered User
    Join Date
    Mar 2005
    Location
    Mountaintop, Pa
    Posts
    1,058
    Well, how about posting more detailed info on your SETTEXT issue such as a code snippet illustrating the problem?

  7. #7
    Registered User
    Join Date
    Dec 2007
    Posts
    214
    I'm assuming you are wanting to select the "Name" string you just added. Try using the CB_SETCURSEL message.

  8. #8
    Registered User
    Join Date
    May 2009
    Posts
    37
    All problems are solved, thanks!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C or C++
    By AcerN30 in forum Game Programming
    Replies: 41
    Last Post: 05-30-2008, 06:57 PM
  2. 6 measly errors
    By beene in forum Game Programming
    Replies: 11
    Last Post: 11-14-2006, 11:06 AM
  3. confused about adding controls to main window
    By terracota in forum Windows Programming
    Replies: 4
    Last Post: 11-24-2004, 12:35 PM
  4. Adding colour & bmps to a Win 32 Window??
    By carey_sizer in forum Windows Programming
    Replies: 4
    Last Post: 09-04-2004, 05:55 PM
  5. problem with open gl engine.
    By gell10 in forum Game Programming
    Replies: 1
    Last Post: 08-21-2003, 04:10 AM