Setting ListBox text

This is a discussion on Setting ListBox text within the Windows Programming forums, part of the Platform Specific Boards category; What is the line of code to add strings to a ListBox? I don't need the list box, I already ...

  1. #1
    BubbleMan
    Guest

    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
    Posts
    5,789
    Send LB_ADDSTRING to the ListBox


    From MSDN;


    LB_ADDSTRING
    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
    BubbleMan
    Guest

    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
    Location
    near a computer
    Posts
    3,859
    Do you have LBS_HASSTRINGS on the listbox?

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

    Code:
    SendDlgItemMessage(YourDialogHandle,YourDialogControlID,LB_ADDSTRING,0,(LPARAM)"Hi");

  6. #6
    Registered User ski6ski's Avatar
    Join Date
    Aug 2001
    Posts
    133
    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
    Code:
    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

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