基于winsock的局域网通信系统的开发(3)

2025-09-26

重庆理工大学课程设计

}

return;

if(m_strPassword.IsEmpty()) { }

if(m_strPasswordAgain.IsEmpty()) { }

if(m_strNick.GetLength() > MAX_NICK_LEN) //昵称不能超长 { }

if(m_strPassword.GetLength() > MAX_PASSWORD_LEN) //密码不能超长 { }

if(m_strPassword != m_strPasswordAgain) {

AfxMessageBox(CString(\两次密码输入不一致!\GotoDlgCtrl((CWnd*)GetDlgItem(IDC_PASSWORD)); CString strTemp;

strTemp.Format(\密码不能超过%d个字符!\AfxMessageBox(strTemp);

GotoDlgCtrl((CWnd*)GetDlgItem(IDC_PASSWORD)); return;

CString strTemp;

strTemp.Format(\昵称不能超过%d个字符!\AfxMessageBox(strTemp);

GotoDlgCtrl((CWnd*)GetDlgItem(IDC_NICK)); return;

AfxMessageBox(CString(\请再次输入密码!\

GotoDlgCtrl((CWnd*)GetDlgItem(IDC_PASSWORD_AGAIN)); return;

AfxMessageBox(CString(\请输入密码!\

GotoDlgCtrl((CWnd*)GetDlgItem(IDC_PASSWORD)); return;

11

重庆理工大学课程设计

}

}

return;

CDialog::OnOK();//调用基类的OnOk函数,关闭对话框,并返回IDOK

void CRegisterDlg::OnCancel() { }

// TODO: Add extra cleanup here

CDialog::OnCancel();

2.3模块三

void CP2PClientDlg::OnSelchangeOnlineStatus() {

int nCurSel = m_ctrlOnlineStatus.GetCurSel();

if((nCurSel!=theApp.m_ClientInfo.status) || (!m_bIsLogin)) {

//开始发送改变在线状态信息 IM_Header header;

header.cmd = IM_SESSION_STATUS_CHANGE; header.id = theApp.m_ClientInfo.uid;

header.seq = CP2PClientApp::create_blk_seq(); header.reserved = 0; //开始构造数据包

IM_Message_Block* send_blk = new IM_Message_Block; send_blk->write_header(header);//构造消息头 send_blk->write_UINT32(theApp.m_ClientInfo.uid); send_blk->write_UINT32(theApp.m_ClientInfo.client_ip); send_blk->write_UINT16(theApp.m_ClientInfo.client_port); if(nCurSel == 0) {

send_blk->write_UINT8(IM_STATUS_ONLINE);

12

重庆理工大学课程设计

}

}

}

//本地记录的状态也作相应的改动

theApp.m_ClientInfo.status = IM_STATUS_ONLINE;

else if(nCurSel == 1) { }

else if(nCurSel == 2) { }

else if(nCurSel == 3) { }

send_blk->src_ip_ = theApp.m_ServerInfo.server_ip;//填充该消息的目的地 send_blk->src_port_ = theApp.m_ServerInfo.server_port; send_blk->length_ = send_blk->get_cursor();//填充消息长度 g_send_msg_queue.push_msg(send_blk);//将消息放入发送消息队列

send_blk->write_UINT8(IM_STATUS_OFFLINE); theApp.m_ClientInfo.status = IM_STATUS_OFFLINE; send_blk->write_UINT8(IM_STATUS_OUTWAY); theApp.m_ClientInfo.status = IM_STATUS_OUTWAY; send_blk->write_UINT8(IM_STATUS_HIDE); theApp.m_ClientInfo.status = IM_STATUS_HIDE;

void CP2PClientDlg::OnSendMsg() {

//查看是否选中了好友,如果选中了则顺便取出跟他的聊天记录 POSITION pos = m_ctrlFriendList.GetFirstSelectedItemPosition(); if(!pos) { }

AfxMessageBox(CString(\请选择好友!\return;

13

重庆理工大学课程设计

int nItem = m_ctrlFriendList.GetNextSelectedItem(pos); //界面上显示的新消息数恢复为 m_ctrlFriendList.SetItemText(nItem,3,\vector* history_msg =

CString strValue = m_ctrlFriendList.GetItemText(nItem,0); unsigned int uid = atoi(strValue.GetBuffer(0)); strValue.ReleaseBuffer();

//查看该好友是否在线,如果在线顺便记住该好友的在线信息 BOOL bIsOnline = FALSE;

usr_info_online* friend_online_info = NULL;

vector::iterator it = m_friend_online_list.begin(); for(; it!=m_friend_online_list.end(); it++) { }

//弹出聊天对话框 CSMsgDlg dlg; m_pChildWnd = &dlg; m_nChatFriendID = uid; //查找该好友的基本信息

vector::iterator it_a = m_friend_list.begin(); for(; it_a!=m_friend_list.end(); it_a++) {

usr_info_base* friend_base_info = (usr_info_base*)*it_a; friend_online_info = (usr_info_online*)*it; if(friend_online_info->user_id == uid) { }

if(friend_online_info->status==IM_STATUS_ONLINE || { }

bIsOnline = TRUE; break;

(vector*)m_ctrlFriendList.GetItemData(nItem);

friend_online_info->status==IM_STATUS_OUTWAY)

14

重庆理工大学课程设计

}

if(friend_base_info->user_id == uid) {

memcpy((char*)&dlg.m_friend_info,(char*)(friend_base_info),sizeof(usr_info_b }

if(bIsOnline)//如果在线则将好友的在线信息拷贝给聊天对话框

memcpy((char*)&dlg.m_friend_online,(char*)(friend_online_info),sizeof(usr_infdlg.m_history_msg = history_msg;//将该好友的历史聊天记录传给聊天对话框 dlg.m_bIsOffline = !bIsOnline;//将该好友是否在线传递给聊天对话框 dlg.DoModal();//显示聊天对话框

m_nChatFriendID = 0;//聊天结束后将记录当前聊天好友id变量重新置

}

break;

ase));

o_online));

void CP2PClientDlg::OnDelFriend() {

POSITION pos = m_ctrlFriendList.GetFirstSelectedItemPosition(); if(!pos) { }

int nItem = m_ctrlFriendList.GetNextSelectedItem(pos); CString strValue = m_ctrlFriendList.GetItemText(nItem,0); unsigned int uid = atoi(strValue.GetBuffer(0)); strValue.ReleaseBuffer(); //开始发送删除好友数据包 IM_Header header;

header.cmd = IM_CONTACT_DEL; header.id = theApp.m_ClientInfo.uid;

AfxMessageBox(CString(\请选择好友!\return;

15


基于winsock的局域网通信系统的开发(3).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:铁路客运专线结构物沉降观测方案

相关阅读
本类排行
× 游客快捷下载通道(下载后可以自由复制和排版)

下载本文档需要支付 7

支付方式:

开通VIP包月会员 特价:29元/月

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信:xuecool-com QQ:370150219