chatsocket.cpp
来自「这是一个用MFC实现CSocket程序,能够一定的聊天功能,是基于网络局域网的一」· C++ 代码 · 共 72 行
CPP
72 行
// ChatSocket.cpp : implementation file
//
#include "stdafx.h"
#include "Client.h"
#include "ChatSocket.h"
#include "ClientDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CChatSocket
CChatSocket::CChatSocket()
{
}
CChatSocket::~CChatSocket()
{
}
// Do not edit the following lines, which are needed by ClassWizard.
#if 0
BEGIN_MESSAGE_MAP(CChatSocket, CSocket)
//{{AFX_MSG_MAP(CChatSocket)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
#endif // 0
/////////////////////////////////////////////////////////////////////////////
// CChatSocket member functions
void CChatSocket::OnReceive(int nErrorCode) //重载Receive函数,以收到发来的消息(和异步的socket有些像)
{
// TODO: Add your specialized code here and/or call the base class
CClientApp* pApp=(CClientApp*)AfxGetApp();
CClientDlg* pDlg=(CClientDlg*)pApp->m_pMainWnd;//获取主对话框指针
char flag[2]={0};
if(Receive(flag,2)!=2)//接收的标志函数
return;
if(flag[0]=='Y')//Y表示对方已打开文件!
{
CString str1;
str1=_T("对方已打开文件!");
pDlg->m_ChatDlg.m_MSG.SetSel(0);//对方已打开文件!写入子对话框
pDlg->m_ChatDlg.m_MSG.ReplaceSel(str1);//
}
else
{
char buffer[1024]={0};
int len=Receive(buffer,1024);//服务器转划过来的信息
if(!len)
{
AfxMessageBox("接收信息异常!");
return;
}
pDlg->m_ChatDlg.m_MSGS.InsertString(0,buffer); //由主对话框获取子对话框的指针
}
CSocket::OnReceive(nErrorCode);
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?