【正文】
addrTo,sizeof(SOCKADDR))。 =htons(5000)。 ((CIPAddressCtrl*)GetDlgItem(IDC_IPADDRESS1))GetAddress(dwIP)。 str+=\r\n。 } return 0。len)。 char tempBuf[100]。 HWND hwnd=((RECVPARAM*)lpParameter)hwnd。 return FALSE。 retval=bind(m_socket,(SOCKADDR*)amp。 =AF_INET。}BOOL CChatDlg::InitSocket(){ m_socket=socket(AF_INET,SOCK_DGRAM,0)。 int y = (() cyIcon + 1) / 2。 CRect rect。 }}// 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)。 // return TRUE unless you set the focus to a control}void CChatDlg::OnSysCommand(UINT nID, LPARAM lParam){ if ((nID amp。 HANDLE hThread=CreateThread(NULL,0,RecvProc,(LPVOID)pRecvParam,0,NULL)。 // Set small icon // TODO: Add extra initialization here InitSocket()。 pSysMenuAppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu)。 CMenu* pSysMenu = GetSystemMenu(FALSE)。 //{{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()。 // DDX/DDV support //}}AFX_VIRTUAL// Implementationprotected: //{{AFX_MSG(CAboutDlg) //}}AFX_MSG DECLARE_MESSAGE_MAP()}。 } :// : implementation file//include include include ifdef _DEBUGdefine new DEBUG_NEWundef THIS_FILEstatic char THIS_FILE[] = __FILE__。/*發(fā)送完后將編輯文本框設(shè)置為空。*/ sendto(m_socket,strSend,()+1,0, (SOCKADDR*)amp。 =htons(5000)。 SOCKADDR_IN addrTo。}發(fā)送函數(shù)void CChatDlg::OnBtnSend() { // TODO: Add your control notification handler code here DWORD dwIP。 str+=strTemp。 GetDlgItemText(IDC_EDIT_RECV,strTemp)。void CChatDlg::OnRecvData(WPARAM wParam,LPARAM lParam){ CString str=(char*)lParam。 ::PostMessage(hwnd,WM_RECVDATA,0