【正文】
//{{AFX_DATA_MAP(CChatDlg) // NOTE: the ClassWizard will add DDX and DDV calls here //}}AFX_DATA_MAP}BEGIN_MESSAGE_MAP(CChatDlg, CDialog) //{{AFX_MSG_MAP(CChatDlg) ON_WM_SYSCOMMAND() ON_WM_PAINT() ON_WM_QUERYDRAGICON() ON_BN_CLICKED(IDC_BTN_SEND, OnBtnSend) //}}AFX_MSG_MAP ON_MESSAGE(WM_RECVDATA,OnRecvData)END_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////// CChatDlg message handlersBOOL CChatDlg::OnInitDialog(){ CDialog::OnInitDialog()。 0xFFF0) == IDM_ABOUTBOX)。 CMenu* pSysMenu = GetSystemMenu(FALSE)。 (IDS_ABOUTBOX)。 pSysMenuAppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu)。s main window is not a dialog SetIcon(m_hIcon, TRUE)。 // Set small icon // TODO: Add extra initialization here InitSocket()。 pRecvParamhwnd=m_hWnd。 HANDLE hThread=CreateThread(NULL,0,RecvProc,(LPVOID)pRecvParam,0,NULL)。 thisSetWindowText(ChatWindow)。 // return TRUE unless you set the focus to a control}void CChatDlg::OnSysCommand(UINT nID, LPARAM lParam){ if ((nID amp。 ()。 }}// 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 CChatDlg::OnPaint() { if (IsIconic()) { CPaintDC dc(this)。 // Center icon in client rectangle int cxIcon = GetSystemMetrics(SM_CXICON)。 CRect rect。rect)。 int y = (() cyIcon + 1) / 2。 } else { CDialog::OnPaint()。}BOOL CChatDlg::InitSocket(){ m_socket=socket(AF_INET,SOCK_DGRAM,0)。 return FALSE。 =AF_INET。 =htonl(INADDR_ANY)。 retval=bind(m_socket,(SOCKADDR*)amp。 if(SOCKET_ERROR==retval) { closesocket(m_socket)。 return FALSE。 } return TRUE。 HWND hwnd=((RECVPARAM*)lpParameter)hwnd。 int len=sizeof(SOCKADDR)。 char tempBuf[100]。 while(TRUE) { retval=recvfrom(sock,recvBuf,100,0, (SOCKADDR*)amp。len)。 } sprintf(tempBuf,%s說(shuō):%s,inet_ntoa(), recvBuf)。 } return 0。 CString strTemp。 str+=\r\n。 SetDlgItemText(IDC_EDIT_RECV,str)。 ((CIPAddressCtrl*)GetDlgItem(IDC_IPADDRESS1))GetAddress(dwIP)。 =AF_INET。 =htons(5000)。 GetDlgItemText(IDC_EDIT_SEND,strSend)。addrTo,sizeof(SOCKADDR))。} 20