网络聊天系统源代码 第9页
//创建聊天室
void CUserDlg::OnCreateRoom()
{
// TODO: Add your control notification handler code here
if (m_IsInRoom)
{
MessageBox("请先退出房间再创建!", "聊天系统", MB_ICONINFORMATION | MB_OK);
751com.cn
}
CCreateRoomDlg dlg;
dlg.DoModal();
}//加入房间
void CUserDlg::OnJoinRoom()
{
// TODO: Add your control notification handler code here
if (m_IsInRoom)
{
MessageBox("请先退出房间再加入!", "聊天系统", MB_ICONINFORMATION | MB_OK);
}
int m_Index;
char sendbuffer[200];
CString SelectText;
//取得要加入的聊天室名
m_Index = m_RoomList.GetCurSel();
m_RoomList.GetText(m_Index, SelectText);
if (SelectText.IsEmpty())
{
MessageBox("你没有选中房间!", "聊天系统", MB_ICONINFORMATION |MB_OK);
return;
}
//封装信息并发送到服务器
sprintf(sendbuffer, "JOIN_ROOM~%s", SelectText);
if (send(usersock, sendbuffer, strlen(sendbuffer) + 1, 0) <= 0)
{
MessageBox("发送错误!", "聊天系统", MB_ICONERROR|MB_OK);
return;
}
//如果聊天室指针不为空先删除再分配,并显示
if (pChatRoomDlg != NULL)
{
delete pChatRoomDlg;
pChatRoomDlg = NULL;
}
pChatRoomDlg = new CChatRoomDlg;
pChatRoomDlg->TitleText = SelectText;
pChatRoomDlg->m_IsCreator = FALSE;
pChatRoomDlg->Create();
pChatRoomDlg->ShowWindow(SW_SHOW);
//从服务器获取聊天室用户列表
int isend = send(usersock, "USER_LIST", strlen("USER_LIST") + 1, 0);
if (isend <=0 )
{
MessageBox("发送失败!", "聊天系统", MB_ICONERROR|MB_OK);
return;
}
m_IsInRoom = TRUE;
UpdateWindow();
}
邀请私聊
//邀请私聊函数
void CUserDlg::OnInviteTalk()
{
// TODO: Add your control notification handler code here
int m_Index = -1;
char sendbuffer[100];
CString m_DestUser;
//取得选中的用户
m_Index = m_AllUser.GetCurSel();
if (m_Index == -1)
{
MessageBox("你没有选中用户!", "聊天系统", MB_ICONINFORMATION | MB_OK);
return;
}
m_AllUser.GetText(m_Index, m_DestUser);
//封装信息,向服务器发送消息
CChatSystemDlg *pdlg = NULL;
pdlg = (CChatSystemDlg *)AfxGetApp()->m_pMainWnd;
if (strcmp(m_DestUser, pdlg->Session) == 0)
{
MessageBox("不能向自己发送私聊请求!", "", MB_ICONINFORMATION | MB_OK);
return;
}
sprintf(sendbuffer, "INVITE_TALK~%s\0", m_DestUser);
if (send(usersock, sendbuffer, strlen(sendbuffer) + 1, 0) <=0 )
{
MessageBox("发送失败!", "聊天系统", MB_OK | MB_ICONERROR);
return;
}
}
上一页 [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] ... 下一页 >>
网络聊天系统源代码 第9页下载如图片无法显示或论文不完整,请联系qq752018766