Visual C++ MFC - CListBox - AddString
CListBox::AddString function is used to add items into the MFC list box control. Look at the sample code given below and also the downloadable link.
Source Code
void CMyTestDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Control(pDX, IDC_LIST1, m_listBox);
}
class CMyTestDlg : public CDialog
{
public:
CMyTestDlg(CWnd* pParent = NULL); // standard constructor
enum { IDD = IDD_MYTEST_DIALOG };
protected:
virtual void DoDataExchange(CDataExchange* pDX);
public:
CListBox m_listBox;
afx_msg void OnBnClickedOk();
afx_msg void OnLbnDblclkList1();
};
BOOL CMyTestDlg::OnInitDialog()
{
CDialog::OnInitDialog();
m_listBox.AddString("ONE");
m_listBox.AddString("TWO");
m_listBox.AddString("THREE");
m_listBox.AddString("FOUR");
m_listBox.AddString("FIVE");
return TRUE; // return TRUE unless you set the focus to a control
}
Click here to download the VC++ Project and Executable
Output
|