mp = strTemp.Mid(strTemp.Find(":" , 0)+1);
}while(strTemp.Find(":",0) != -1);
枫叶文学网www.fywxw.com
Visual C++ 6.0 程序设计从入门到精通
·320·
}
为DeleteContents()函数编写如下代码:
void CChatClientDoc::DeleteContents()
{
if ((m_pSocket != NULL) && (m_pFile != NULL) && (m_pArchiveOut != NULL))
{
//首先发送用户名
SendMsg(m_strNcom, LEAVING_CHAT, false);
CMsg msg;
CString strTemp;
//发送普通消息
strTemp.Format(":离开了聊天室");
msg.code = NORMAL_MESSAGE;
msg.m_bClose = TRUE;
msg.m_strText = m_strNcom + strTemp;
msg.Serialize(*m_pArchiveOut);
m_pArchiveOut->Flush();
}
//删除各对象
delete m_pArchiveOut;
m_pArchiveOut = NULL;
delete m_pArchiveIn;
m_pArchiveIn = NULL;
delete m_pFile;
m_pFile = NULL;
//关闭连接
if (m_pSocket != NULL)
{
m_pSocket->ShutDown(2);
delete m_pSocket;
m_pSocket = NULL;
}
//更新视图
for(POSITION pos=GetFirstViewPosition();pos!=NULL;)
{
CView* pView = GetNextView(pos);
if (pView->IsKindOf(RUNTIME_CLASS(CMessageView)))
{
CMessageView* pChatView = (CMessageView*)pView;
pChatView->GetEditCtrl().SetWindowText(_T(""));
枫叶文学网www.fywxw.com
第11 章 网络编程
·321·
}
if (pView->IsKindOf(RUNTIME_CLASS(CChattersView)))
{
CChattersView* pCChattersView = (CChattersView*)pView;