点对点交谈的客户端程序Word格式文档下载.docx
《点对点交谈的客户端程序Word格式文档下载.docx》由会员分享,可在线阅读,更多相关《点对点交谈的客户端程序Word格式文档下载.docx(19页珍藏版)》请在冰豆网上搜索。
![点对点交谈的客户端程序Word格式文档下载.docx](https://file1.bdocx.com/fileroot1/2022-11/26/154b11e0-e980-47f4-936a-cf2f88c5e485/154b11e0-e980-47f4-936a-cf2f88c5e4851.gif)
{
public:
CTalkcApp();
//Overrides
//ClassWizardgeneratedvirtualfunctionoverrides
//{{AFX_VIRTUAL(CTalkcApp)
public:
virtualBOOLInitInstance();
//}}AFX_VIRTUAL
//Implementation
//{{AFX_MSG(CTalkcApp)
//NOTE-theClassWizardwilladdandremovememberfunctionshere.
//DONOTEDITwhatyouseeintheseblocksofgeneratedcode!
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
//{{AFX_INSERT_LOCATION}}
//MicrosoftVisualC++willinsertadditionaldeclarationsimmediatelybeforethepreviousline.
#endif//!
//talkc.cpp:
Definestheclassbehaviorsfortheapplication.
stdafx.h"
talkc.h"
talkcDlg.h"
#ifdef_DEBUG
#definenewDEBUG_NEW
#undefTHIS_FILE
staticcharTHIS_FILE[]=__FILE__;
//CTalkcApp
BEGIN_MESSAGE_MAP(CTalkcApp,CWinApp)
//{{AFX_MSG_MAP(CTalkcApp)
//NOTE-theClassWizardwilladdandremovemappingmacroshere.
//DONOTEDITwhatyouseeintheseblocksofgeneratedcode!
ON_COMMAND(ID_HELP,CWinApp:
:
OnHelp)
END_MESSAGE_MAP()
//CTalkcAppconstruction
CTalkcApp:
CTalkcApp()
//TODO:
addconstructioncodehere,
//PlaceallsignificantinitializationinInitInstance
}
//TheoneandonlyCTalkcAppobject
CTalkcApptheApp;
//CTalkcAppinitialization
BOOLCTalkcApp:
InitInstance()
if(!
AfxSocketInit())
{
AfxMessageBox(IDP_SOCKETS_INIT_FAILED);
returnFALSE;
}
AfxEnableControlContainer();
//Standardinitialization
//Ifyouarenotusingthesefeaturesandwishtoreducethesize
//ofyourfinalexecutable,youshouldremovefromthefollowing
//thespecificinitializationroutinesyoudonotneed.
#ifdef_AFXDLL
Enable3dControls();
//CallthiswhenusingMFCinasharedDLL
#else
Enable3dControlsStatic();
//CallthiswhenlinkingtoMFCstatically
CTalkcDlgdlg;
m_pMainWnd=&
dlg;
intnResponse=dlg.DoModal();
if(nResponse==IDOK)
//TODO:
Placecodeheretohandlewhenthedialogis
//dismissedwithOK
elseif(nResponse==IDCANCEL)
//dismissedwithCancel
//Sincethedialoghasbeenclosed,returnFALSEsothatweexitthe
//application,ratherthanstarttheapplication'
smessagepump.
returnFALSE;
//MySocket.h:
headerfile
defined(AFX_MYSOCKET_H__9741667D_315B_4915_BCDE_9F2125BA065C__INCLUDED_)
#defineAFX_MYSOCKET_H__9741667D_315B_4915_BCDE_9F2125BA065C__INCLUDED_
classCTalkcDlg;
//CMySocketcommandtarget
classCMySocket:
publicCAsyncSocket
//Attributes
//Operations
CMySocket();
virtual~CMySocket();
voidSetParent(CTalkcDlg*pDlg);
//{{AFX_VIRTUAL(CMySocket)
virtualvoidOnConnect(intnErrorCode);
virtualvoidOnReceive(intnErrorCode);
virtualvoidOnClose(intnErrorCode);
//Generatedmessagemapfunctions
//{{AFX_MSG(CMySocket)
private:
CTalkcDlg*m_pDlg;
//MySocket.cpp:
implementationfile
MySocket.h"
TalkcDlg.h"
//CMySocket
CMySocket:
CMySocket()
//putthememberpointertoNULL
m_pDlg=NULL;
~CMySocket()
//Donoteditthefollowinglines,whichareneededbyClassWizard.
#if0
BEGIN_MESSAGE_MAP(CMySocket,CAsyncSocket)
//{{AFX_MSG_MAP(CMySocket)
//}}AFX_MSG_MAP
#endif//0
//CMySocketmemberfunctions
voidCMySocket:
OnConnect(intnErrorCode)
if(nErrorCode==0)
//callthedialog'
sOnConnectfunction
m_pDlg->
OnConnect();
OnReceive(intnErrorCode)
sOnReceivefunction
OnReceive();
OnClose(intnErrorCode)
sOnClosefunction
OnClose();
SetParent(CTalkcDlg*pDlg)
//setthememberpointer
m_pDlg=pDlg;
//talkcDlg.h:
defined(AFX_TALKCDLG_H__AC4F7955_1012_4B99_946D_E63FFC0AD185__INCLUDED_)
#defineAFX_TALKCDLG_H__AC4F7955_1012_4B99_946D_E63FFC0AD185__INCLUDED_
//CTalkcDlgdialog
classCTalkcDlg:
publicCDialog
//Construction
voidOnClose();
voidOnConnect();
CMySocketm_sConnectSocket;
voidOnReceive();
CTalkcDlg(CWnd*pParent=NULL);
//standardconstructor
//DialogData
//{{AFX_DATA(CTalkcDlg)
enum{IDD=IDD_TALKC_DIALOG};
CListBoxm_listSent;
CListBoxm_listReceived;
CButtonm_btnConnect;
CStringm_strMsg;
CStringm_strServName;
intm_nServPort;
//}}AFX_DATA
//{{AFX_VIRTUAL(CTalkcDlg)
protected:
virtualvoidDoDataExchange(CDataExchange*pDX);
//DDX/DDVsupport
protected:
HICONm_hIcon;
//{{AFX_MSG(CTalkcDlg)
virtualBOOLOnInitDialog();
afx_msgvoidOnSysCommand(UINTnID,LPARAMlParam);
afx_msgvoidOnPaint();
afx_msgHCURSOROnQueryDragIcon();
afx_msgvoidOnButtonConnect();
afx_msgvoidOnSendMsg();
afx_msgvoidOnButtonClose();
//talkcDlg.cpp:
//CAboutDlgdialogusedforAppAbout
classCAboutDlg:
CAboutDlg();
//{{AFX_DATA(CAboutDlg)
enum{IDD=IDD_ABOUTBOX};
//{{AFX_VIRTUAL(CAboutDlg)
//{{AFX_MSG(CAboutDlg)
CAboutDlg:
CAboutDlg():
CDialog(CAboutDlg:
IDD)
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
voidCAboutDlg:
DoDataExchange(CDataExchange*pDX)
CDialog:
DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
BEGIN_MESSAGE_MAP(CAboutDlg,CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
//Nomessagehandlers
CTalkcDlg:
CTalkcDlg(CWnd*pParent/*=NULL*/)
:
CDialog(CTalkcDlg:
IDD,pParent)
//{{AFX_DATA_INIT(CTalkcDlg)
m_strMsg=_T("
"
);
m_strServName=_T("
m_nServPort=0;
//NotethatLoadIcondoesnotrequireasubsequentDestroyIconinWin32
m_hIcon=AfxGetApp()->
LoadIcon(IDR_MAINFRAME);
voidCTalkcDlg:
//{{AFX_DATA_MAP(CTalkcDlg)
DDX_Control(pDX,IDC_LIST_SENT,m_listSent);
DDX_Control(pDX,IDC_LIST_RECEIVED,m_listReceived);
DDX_Control(pDX,IDC_BUTTON_CONNECT,m_btnConnect);
DDX_Text(pDX,IDC_EDIT_MSG,m_strMsg);
DDX_Text(pDX,IDC_EDIT_SERVNAME,m_strServName);
DDX_Text(pDX,IDC_EDIT_SERVPORT,m_nServPort);
BEGIN_MESSAGE_MAP(CTalkcDlg,CDialog)
//{{AFX_MSG_MAP(CTalkcDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BUTTON_CONNECT,OnButtonConnect)
ON_BN_CLICKED(IDOK,OnSendMsg)
ON_BN_CLICKED(IDC_BUTTON_CLOSE,OnButtonClose)
//CTalkcDlgmessa