【文章內(nèi)容簡(jiǎn)介】
DDX_Control(pDX, IDC_STATICIP, m_name)。 DDX_Control(pDX, IDC_STATICPORT, m_port)。 //}}AFX_DATA_MAP}BEGIN_MESSAGE_MAP(CServerDlg, CDialog)//{{AFX_MSG_MAP(CServerDlg)ON_WM_SYSCOMMAND()ON_WM_PAINT()ON_WM_QUERYDRAGICON()//}}AFX_MSG_MAPEND_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////// CServerDlg message handlersBOOL CServerDlg::OnInitDialog(){ CDialog::OnInitDialog()。 // Add About... menu item to system menu. // IDM_ABOUTBOX must be in the system mand range. ASSERT((IDM_ABOUTBOX amp。 0xFFF0) == IDM_ABOUTBOX)。 ASSERT(IDM_ABOUTBOX 0xF000)。 CMenu* pSysMenu = GetSystemMenu(FALSE)。 if (pSysMenu != NULL) { CString strAboutMenu。 (IDS_ABOUTBOX)。 if (!()) { pSysMenuAppendMenu(MF_SEPARATOR)。 pSysMenuAppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu)。 } } // Set the icon for this dialog. The framework does this automatically // when the application39。s main window is not a dialog SetIcon(m_hIcon, TRUE)。 // 設(shè)置大圖 SetIcon(m_hIcon, FALSE)。 // 設(shè)置小圖 DWORD nSize = MAX_COMPUTERNAME_LENGTH + 1。 char Buffer[MAX_COMPUTERNAME_LENGTH + 1]。 GetComputerName(Buffer,amp。nSize)。 CString str。 (服務(wù)器名稱:%s,Buffer)。 (str)。 (服務(wù)器端口號(hào):70)。 return TRUE。 // return TRUE unless you set the focus to a control}void CServerDlg::OnSysCommand(UINT nID, LPARAM lParam){ if ((nID amp。 0xFFF0) == IDM_ABOUTBOX) { CAboutDlg dlgAbout。 ()。 } 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 using the document/view model,// this is automatically done for you by the framework.void CServerDlg::OnPaint() { if (IsIconic()) { CPaintDC dc(this)。 // 創(chuàng)建一個(gè)設(shè)備上下文,用于畫圖 SendMessage(WM_ICONERASEBKGND, (WPARAM) (), 0)。 // 圖片居中顯示 int cxIcon = GetSystemMetrics(SM_CXICON)。 int cyIcon = GetSystemMetrics(SM_CYICON)。 CRect rect。 GetClientRect(amp。rect)。 int x = (() cxIcon + 1) / 2。 int y = (() cyIcon + 1) / 2。 // 畫圖 (x, y, m_hIcon)。 } else { CDialog::OnPaint()。 }}// The system calls this to obtain the cursor to display while the user drags// the minimized window.HCURSOR CServerDlg::OnQueryDragIcon(){ return (HCURSOR) m_hIcon。}void CServerDlg::OnOK() { thisUpdateData()。 m_pSocket = new CServerSocket(this)。 if (!m_pSocketCreate(70)) { MessageBox(套接字創(chuàng)建失敗)。 delete m_pSocket。 m_pSocket = NULL。 return。 } if (!m_pSocketListen()) MessageBox(監(jiān)聽失敗)。}void CServerDlg::AcceptConnect(){ CClientSocket* socket = new CClientSocket(this)。 //接受客戶端的連接 if (m_pSocketAccept(*socket)) (socket)。 else delete socket。}void CServerDlg::ReceiveData(CClientSocket* socket){ char bufferdata[BUFFERSIZE]。 //接收客戶端傳來的數(shù)據(jù) int result = socketReceive(bufferdata,BUFFERSIZE)。 bufferdata[result] = 0。 POSITION pos = ()。 //將數(shù)據(jù)發(fā)送給每個(gè)客戶端 while (pos!=NULL) { CClientSocket* socket = (CClientSocket*)(pos)。 if (socket != NULL) socketSend(bufferdata,result)。 }}(二)客戶端主要代碼// : implementation fileinc