一、将字符串形式的IP地址显示到CIPAddressCtrl
void CMyDlg::SetIPValue(CString strIP)
{
int b1, b2, b3, b4;
int nPos = strIP.Find(".");
b1 = atoi(strIP.Left(nPos));
strIP.Delete(0, nPos + 1);
nPos = strIP.Find(".");
b2 = atoi(strIP.Left(nPos));
strIP.Delete(0, nPos + 1);
nPos = strIP.Find(".");
b3 = atoi(strIP.Left(nPos));
strIP.Delete(0, nPos + 1);
b4 = atoi(strIP);
m_IP.SetAddress(b1, b2, b3, b4);
}
二、获取IP地址并转换成字符串
int CMyDlg::GetIPValue(CString& strIP)
{
BYTE b1, b2, b3, b4;
int nIpNum = m_IP.GetAddress(b1, b2, b3, b4);
if(nIpNum == 0)
strIP = "";
else
strIP.Format("%d.%d.%d.%d", b1, b2, b3, b4);
return nIpNum;
}