void CSendFDlg::OnButtonSetAddr()
{
// TODO: Add your control notification handler code here
byte ips[4];
if (0 == m_ctl_IP_Dst. GetAddress(ips[0],ips[1],ips[2],ips[3]) )
{
AfxMessageBox("获取IP地址失败");
}
{
// TODO: Add your control notification handler code here
byte ips[4];
if (0 == m_ctl_IP_Dst. GetAddress(ips[0],ips[1],ips[2],ips[3]) )
{
AfxMessageBox("获取IP地址失败");
}
m_strIP.Format("%d,%d,%d,%d",ips[0],ips[1],ips[2],ips[3]);
AfxMessageBox( m_strIP);
}
AfxMessageBox( m_strIP);
}
当点击应用按钮时,从界面输入的值,就被存到了CString对象中,在程序的其它地方就可以使用了。
如果输入的值超出有效范围,比如444,控件会自动将其改为255。想输入负号或者字母也是不可能的,控件只允许输入0至255的整数。
可以将弹出提示修改一下:
AfxMessageBox("您输入的IP地址为:" + m_strIP);
上面好像弄错了,格式化时应该格式化成.分隔
m_strIP.Format("%d.%d.%d.%d",ips[0],ips[1],ips[2],ips[3]);
void CSendFDlg::OnButtonSetAddr()
{
// TODO: Add your control notification handler code here
byte ips[4];
if (0 == m_ctl_IP_Dst.GetAddress(ips[0],ips[1],ips[2],ips[3]))
{
AfxMessageBox("获取IP地址失败");
}
{
// TODO: Add your control notification handler code here
byte ips[4];
if (0 == m_ctl_IP_Dst.GetAddress(ips[0],ips[1],ips[2],ips[3]))
{
AfxMessageBox("获取IP地址失败");
}
m_strIP.Format("%d.%d.%d.%d",ips[0],ips[1],ips[2],ips[3]);
UpdateData(true);
CString str;
str.Format("您输入的IP地址为:%s : %d",m_strIP,m_i_dst_port);
AfxMessageBox(str);
}
UpdateData(true);
CString str;
str.Format("您输入的IP地址为:%s : %d",m_strIP,m_i_dst_port);
AfxMessageBox(str);
}