1、 / ChatRoomServerDlg.cpp : implementation file / #include “stdafx.h“ #include “ChatRoomServer.h“ #include “ChatRoomServerDlg.h“ #include “ListenSocket.h“ #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE = _FILE_; #endif / / CAboutDlg dialog used for App About class CAboutDl
2、g : public CDialog public: CAboutDlg(); / Dialog Data /AFX_DATA(CAboutDlg) enum IDD = IDD_ABOUTBOX ; /AFX_DATA / ClassWizard generated virtual function overrides /AFX_VIRTUAL(CAboutDlg) protected: virtual void DoDataExchange(CDataExchange* pDX); / DDX/DDV support /AFX_VIRTUAL / Implementation protec
3、ted: /AFX_MSG(CAboutDlg) /AFX_MSG DECLARE_MESSAGE_MAP() ; CAboutDlg:CAboutDlg() : CDialog(CAboutDlg:IDD) /AFX_DATA_INIT(CAboutDlg) /AFX_DATA_INIT void CAboutDlg:DoDataExchange(CDataExchange* pDX) CDialog:DoDataExchange(pDX); /AFX_DATA_MAP(CAboutDlg) /AFX_DATA_MAP BEGIN_MESSAGE_MAP(CAboutDlg, CDialog
4、) /AFX_MSG_MAP(CAboutDlg) / No message handlers /AFX_MSG_MAP END_MESSAGE_MAP() / / CChatRoomServerDlg dialog CChatRoomServerDlg:CChatRoomServerDlg(CWnd* pParent /*=NULL*/) : CDialog(CChatRoomServerDlg:IDD, pParent) /AFX_DATA_INIT(CChatRoomServerDlg) / NOTE: the ClassWizard will add member initializa
5、tion here /AFX_DATA_INIT / Note that LoadIcon does not require a subsequent DestroyIcon in Win32 m_hIcon = AfxGetApp()-LoadIcon(IDR_MAINFRAME); void CChatRoomServerDlg: /AFX_DATA_MAP(CChatRoomServerDlg) DDX_Control(pDX, IDC_BUTTON_STOP, m_IDC_BUTTON_STOP); DDX_Control(pDX, IDC_BUTTON_START, m_IDC_BU
6、TTON_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_MAP END_MESSAGE_MAP() / / CChatRoomSe
7、rverDlg message handlers BOOL CChatRoomServerDlg:OnInitDialog() CDialog:OnInitDialog(); / Add “About.“ menu item to system menu. / IDM_ABOUTBOX must be in the system command range. ASSERT(IDM_ABOUTBOX ASSERT(IDM_ABOUTBOX AppendMenu(MF_SEPARATOR); pSysMenu-AppendMenu(MF_STRING, IDM_ABOUTBOX, strAbout
8、Menu); / Set the icon for this dialog. The framework does this automatically / when the application s main window is not a dialog SetIcon(m_hIcon, TRUE);/ Set big icon SetIcon(m_hIcon, FALSE);/ Set small icon / TODO: Add extra initialization here m_IDC_BUTTON_STOP.EnableWindow(FALSE); return TRUE; /
9、 return TRUE unless you set the focus to a control void CChatRoomServerDlg:OnSysCommand(UINT nID, LPARAM lParam) if (nID dlgAbout.DoModal(); else CDialog:OnSysCommand(nID, lParam); / If you add a minimize button to your dialog, you will need the code below / to draw the icon. For MFC applications us
10、ing the document/view model, / this is automatically done for you by the framework. void CChatRoomServerDlg:OnPaint() if (IsIconic() CPaintDC dc(this); / device context for painting SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0); / Center icon in client rectangle int cxIcon = GetSystemM
11、etrics(SM_CXICON); int cyIcon = GetSystemMetrics(SM_CYICON); CRect rect; GetClientRect( int x = (rect.Width() - cxIcon + 1) / 2; int y = (rect.Height() - cyIcon + 1) / 2; / Draw the icon dc.DrawIcon(x, y, m_hIcon);OnPaint(); / The system calls this to obtain the cursor to display while the user drag
12、s / the minimized window. HCURSOR CChatRoomServerDlg:OnQueryDragIcon() return (HCURSOR) m_hIcon;OnButtonStart() / TODO: Add your control notification handler code here m_IDC_BUTTON_START.EnableWindow(FALSE);/使启动按钮无效 ListenSocket.Create(6767);/创建监听套接字端口为6767 ListenSocket.Listen();/开始监听 m_IDC_BUTTON_S
13、TOP.EnableWindow(TRUE);/将停止按钮激活 void CChatRoomServerDlg:OnButtonStop() / TODO: Add your control notification handler code here m_IDC_BUTTON_STOP.EnableWindow(FALSE);/使停止按钮无效 ListenSocket.Close();/关闭监听套接字 m_IDC_BUTTON_START.EnableWindow(TRUE);/将启动按钮激活 / ChatRoomServer.h : main header file for the CHA
14、TROOMSERVER application / #if !defined(AFX_CHATROOMSERVER_H_680EC642_E19B_4D55_88DF_2C9E9B1B30FD_INCLUDED_) #define AFX_CHATROOMSERVER_H_680EC642_E19B_4D55_88DF_2C9E9B1B30FD_INCLUDED_ #if _MSC_VER 1000 #pragma once #endif / _MSC_VER 1000 #ifndef _AFXWIN_H_ #error include stdafx.h before including th
15、is file for PCH #endif #include “resource.h“/ main symbols / / CChatRoomServerApp: / See ChatRoomServer.cpp for the implementation of this class / class CChatRoomServerApp : public CWinApp public: CChatRoomServerApp(); / Overrides / ClassWizard generated virtual function overrides /AFX_VIRTUAL(CChat
16、RoomServerApp) public: virtual BOOL InitInstance(); /AFX_VIRTUAL / Implementation /AFX_MSG(CChatRoomServerApp) / NOTE - the ClassWizard will add and remove member functions here. / DO NOT EDIT what you see in these blocks of generated code ! /AFX_MSG DECLARE_MESSAGE_MAP() ; / /AFX_INSERT_LOCATION /
17、Microsoft Visual C+ will insert additional declarations immediately before the previous line. #endif / !defined(AFX_CHATROOMSERVER_H_680EC642_E19B_4D55_88DF_2C9E9B1B30FD_INCLUDED_) / ChatRoomServerDlg.h : header file / #if !defined(AFX_CHATROOMSERVERDLG_H_5BE648B6_8A9C_4E90_BF1D_20FE943A525F_INCLUDE
18、D_) #define AFX_CHATROOMSERVERDLG_H_5BE648B6_8A9C_4E90_BF1D_20FE943A525F_INCLUDED_ #include “ClientSocketList.h“/ Added by ClassView #include “ListenSocket.h“/ Added by ClassView #if _MSC_VER 1000 / / CChatRoomServerDlg dialog class CChatRoomServerDlg : public CDialog / Construction public: CListenS
19、ocket ListenSocket; CChatRoomServerDlg(CWnd* pParent = NULL);/ standard constructor / Dialog Data /AFX_DATA(CChatRoomServerDlg) enum IDD = IDD_CHATROOMSERVER_DIALOG ; CButtonm_IDC_BUTTON_STOP; CButtonm_IDC_BUTTON_START; /AFX_DATA / ClassWizard generated virtual function overrides /AFX_VIRTUAL(CChatR
20、oomServerDlg) protected:/ DDX/DDV support /AFX_VIRTUAL / Implementation protected: HICON m_hIcon; / Generated message map functions /AFX_MSG(CChatRoomServerDlg) virtual BOOL OnInitDialog(); afx_msg void OnSysCommand(UINT nID, LPARAM lParam); afx_msg void OnPaint(); afx_msg HCURSOR OnQueryDragIcon();
21、 afx_msg void OnButtonStart(); afx_msg void OnButtonStop(); /AFX_INSERT_LOCATION / Microsoft Visual C+ will insert additional declarations immediately before the previous line. #endif / !defined(AFX_CHATROOMSERVERDLG_H_5BE648B6_8A9C_4E90_BF1D_20FE943A525F_INCLUDED_) #if !defined(AFX_CLIENTSOCKET_H_5
22、B707F31_3AD5_4F47_B58E_ECFC99EB60F0_INCLUDED_) #define AFX_CLIENTSOCKET_H_5B707F31_3AD5_4F47_B58E_ECFC99EB60F0_INCLUDED_ #if _MSC_VER 1000 / ClientSocket.h : header file / / / CClientSocket command target class CClientSocketList; class CClientSocket : public CSocket / Attributes public: / Operations
23、 public: CClientSocket(CClientSocketList *); virtual CClientSocket(); / Overrides public: CClientSocketList *List; CClientSocket * Front; CClientSocket * Next; / ClassWizard generated virtual function overrides /AFX_VIRTUAL(CClientSocket) public: virtual void OnReceive(int nErrorCode); virtual void
24、OnClose(int nErrorCode); /AFX_VIRTUAL / Generated message map functions /AFX_MSG(CClientSocket) / NOTE - the ClassWizard will add and remove member functions here. /AFX_MSG / Implementation protected: ;defined(AFX_CLIENTSOCKET_H_5B707F31_3AD5_4F47_B58E_ECFC99EB60F0_INCLUDED_) / ClientSocketList.h: i
25、nterface for the CClientSocketList class. / / #if !defined(AFX_CLIENTSOCKETLIST_H_E746355D_FA10_4D12_B544_2FF152C16414_INCLUDED_) #define AFX_CLIENTSOCKETLIST_H_E746355D_FA10_4D12_B544_2FF152C16414_INCLUDED_ #include “ClientSocket.h“ #if _MSC_VER 1000 class CClientSocketList public: BOOL Sends(CClie
26、ntSocket *); BOOL Add(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_) #define AFX_LISTENSOCKET_H_5D655304_370E_4680_A556_E417552D24EC_INCLUDED_ #if _MSC_VER 1000 / ListenSocket.h : header file / #include “ClientSocketList.h“ / / CListenSock
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1