msg.m_bClose = TRUE;
m_pArchiveOut->Abort();
CString strTemp;
strTemp.Format("接收数据失败");
DisplayMsg(strTemp);
}
END_CATCH
//如果连接已关闭则删除各对象
if (msg.m_bClose)
{
delete m_pArchiveIn;
枫叶文学网www.fywxw.com
第11 章 网络编程
·319·
m_pArchiveIn = NULL;
delete m_pArchiveOut;
m_pArchiveOut = NULL;
delete m_pFile;
m_pFile = NULL;
delete m_pSocket;
m_pSocket = NULL;
}
}
为DisplayMsg()函数编写如下代码:
void CChatClientDoc::DisplayMsg(LPCTSTR lpszText)
{
for(POSITION pos=GetFirstViewPosition();pos!=NULL;)
{
CView* pView = GetNextView(pos);
CMessageView* pChatView = DYNAMIC_DOWNCAST(CMessageView, pView);
if (pChatView != NULL)
pChatView->ShowMessage(lpszText);
}
}
为UpdateChattersList()函数编写如下代码:
void CChatClientDoc::UpdateChattersList(CMsg* pMsg)
{
CChattersView* pChattersView;
for(POSITION pos=GetFirstViewPosition();pos!=NULL;)
{
CView* pView = GetNextView(pos);
pChattersView = DYNAMIC_DOWNCAST(CChattersView, pView);
//首先清空用户列表视图
if (pChattersView != NULL)
pChattersView->ClearChattersList();
}
CString strTemp = pMsg->m_strText;
//得到所有的用户名并加入到用户列表中
do
{
CString sNcom = strTemp.Left(strTemp.Find(":",0));
pChattersView->AddToChattersList(sNcom);
strTe