CLitBox控件,显示内容重复到一块
jzp12 2009-08-18 05:11:56 在dialog上放了一个ListBox控件(ID:IDC_LIST_BOX_CONTENT,对应变量m_pListBox),然后用CStdioFile去一行一行读取一个文件1.txt. 现1.txt内容为:
1111111
22222222
333333333
1111111
22222222
333333333
代码如下:
m_pListBox = (CListBox *)GetDlgItem(IDC_LIST_BOX_CONTENT);
if (NULL == m_pListBox) {
return FALSE;
}
// Reset List Box content
m_pListBox->ResetContent();
sfile.Open(m_strFileToOpen, CFile::modeRead);
while (sfile.ReadString(strContent))
{
m_pListBox->AddString(strContent);
}
sfile.Close();
我调用发现strContent中的内容还是跟内容一致的,但是在ListBox控件上显示出来却变成了,同要样的内容在一起了,百思不得其解:
1111111
1111111
22222222
22222222
333333333
333333333
另外想问一下,为什么调用:m_pListBox = (CListBox *)GetDlgItem(IDC_LIST_BOX_CONTENT);
后不能再使用m_pListBox->Create(...)了。
否则会在WINCORE.CPP中报错:ASSERT(pWnd->m_hWnd == NULL); // only do once