打开EVC4.0SP4新建“WCE MFC AppWizard(exe)”,再选“Dialog based”。
编辑“IDD_SIMPLELISTBOX_DIALOG”。
新建一个List Box,ID为“IDC_LIST1”。
新建一个Button,ID为“IDC_BUTTON1”,Caption为“Add”。
效果图如下:

双击“Add”按钮,function name为“OnAdd”。
函数内容如下:
编辑“IDD_SIMPLELISTBOX_DIALOG”。
新建一个List Box,ID为“IDC_LIST1”。
新建一个Button,ID为“IDC_BUTTON1”,Caption为“Add”。
效果图如下:

双击“Add”按钮,function name为“OnAdd”。
函数内容如下:
- void CSimpleListBoxDlg::OnAdd()
- {
- // TODO: Add your control notification handler code here
- int i=0;
- TCHAR tmp[10];
- CListBox* pList1;
- pList1 = (CListBox*) GetDlgItem(IDC_LIST1);
- _itow(i,tmp,10);//将i转换为UNICODE码字符串放入temp中,
- //最后一个数字表示十进制
- pList1->AddString(tmp);
- i++;
- /*//另一种添加字符的方式
- CString str;
- for (int i=0;i < 10;i++)
- {
- str.Format(_T("item string %d"), i);
- pmyListBox->AddString( str );
- }
- */
- }