IP地址控件,所属类:CIPAddressCtrl
一、类成员函数
IsBlank | Determines if all fields in the IP Address Control are empty. |
ClearAddress | Clears the contents of the IP Address Control. |
GetAddress | Retrieves the address values for all four fields in the IP Address Control. |
SetAddress | Sets the address values for all four fields in the IP Address Control. |
SetFieldFocus | Sets the keyboard focus to the specified field in the IP Address Control. |
SetFieldRange | Sets the range in the specified field in the IP Address Control. |
二、用法示例
void CDialog_IPAdress::OnBnClickedButton1()
{
// TODO: 在此添加控件通知处理程序代码
BOOL r=m_ip.IsBlank();
TRACE("%d \n",r);
}
void CDialog_IPAdress::OnBnClickedButton3()
{
// TODO: 在此添加控件通知处理程序代码
m_ip.ClearAddress();
}
void CDialog_IPAdress::OnBnClickedButton2()
{
// TODO: 在此添加控件通知处理程序代码
//格式一
BYTE i1,i2,i3,i4;
m_ip.GetAddress(i1,i2,i3,i4);
//格式二
DWORD d;
m_ip.GetAddress(d);
//格式二取出单个值
BYTE* pd=(BYTE *)&d;
i4=*pd++;
i3=*pd++;
i2=*pd++;
i1=*pd;
//注意排序
}
void CDialog_IPAdress::OnBnClickedButton4()
{
// TODO: 在此添加控件通知处理程序代码
//法一
m_ip.SetAddress(192,168,0,1);
//法二,较少用
DWORD a=0x11223344;
m_ip.SetAddress(a);
}
void CDialog_IPAdress::OnBnClickedButton5()
{
// TODO: 在此添加控件通知处理程序代码
static int f=0;
if (f>3)
{
f=0;
}
m_ip.SetFieldFocus(f++);//设置焦点,即光标显示的位置0.1.2.3
}
void CDialog_IPAdress::OnBnClickedButton6()
{
// TODO: 在此添加控件通知处理程序代码
//192.168.0.1-192.168.0.100
//第几个位置(0-3),最小值(0-255),最大值(0-255)
m_ip.SetFieldRange(0,192,192);
m_ip.SetFieldRange(1,168,168);
m_ip.SetFieldRange(2,0,0);
m_ip.SetFieldRange(3,1,100);
}