* pSocket , int nCode)
{
static CMsg msg;
msg.Init();
for (POSITION pos1 = m_msgList.FindIndex(pSocket->m_nMsgCount); pos1 != NULL;)
{
//信息内容
枫叶文学网www.fywxw.com
Visual C++ 6.0 程序设计从入门到精通
·306·
msg.m_strText = m_msgList.GetNext(pos1);
//信息类型
msg.code = nCode;
}
pSocket->m_nMsgCount = m_msgList.GetCount();
return &msg;
}
为函数SendForNewccomr()编写如下代码:
void CChatServerDoc::SendForNewccomr(CMsg* pMsg)
{
for(POSITION pos = m_connectionList.GetHeadPosition(); pos != NULL;)
{
//对每个客户端都发送信息
CClientSocket* pSocket = (CClientSocket*)m_connectionList.GetNext(pos);
if (pSocket != NULL)
SendMsg(pSocket, pMsg);
}
}
为函数SendToAllClients()编写如下代码:
void CChatServerDoc::SendToAllClients(int nCode)
{
for(POSITION pos = m_connectionList.GetHeadPosition(); pos != NULL;)
{
//得到每个客户端
CClientSocket* pSocket = (CClientSocket*)m_connectionList.GetNext(pos);
//封装信息
CMsg* pMsg = AssembleMsg(pSocket, nCode);
//发送信息
if (pMsg != NULL)
SendMsg(pSocket, pMsg);
}
}
为函数UpdateMessageView()编写如下代码:
void CChatServerDoc::UpdateMessageView(LPCTSTR lpszMessage)
{
for(POSITION pos=GetFirstViewPosition();pos!=NULL;)
{
CView* pView = GetNextView(pos);
CChatView* pChatView = DYNAMIC_DOWNCAST(CCha