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.
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.
Send LB_ADDSTRING to the ListBox
If its on a dialog window you can send it to the ListBox with..
From MSDN;
LB_ADDSTRING
wParam = 0; // not used; must be zero
lParam = (LPARAM) (LPCTSTR) lpsz; // address of string to add
For exampleLONG 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
);
SendDlgItemMessage(hdwnd,IDC_LIST1,LB_ADDSTRING,0, buffer);
I tried:
LB_ADDSTRING wParam = 0;
lParam = (LPARAM)(LPCTSTR) "Hi";
But I get:
74 wnd_mng.cpp
parse error before `='
Do you have LBS_HASSTRINGS on the listbox?
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");
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
Where 1 is the place of insert //Note in C++ everything starts on 0 (zero)Code:m_listbox.InsertString(1,"Item 1");
C++ Is Powerful
I use C++
There fore I am Powerful