怎样取到MFC里IP控件的值啊

jinnykiki 2008-10-17 04:15:34
怎样取到MFC里IP控件的值啊,他是CIPAddressCtrl类,我怎么取到IP地址,并进行判断让IP设置不能为一样。
不要把MSDN的英文解释贴给我啊,他给的方法GetAdress不能用,其他方法也都试过不行GetDlgItemtext,GetWindowText怎么都不行啊
...全文
1075 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
crackle 2009-05-14
  • 打赏
  • 举报
回复
GetAddress 和SetAddress 在VC++6.0 里面调用不出来问题(点不出来)!
其实你只要写上这个方法就可以了,编译不会出错。可以用...
jinnykiki 2008-10-28
  • 打赏
  • 举报
回复
用三楼的方法,可以解决,谢谢
迷途的书童 2008-10-17
  • 打赏
  • 举报
回复
学习中。。。
wtfelse 2008-10-17
  • 打赏
  • 举报
回复
CIPAddressCtrl::GetAddress是有的

CIPAddressCtrl m_ip;
unsigned long u_ip;
m_ip.GetAddress(u_ip);
arthurlee 2008-10-17
  • 打赏
  • 举报
回复
实在不行,你给IP控件发这个消息IPM_GETADDRESS来获取IP地址。

lResult = SendMessage(      // returns LRESULT in lResult     
(HWND) hWndControl, // handle to destination control
(UINT) IPM_GETADDRESS, // message ID
(WPARAM) wParam, // = 0; not used, must be zero
(LPARAM) lParam // = (LPARAM) (LPDWORD) pdwAddr;
);


wParam
Must be zero.
pdwAddr
A pointer to a DWORD value that receives the address. The field 3 value will be contained in bits 0 through 7. The field 2 value will be contained in bits 8 through 15. The field 1 value will be contained in bits 16 through 23. The field 0 value will be contained in bits 24 through 31. The FIRST_IPADDRESS, SECOND_IPADDRESS, THIRD_IPADDRESS, and FOURTH_IPADDRESS macros can also be used to extract the address information. Zero will be returned as the address for any blank fields.
arthurlee 2008-10-17
  • 打赏
  • 举报
回复
不好意思,我用的是VS2008。
jinnykiki 2008-10-17
  • 打赏
  • 举报
回复
难道是我的VC6.0是盗版的?
对象m_ip_ctrl.后没有Getaddress的函数给我选,说我的库里没这函数?
晕,不会吧?
loner0225 2008-10-17
  • 打赏
  • 举报
回复
GetDlgItemText(IDC_IPADDRESS1)就能取得该控件的内容
arthurlee 2008-10-17
  • 打赏
  • 举报
回复



// 头文件
CIPAddressCtrl m_ip_ctrl;

// cpp文件
void CiptestDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Control(pDX, IDC_IPADDRESS1, m_ip_ctrl);
}

void CiptestDlg::OnBnClickedButton1()
{
BYTE field0, field1, field2, field3;
this->m_ip_ctrl.GetAddress( field0, field1, field2, field3 );

CString ip;
ip.Format( _T("%d.%d.%d.%d"), field0, field1, field2, field3 );
AfxMessageBox(ip);
}


测试通过,没有问题,不知道楼主为什么说GetAdress不能用。
PenleyWang 2008-10-17
  • 打赏
  • 举报
回复

BYTE f1, f2, f3, f4;
((CIPAddressCtrl*)GetDlgItem(IP控件ID))->GetAddress(f1, f2, f3, f4);

CString str;
str.Format(L("%d:%d:%d:%d"), f1, f2, f3, f4);
MessageBox(str);

64,691

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