SetItemText()出错
编译时没有错误,运行时弹出下面的对话框:
winctrl2.cpp中Line:494为
BOOL CListCtrl::SetItemText(int nItem, int nSubItem, LPCTSTR lpszText)
{
ASSERT(::IsWindow(m_hWnd));
ASSERT((GetStyle() & LVS_OWNERDATA)==0);//Line 494
LVITEM lvi;
lvi.iSubItem = nSubItem;
lvi.pszText = (LPTSTR) lpszText;
return (BOOL) ::SendMessage(m_hWnd, LVM_SETITEMTEXT, nItem, (LPARAM)&lvi);
}
BOOL CListDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// UpdateData(false);
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
m_ListCtrl.SetExtendedStyle(LVS_EX_FLATSB|LVS_EX_FULLROWSELECT
|LVS_EX_HEADERDRAGDROP|LVS_EX_ONECLICKACTIVATE
|LVS_EX_GRIDLINES);
// m_ListCtrl.DeleteAllItems();
//初始化列表框的第一行
char *szColumn[]={"姓名","性别","时间","信息"};
int widths[]={70,40,70,100};
for(short ii=0;ii<sizeof(widths)/sizeof(int);ii++)
{
m_ListCtrl.InsertColumn(ii,szColumn[ii],LVCFMT_CENTER,widths[ii]);
}
m_ListCtrl.InsertItem(1,"ddd");
m_ListCtrl.SetItemText(0,1,"ssss");
//导入文件
/* CStdioFile file;
file.Open("F:\\c++\\List\\Debug\\list.txt",CFile::modeReadWrite);
CString str="";
int nCol=0;
int iRow=1;
while(file.ReadString(str))
{
if(nCol==0)
{
m_ListCtrl.InsertItem(iRow,str);
}
else
{
m_ListCtrl.SetItemText(iRow,nCol,str);
}
nCol=(++nCol)%5;
if(nCol==0)
iRow++;
}
//关闭文件
file.Close();*/
return TRUE; // return TRUE unless you set the focus to a control
}