MFCSocketServerSample的头文件

// MFCSocketServerSample.h : PROJECT_NAME 应用程序的主头文件
//

#pragma once

#ifndef __AFXWIN_H__
    #error "在包含此文件之前包含“stdafx.h”以生成 PCH 文件"
#endif

#include "resource.h"        // 主符号


// CMFCSocketServerSampleApp: 
// 有关此类的实现,请参阅 MFCSocketServerSample.cpp
//

class CMFCSocketServerSampleApp : public CWinApp
{
public:
    CMFCSocketServerSampleApp();

// 重写
public:
    virtual BOOL InitInstance();

// 实现

    DECLARE_MESSAGE_MAP()
};

extern CMFCSocketServerSampleApp theApp;
// MFCSocketServerSampleDlg.h : 头文件
//

#pragma once
#include "SocketServer.h"
#include "afxwin.h"
#include "afxcmn.h"

// CMFCSocketServerSampleDlg 对话框
class CMFCSocketServerSampleDlg : public CDialogEx
{
// 构造
public:
    CMFCSocketServerSampleDlg(CWnd* pParent = NULL);    // 标准构造函数

// 对话框数据
#ifdef AFX_DESIGN_TIME
    enum { IDD = IDD_MFCSOCKETSERVERSAMPLE_DIALOG };
#endif

    protected:
    virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV 支持


// 实现
protected:
    HICON m_hIcon;

    // 生成的消息映射函数
    virtual BOOL OnInitDialog();
    afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
    afx_msg void OnPaint();
    afx_msg HCURSOR OnQueryDragIcon();
    DECLARE_MESSAGE_MAP()
public:
    afx_msg void OnBnClickedButtonListen();
    CSocketServer* pSocketServer;
//    CEdit m_Port;
    CString m_Port;
    void WriteLog(CString log);
    CString m_Log;
    afx_msg void OnBnClickedButtonSend();
    CString m_editSend;
    CIPAddressCtrl m_IP;
    afx_msg void OnBnClickedOk();
    afx_msg void OnBnClickedCancel();
    HRESULT OnRecvMsg(WPARAM dwEvent, LPARAM dwLen);
    HRESULT OnLogMsg(WPARAM dwEvent, LPARAM dwLen);
    CString m_editRecv;
};
//SocketClient.h
#pragma once
#define MAXSOCKBUF    1024
class CSocketClient:public CAsyncSocket
{
public:
    CSocketClient();
    ~CSocketClient();
public:
    CString m_strIP;
    HWND m_hMsgWnd;
    int m_nLength;
    char m_szReceBuf[MAXSOCKBUF];
    char m_szSendBuf[MAXSOCKBUF];
    bool m_bConnect;
    HWND m_hWnd;
    CString m_strHost;
    void OnSend(int nErrorCode);
    void OnReceive(int nErrorCode);
    void OnConnect(int nErrorCode);
    void Init();
};
//SocketServer.h
#pragma once
#include "socketclient.h"
class CSocketServer:public CAsyncSocket
{
public:
    CSocketServer();
    ~CSocketServer();
public:
    //void DeleteRemoteSocket(CSocketClient* pSock);
    //POSITION GetRemoteSocketPos(CSocketClient* pSock);
//    CSocketClient* GetRemoteSocket(int pSock);
    CPtrList m_clientList;
    HWND m_hMsgWnd;
//    void OnAccept(int mErrprCpde);
    void OnAccept(int nErrorCode);
    void OnClose(int nErrorCode);
    void DeleteRemoteSocket(CSocketClient* pSock);
};

stdafx.h

// stdafx.h : 标准系统包含文件的包含文件,
// 或是经常使用但不常更改的
// 特定于项目的包含文件

#pragma once

#ifndef VC_EXTRALEAN
#define VC_EXTRALEAN            // 从 Windows 头中排除极少使用的资料
#endif


#include "targetver.h"

#define _ATL_CSTRING_EXPLICIT_CONSTRUCTORS      // 某些 CString 构造函数将是显式的

// 关闭 MFC 对某些常见但经常可放心忽略的警告消息的隐藏
#define _AFX_ALL_WARNINGS
#define _CRT_SECURE_NO_WARNINGS

#include <afxwin.h>         // MFC 核心组件和标准组件
#include <afxext.h>         // MFC 扩展


#include <afxdisp.h>        // MFC 自动化类
#include <afxsock.h>  //new added
#define WM_SOCKET_LOG WM_USER+202
#define WM_SOCKET_RECEIVE WM_USER+203



#ifndef _AFX_NO_OLE_SUPPORT
#include <afxdtctl.h>           // MFC 对 Internet Explorer 4 公共控件的支持
#endif
#ifndef _AFX_NO_AFXCMN_SUPPORT
#include <afxcmn.h>             // MFC 对 Windows 公共控件的支持
#endif // _AFX_NO_AFXCMN_SUPPORT

#include <afxcontrolbars.h>     // 功能区和控件条的 MFC 支持
#include <windows.h>









#ifdef _UNICODE
#if defined _M_IX86
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='x86' publicKeyToken='6595b64144ccf1df' language='*'\"")
#elif defined _M_X64
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='amd64' publicKeyToken='6595b64144ccf1df' language='*'\"")
#else
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
#endif
#endif

targetver.h

#pragma once

// 包括 SDKDDKVer.h 将定义可用的最高版本的 Windows 平台。

// 如果要为以前的 Windows 平台生成应用程序,请包括 WinSDKVer.h,并将
// 将 _WIN32_WINNT 宏设置为要支持的平台,然后再包括 SDKDDKVer.h。

#include <SDKDDKVer.h>

 

posted @ 2020-09-18 00:05  txwtech  阅读(167)  评论(0编辑  收藏  举报