网络程序设计课程设计vcmfc实现简单的聊天室程序Word文档格式.docx

上传人:b****3 文档编号:16851048 上传时间:2022-11-26 格式:DOCX 页数:5 大小:17.81KB
下载 相关 举报
网络程序设计课程设计vcmfc实现简单的聊天室程序Word文档格式.docx_第1页
第1页 / 共5页
网络程序设计课程设计vcmfc实现简单的聊天室程序Word文档格式.docx_第2页
第2页 / 共5页
网络程序设计课程设计vcmfc实现简单的聊天室程序Word文档格式.docx_第3页
第3页 / 共5页
网络程序设计课程设计vcmfc实现简单的聊天室程序Word文档格式.docx_第4页
第4页 / 共5页
网络程序设计课程设计vcmfc实现简单的聊天室程序Word文档格式.docx_第5页
第5页 / 共5页
亲,该文档总共5页,全部预览完了,如果喜欢就下载吧!
下载资源
资源描述

网络程序设计课程设计vcmfc实现简单的聊天室程序Word文档格式.docx

《网络程序设计课程设计vcmfc实现简单的聊天室程序Word文档格式.docx》由会员分享,可在线阅读,更多相关《网络程序设计课程设计vcmfc实现简单的聊天室程序Word文档格式.docx(5页珍藏版)》请在冰豆网上搜索。

网络程序设计课程设计vcmfc实现简单的聊天室程序Word文档格式.docx

//ChatRoomServerDlg.cpp:

implementationfile//#include“stdafx.h“#include“ChatRoomServer.h“#include“ChatRoomServerDlg.h“#include“ListenSocket.h“#ifdef_DEBUG#definenewDEBUG_NEW#undefTHIS_FILEstaticcharTHIS_FILE[]=__FILE__;

#endif///////////////////////////////////////////////////////////////////////////////CAboutDlgdialogusedforAppAboutclassCAboutDlg:

publicCDialog{public:

CAboutDlg();

//DialogData//{{AFX_DATA(CAboutDlg)enum{IDD=IDD_ABOUTBOX};

//}}AFX_DATA//ClassWizardgeneratedvirtualfunctionoverrides//{{AFX_VIRTUAL(CAboutDlg)protected:

virtualvoidDoDataExchange(CDataExchange*pDX);

//DDX/DDVsupport//}}AFX_VIRTUAL//Implementationprotected:

//{{AFX_MSG(CAboutDlg)//}}AFX_MSGDECLARE_MESSAGE_MAP()};

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//}}AFX_MSG_MAPEND_MESSAGE_MAP()///////////////////////////////////////////////////////////////////////////////CChatRoomServerDlgdialogCChatRoomServerDlg:

CChatRoomServerDlg(CWnd*pParent/*=NULL*/):

CDialog(CChatRoomServerDlg:

IDD,pParent){//{{AFX_DATA_INIT(CChatRoomServerDlg)//NOTE:

theClassWizardwilladdmemberinitializationhere//}}AFX_DATA_INIT//NotethatLoadIcondoesnotrequireasubsequentDestroyIconinWin32m_hIcon=AfxGetApp()->

LoadIcon(IDR_MAINFRAME);

}voidCChatRoomServerDlg:

//{{AFX_DATA_MAP(CChatRoomServerDlg)DDX_Control(pDX,IDC_BUTTON_STOP,m_IDC_BUTTON_STOP);

DDX_Control(pDX,IDC_BUTTON_START,m_IDC_BUTTON_START);

//}}AFX_DATA_MAP}BEGIN_MESSAGE_MAP(CChatRoomServerDlg,CDialog)//{{AFX_MSG_MAP(CChatRoomServerDlg)ON_WM_SYSCOMMAND()ON_WM_PAINT()ON_WM_QUERYDRAGICON()ON_BN_CLICKED(IDC_BUTTON_START,OnButtonStart)ON_BN_CLICKED(IDC_BUTTON_STOP,OnButtonStop)//}}AFX_MSG_MAPEND_MESSAGE_MAP()///////////////////////////////////////////////////////////////////////////////CChatRoomServerDlgmessagehandlersBOOLCChatRoomServerDlg:

OnInitDialog(){CDialog:

OnInitDialog();

//Add“About.“menuitemtosystemmenu.//IDM_ABOUTBOXmustbeinthesystemcommandrange.ASSERT((IDM_ABOUTBOXASSERT(IDM_ABOUTBOXAppendMenu(MF_SEPARATOR);

pSysMenu->

AppendMenu(MF_STRING,IDM_ABOUTBOX,strAboutMenu);

}}//Settheiconforthisdialog.Theframeworkdoesthisautomatically//whentheapplicationsmainwindowisnotadialogSetIcon(m_hIcon,TRUE);

