MFCSocketClient头文件

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

#pragma once

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

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


// CMFCSocketClientApp: 
// 有关此类的实现,请参阅 MFCSocketClient.cpp
//

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

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

// 实现

    DECLARE_MESSAGE_MAP()
};

extern CMFCSocketClientApp theApp;
// MFCSocketClientDlg.h : 头文件
//
#include "SocketClient.h"
#pragma once
#include "afxcmn.h"



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

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

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


// 实现
protected:
    HICON m_hIcon;
    //new added
    CSocketClient* pSocketClient;

    // 生成的消息映射函数
    virtual BOOL OnInitDialog();
    afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
    afx_msg void OnPaint();
    afx_msg HCURSOR OnQueryDragIcon();
    DECLARE_MESSAGE_MAP()
public:
    CString m_Log;
    CString m_Port;
    CString m_editRecv;
    CString m_editSend;
    CIPAddressCtrl m_IP;
    afx_msg void OnBnClickedButtonConnect();
    afx_msg void OnBnClickedButtonSend();
    HRESULT OnLogMsg(WPARAM dwEvent, LPARAM dwLen);
    HRESULT OnRecvMsg(WPARAM dwEvent, LPARAM dwLen);
    void WriteLog(CString log);
    
};

SocketClient.h

#pragma once
#define MAXSOCKBUF 1024
class CSocketClient:public CAsyncSocket
{
public:
    CSocketClient();
    ~CSocketClient();
    
public:
    void Init();
    char m_szReceBuf[MAXSOCKBUF];
    char m_szSendBuf[MAXSOCKBUF];
    int m_nLength;
//    void OnClose();
    void OnClose(int nErrorCode);
    void OnConnect(int nErrorCode);
    bool m_bConnect;
    HWND m_hMsgWnd;
    void OnReceive(int nErrorCode);
    void OnSend(int nErrorCode);
    CString m_strHost;
    CString m_strIP;
};

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 WM_SOCKET_LOG WM_USER+200
#define WM_SOCKET_RECEIVE WM_USER+201

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


#include <afxdisp.h>        // MFC 自动化类

#include <afxsock.h> //new added---------

#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

gargetver.h

#pragma once

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

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

#include <SDKDDKVer.h>

 

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