Thread: Add String To Combobox?

  1. #1
    Registered User (TNT)'s Avatar
    Join Date
    Aug 2001
    Location
    UK
    Posts
    339

    Cool Add String To Combobox?

    Hi,

    I have created a combo box:

    hWndServer = CreateWindow("COMBOBOX", "", WS_CHILD | WS_VISIBLE | CBS_DROPDOWN
    ,80, 30,
    200, 20, hWnd, (HMENU)ID_SERVER, hInstance, NULL);

    That works fine. How do i add strings to the combo box? i assume i use send message.

    And also do i just use GetWindowText() to get the current selection?

    Thanks

    TNT
    TNT
    You Can Stop Me, But You Cant Stop Us All

  2. #2
    of Zen Hall zen's Avatar
    Join Date
    Aug 2001
    Posts
    1,007
    You can send your combo box an CB_ADDSTRING message to add a string -

    SendMessage(hWndServer,CB_ADDSTRING,0,(LPARAM) yourString);

    and get the selected item's index with CB_GETCURSEL -

    int theIndex = SendMessage(hWndServer,CB_GETCURSEL,0,0);

    You can then get the text that corresponds with this index by sending a CB_GETLBTEXT message with your WPARAM as the index number and the LPARAM as the buffer to recieve the text (if you need the length of text you can send a CB_GETLBTEXTLEN message).

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. char Handling, probably typical newbie stuff
    By Neolyth in forum C Programming
    Replies: 16
    Last Post: 06-21-2009, 04:05 AM
  2. Replies: 4
    Last Post: 03-03-2006, 02:11 AM
  3. Calculator + LinkedList
    By maro009 in forum C++ Programming
    Replies: 20
    Last Post: 05-17-2005, 12:56 PM
  4. creating class, and linking files
    By JCK in forum C++ Programming
    Replies: 12
    Last Post: 12-08-2002, 02:45 PM
  5. Again Character Count, Word Count and String Search
    By client in forum C Programming
    Replies: 2
    Last Post: 05-09-2002, 11:40 AM