建一个对话框模板,类名为myDlg,里面放置一IP控件,将变量m_ip与之关联。
比如我在视图里的左键消息映射函数里写
DWORD a;
myDlg dlg;
dlg.DoModal();
dlg.m_ip.GetAddress(a);
myDlg dlg;
dlg.DoModal();
dlg.m_ip.GetAddress(a);
此时,会在dlg.m_ip.GetAddress(a);报错
追踪进入,得到
{ ASSERT(::IsWindow(m_hWnd)); return (int) ::SendMessage(m_hWnd, IPM_GETADDRESS, 0, (LPARAM) &dwAddress); }
_AFXCMN_INLINE void CIPAddressCtrl::SetAddress(DWORD dwAddress)
_AFXCMN_INLINE void CIPAddressCtrl::SetAddress(DWORD dwAddress)
问题原因:
DoModal后窗口已经销毁, 对应的CIPAddressCtrl控件已经不存在
解决方法:
可用OK()或者其他成员函数保存一个成员变量,存放这个IP
void CClient_Setting::OnOK()
{
BYTE ips[4];
CString m_clientstring;
m_ip_address.GetAddress(ips[0],ips[1],ips[2],ips[3]); //读取IP m_ip_address是CClient_Setting的成员变量
m_ipstring.Format("%d.%d.%d.%d",ips[0],ips[1],ips[2],ips[3]);
CDialog::OnOK();
}