void CMyDlg::OnIPAddress() { // 此段代码:独立的获取本机IP 地址和计算机名 WORD wVersionRequested; WSADATA wsaData; char name[255]; CString ip; PHOSTENT hostinfo; wVersionRequested = MAKEWORD(2, 0); if (WSAStartup(wVersionRequested, &wsaData) == 0) { if(gethostname(name, sizeof(name)) == 0) { if((hostinfo = gethostbyname(name)) != NULL) { ip = inet_ntoa(*(struct in_addr *)*hostinfo->h_addr_list); } } WSACleanup( ); } // AfxMessageBox(name);//name 里是本机名 // AfxMessageBox(ip); //ip 中是本机IP m_IPAddress = ip; // m_IPAddress 是IP 控件对应的变量,ip 是Edit 控件对应的变量 // m_IP.SetAddress(255, 86, 255, 68); // 直接设置控件里显示的值 // 本段代码:已知IP Address 控件里显示的值,转换为CString 格式 /* // 下面代码实现:把 IP Address 控件里的值转化为 CString 格式 unsigned char *pIP; CString strIP; DWORD dwIP; m_IP.GetAddress(dwIP); // m_IP 为IP Address 控件对应的变量 pIP = (unsigned char*)&dwIP; strIP.Format("%u.%u.%u.%u",*(pIP+3), *(pIP+2), *(pIP+1), *pIP); MessageBox(strIP);*/ /* // 下面代码实现:把 IP Address 控件里的值转化为 CString 格式 BYTE f0, f1, f2, f3; m_IP.GetAddress(f0, f1, f2, f3); CString m_addr; m_addr.Format("%d%s%d%s%d%s%d", f0, ".", f1, ".", f2, ".", f3); MessageBox(m_addr);*/ /* // 下面代码实现:把 IP Address 控件里的值转化为 CString 格式 BYTE IPByte[4]; m_IP.GetAddress(IPByte[0], IPByte[1], IPByte[2], IPByte[3]); CString strIP = ""; char temp1[10], temp2[10], temp3[10], temp4[10]; itoa(IPByte[0], temp1, 10); itoa(IPByte[1], temp2, 10); itoa(IPByte[2], temp3, 10); itoa(IPByte[3], temp4, 10); strIP += temp1; strIP += "."; strIP += temp2; strIP += "."; strIP += temp3; strIP += "."; strIP += temp4; MessageBox(strIP);*/ /* // 下面代码实现:把 IP Address 控件里的值转化为 CString 格式 CString strx; m_IP.GetWindowText(strx); MessageBox(strx);*/ // 此段代码...