我写的程序上下两个CListView,一个OPCClientView和EventView Event要根据程序运行情况显示事件,两个视图的通讯我通过消息传递。EventView Event的消息响应函数为
void CEventView::OnRecvEvent(WPARAM wParam,LPARAM lParam)
{
m_Event=(char*)lParam;
static int index=0;
CTime time=CTime::GetCurrentTime();
CString date=time.Format("%A, %B %d, %Y");
CString times=time.Format("%H:%M:S"); GetListCtrl().InsertItem(index,date);
GetListCtrl().SetItemText(index,1,times);
GetListCtrl().SetItemText(index,2,m_Event);
}
跟踪发现程序运行到RUN函数里后出错。
如果把
GetListCtrl().InsertItem(index,date);
GetListCtrl().SetItemText(index,1,times);
GetListCtrl().SetItemText(index,2,m_Event);
注释后能正常运行;
请大家帮忙看下。
void CEventView::OnRecvEvent(WPARAM wParam,LPARAM lParam)
{
m_Event=(char*)lParam;
static int index=0;
CTime time=CTime::GetCurrentTime();
CString date=time.Format("%A, %B %d, %Y");
CString times=time.Format("%H:%M:S"); GetListCtrl().InsertItem(index,date);
GetListCtrl().SetItemText(index,1,times);
GetListCtrl().SetItemText(index,2,m_Event);
}
跟踪发现程序运行到RUN函数里后出错。
如果把
GetListCtrl().InsertItem(index,date);
GetListCtrl().SetItemText(index,1,times);
GetListCtrl().SetItemText(index,2,m_Event);
注释后能正常运行;
请大家帮忙看下。
在这个函数中加断点,你看一下运行到哪一句出现的错误。
而且这里语句还有问题:
CString times=time.Format("%H:%M:S");
应该是
CString times=time.Format("%H:%M:%S");
现在要知道的是这几句中,哪句引起的run错误,明白么?
GetListCtrl().InsertItem(index,date);
GetListCtrl().SetItemText(index,1,times);
GetListCtrl().SetItemText(index,2,m_Event);
这句有错啊,注释后程序就能正常运行了。
GetListCtrl()能得到啊,我另外个View也是这样的 数据能显示。
if (GetListCtrl().GetSafeHwnd()!=NULL)
{
GetListCtrl().InsertItem(index,date);
GetListCtrl().SetItemText(index,1,times);
GetListCtrl().SetItemText(index,2,m_Event);
}