//SetbigiconSetIcon(m_hIcon,FALSE);

//Setsmallicon//TODO:

Addextrainitializationherem_IDC_BUTTON_STOP.EnableWindow(FALSE);

returnTRUE;

//returnTRUEunlessyousetthefocustoacontrol}voidCChatRoomServerDlg:

OnSysCommand(UINTnID,LPARAMlParam){if((nIDdlgAbout.DoModal();

}else{CDialog:

OnSysCommand(nID,lParam);

}}//Ifyouaddaminimizebuttontoyourdialog,youwillneedthecodebelow//todrawtheicon.ForMFCapplicationsusingthedocument/viewmodel,//thisisautomaticallydoneforyoubytheframework.voidCChatRoomServerDlg:

OnPaint(){if(IsIconic()){CPaintDCdc(this);

//devicecontextforpaintingSendMessage(WM_ICONERASEBKGND,(WPARAM)dc.GetSafeHdc(),0);

//CentericoninclientrectangleintcxIcon=GetSystemMetrics(SM_CXICON);

intcyIcon=GetSystemMetrics(SM_CYICON);

CRectrect;

GetClientRect(intx=(rect.Width()-cxIcon+1)/2;

inty=(rect.Height()-cyIcon+1)/2;

//Drawtheicondc.DrawIcon(x,y,m_hIcon);

OnPaint();

}}//Thesystemcallsthistoobtainthecursortodisplaywhiletheuserdrags//theminimizedwindow.HCURSORCChatRoomServerDlg:

OnQueryDragIcon(){return(HCURSOR)m_hIcon;

OnButtonStart(){//TODO:

Addyourcontrolnotificationhandlercodeherem_IDC_BUTTON_START.EnableWindow(FALSE);

//使启动按钮无效ListenSocket.Create(6767);

//创建监听套接字端口为6767ListenSocket.Listen();

//开始监听m_IDC_BUTTON_STOP.EnableWindow(TRUE);

//将停止按钮激活}voidCChatRoomServerDlg:

OnButtonStop(){//TODO:

Addyourcontrolnotificationhandlercodeherem_IDC_BUTTON_STOP.EnableWindow(FALSE);

//使停止按钮无效ListenSocket.Close();

//关闭监听套接字m_IDC_BUTTON_START.EnableWindow(TRUE);

//将启动按钮激活}//ChatRoomServer.h:

mainheaderfilefortheCHATROOMSERVERapplication//#if!

defined(AFX_CHATROOMSERVER_H__680EC642_E19B_4D55_88DF_2C9E9B1B30FD__INCLUDED_)#defineAFX_CHATROOMSERVER_H__680EC642_E19B_4D55_88DF_2C9E9B1B30FD__INCLUDED_#if_MSC_VER>

1000#pragmaonce#endif//_MSC_VER>

1000#ifndef__AFXWIN_H__#errorincludestdafx.hbeforeincludingthisfileforPCH#endif#include“resource.h“//mainsymbols///////////////////////////////////////////////////////////////////////////////CChatRoomServerApp:

//SeeChatRoomServer.cppfortheimplementationofthisclass//classCChatRoomServerApp:

publicCWinApp{public:

CChatRoomServerApp();

//Overrides//ClassWizardgeneratedvirtualfunctionoverrides//{{AFX_VIRTUAL(CChatRoomServerApp)public:

virtualBOOLInitInstance();

//}}AFX_VIRTUAL//Implementation//{{AFX_MSG(CChatRoomServerApp)//NOTE-theClassWizardwilladdandremovememberfunctionshere.//DONOTEDITwhatyouseeintheseblocksofgeneratedcode!

//}}AFX_MSGDECLARE_MESSAGE_MAP()};

///////////////////////////////////////////////////////////////////////////////{{AFX_INSERT_LOCATION}}//MicrosoftVisualC++willinsertadditionaldeclarationsimmediatelybeforethepreviousline.#endif//!

defined(AFX_CHATROOMSERVER_H__680EC642_E19B_4D55_88DF_2C9E9B1B30FD__INCLUDED_)//ChatRoomServerDlg.h:

headerfile//#if!

defined(AFX_CHATROOMSERVERDLG_H__5BE648B6_8A9C_4E90_BF1D_20FE943A525F__INCLUDED_)#defineAFX_CHATROOMSERVERDLG_H__5BE648B6_8A9C_4E90_BF1D_20FE943A525F__INCLUDED_#include“ClientSocketList.h“//AddedbyClassView#include“ListenSocket.h“//AddedbyClassView#if_MSC_VER>

1000///////////////////////////////////////////////////////////////////////////////CChatRoomServerDlgdialogclassCChatRoomServerDlg:

publicCDialog{//Constructionpublic:

CListenSocketListenSocket;

CChatRoomServerDlg(CWnd*pParent=NULL);

//standardconstructor//DialogData//{{AFX_DATA(CChatRoomServerDlg)enum{IDD=IDD_CHATROOMSERVER_DIALOG};

CButtonm_IDC_BUTTON_STOP;

CButtonm_IDC_BUTTON_START;

//}}AFX_DATA//ClassWizardgeneratedvirtualfunctionoverrides//{{AFX_VIRTUAL(CChatRoomServerDlg)protected:

//DDX/DDVsupport//}}AFX_VIRTUAL//Implementationprotected:

HICONm_hIcon;

//Generatedmessagemapfunctions//{{AFX_MSG(CChatRoomServerDlg)virtualBOOLOnInitDialog();

afx_msgvoidOnSysCommand(UINTnID,LPARAMlParam);

afx_msgvoidOnPaint();

afx_msgHCURSOROnQueryDragIcon();

afx_msgvoidOnButtonStart();

afx_msgvoidOnButtonStop();

//{{AFX_INSERT_LOCATION}}//MicrosoftVisualC++willinsertadditionaldeclarationsimmediatelybeforethepreviousline.#endif//!

defined(AFX_CHATROOMSERVERDLG_H__5BE648B6_8A9C_4E90_BF1D_20FE943A525F__INCLUDED_)#if!

defined(AFX_CLIENTSOCKET_H__5B707F31_3AD5_4F47_B58E_ECFC99EB60F0__INCLUDED_)#defineAFX_CLIENTSOCKET_H__5B707F31_3AD5_4F47_B58E_ECFC99EB60F0__INCLUDED_#if_MSC_VER>

1000//ClientSocket.h:

headerfile/////////////////////////////////////////////////////////////////////////////////CClientSocketcommandtargetclassCClientSocketList;

classCClientSocket:

publicCSocket{//Attributespublic:

//Operationspublic:

CClientSocket(CClientSocketList*);

virtual~CClientSocket();

//Overridespublic:

CClientSocketList*List;

CClientSocket*Front;

CClientSocket*Next;

//ClassWizardgeneratedvirtualfunctionoverrides//{{AFX_VIRTUAL(CClientSocket)public:

virtualvoidOnReceive(intnErrorCode);

virtualvoidOnClose(intnErrorCode);

//}}AFX_VIRTUAL//Generatedmessagemapfunctions//{{AFX_MSG(CClientSocket)//NOTE-theClassWizardwilladdandremovememberfunctionshere.//}}AFX_MSG//Implementationprotected:

};

defined(AFX_CLIENTSOCKET_H__5B707F31_3AD5_4F47_B58E_ECFC99EB60F0__INCLUDED_)//ClientSocketList.h:

interfacefortheCClientSocketListclass.////////////////////////////////////////////////////////////////////////#if!

defined(AFX_CLIENTSOCKETLIST_H__E746355D_FA10_4D12_B544_2FF152C16414__INCLUDED_)#defineAFX_CLIENTSOCKETLIST_H__E746355D_FA10_4D12_B544_2FF152C16414__INCLUDED_#include“ClientSocket.h“#if_MSC_VER>

1000classCClientSocketList{public:

BOOLSends(CClientSocket*);

BOOLAdd(CClientSocket*);

CClientSocket*Head;

CClientSocketList();

virtual~CClientSocketList();

#endif//!

defined(AFX_CLIENTSOCKETLIST_H__E746355D_FA10_4D12_B544_2FF152C16414__INCLUDED_)#if!

defined(AFX_LISTENSOCKET_H__5D655304_370E_4680_A556_E417552D24EC__INCLUDED_)#defineAFX_LISTENSOCKET_H__5D655304_370E_4680_A556_E417552D24EC__INCLUDED_#if_MSC_VER>

1000//ListenSocket.h:

headerfile//#include“ClientSocketList.h“///////////////////////////////////////////////////////////////////////////////CListenSock

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 高中教育 > 初中教育

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1