- 派生一个MyScoket 基于CSocket #include
class CChatDlg;
class MySocket : public CSocket
{
public:
MySocket();
MySocket(CChatDlg* const p_hwnd);//获得窗口的类指针
virtual ~MySocket();
public:
CChatDlg* p_dlgwnd;
virtual void OnReceive(int nErrorCode);
};
// MySocket
MySocket::MySocket()
{
}
MySocket::MySocket(CChatDlg* const p_hwnd)
{
p_dlgwnd=p_hwnd;
}
MySocket::~MySocket()
{
}
// MySocket member functions
void MySocket::OnReceive(int nErrorCode)
{
CSocket::OnReceive(nErrorCode);
//p_dlgwnd->onReceive();
p_dlgwnd->OnReceive(this);
}
- 构造函数 MySocket(CChatDlg* const p_hwnd);//获得窗口的类指针
重写 virtual void OnReceive(int nErrorCode); 也就是重写CSocket类的接收函数
- CChatDlg 类
// ChatDlg.h : header file
//
#pragma once
#include "MySocket.h"
// CChatDlg dialog
class CChatDlg : public CDialogEx
{
//