Thread: Setting ListBox text

  1. #1

    Question Setting ListBox text

    What is the line of code to add strings to a ListBox? I don't need the list box, I already have it. I just need the way to add a string.

  2. #2
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Send LB_ADDSTRING to the ListBox

    From MSDN;

    wParam = 0; // not used; must be zero
    lParam = (LPARAM) (LPCTSTR) lpsz; // address of string to add
    If its on a dialog window you can send it to the ListBox with..

    LONG SendDlgItemMessage(
    HWND hDlg, // handle of dialog box
    int nIDDlgItem, // identifier of control
    UINT Msg, // message to send
    WPARAM wParam, // first message parameter
    LPARAM lParam // second message parameter
    For example

    SendDlgItemMessage(hdwnd,IDC_LIST1,LB_ADDSTRING,0, buffer);

  3. #3

    Question Doesn't work..

    I tried:

    LB_ADDSTRING wParam = 0;
    lParam = (LPARAM)(LPCTSTR) "Hi";

    But I get:

    74 wnd_mng.cpp
    parse error before `='

  4. #4
    train spotter
    Join Date
    Aug 2001
    near a computer
    Do you have LBS_HASSTRINGS on the listbox?

  5. #5
    of Zen Hall zen's Avatar
    Join Date
    Aug 2001
    You don't have to treat the SendDlgItemMessage parameters like variables. You need to do something like -


  6. #6
    Registered User ski6ski's Avatar
    Join Date
    Aug 2001
    If you are using VC6 and working with a dialog, this is what i do:

    Create a member variable for the list box.
    I usualy use something like m_listbox.
    Then use this code to add items
    m_listbox.InsertString(1,"Item 1");
    Where 1 is the place of insert //Note in C++ everything starts on 0 (zero)
    C++ Is Powerful
    I use C++
    There fore I am Powerful

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Setting text cursor in Tubo C
    By sureshkumarct in forum C Programming
    Replies: 1
    Last Post: 12-16-2006, 01:16 AM
  2. Text adventure engine idea. thoughts?
    By suzakugaiden in forum Game Programming
    Replies: 16
    Last Post: 01-15-2006, 05:13 AM
  3. A bunch of Linker Errors...
    By Junior89 in forum Windows Programming
    Replies: 4
    Last Post: 01-06-2006, 02:59 PM
  4. How to use FTP?
    By maxorator in forum C++ Programming
    Replies: 8
    Last Post: 11-04-2005, 03:17 PM
  5. struct question
    By caduardo21 in forum Windows Programming
    Replies: 5
    Last Post: 01-31-2005, 04:49 PM