我试图从MFC C ++中的IP地址控件中获取IP地址。但它返回错误ASSERT(::IsWindow(m_hWnd)); return (int) ::SendMessage(m_hWnd, IPM_GETADDRESS, 0, (LPARAM) &dwAddress); }

这是我所做的代码。在此行Dlg.m_IPAdd.GetAddress(IP2);中生成错误

BOOL CProxyCardSimulatorDlg::OnInitDialog()
{
CLogin Dlg;
bool isDbConnected;

Dlg.DoModal();

CDialog::OnInitDialog();

// Add "About..." menu item to system menu.

// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);

CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
    CString strAboutMenu;
    strAboutMenu.LoadString(IDS_ABOUTBOX);
    if (!strAboutMenu.IsEmpty())
    {
        pSysMenu->AppendMenu(MF_SEPARATOR);
        pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
    }
}

// Set the icon for this dialog.  The framework does this automatically
//  when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE);         // Set big icon
SetIcon(m_hIcon, FALSE);        // Set small icon

// TODO: Add extra initialization here

CRect rect;
ConsoleLog.GetClientRect(&rect);

ConsoleLog.InsertColumn(0, _T(" "), LVCFMT_LEFT, rect.Width());

LONG style = ::GetWindowLong(m_IDEnter.m_hWnd, GWL_STYLE);
style |= ES_NUMBER;
::SetWindowLong(m_IDEnter.m_hWnd, GWL_STYLE, style);

m_IDEnter.SetLimitText(6);

DWORD IP2;

Dlg.m_IPAdd.GetAddress(IP2);  // ERROR HERE

if(true == serverConnect(IP))
{
    addData(ConsoleLog,rec,0,9);
}

return TRUE;  // return TRUE  unless you set the focus to a control
}

最佳答案

假设IP地址控件位于CLogin对话框中,则需要在其中调用GetAddress

因此,覆盖CLogin::OnOK()并在其中调用m_IPAdd.GetAddress将IP地址获取到CLogin成员变量中。然后,您可以从对话框中访问该成员变量。

失败的原因是,当您尝试从封闭的对话框访问控件时,CLogin对话框上的IP地址控件已被破坏。通过将内容放入CLogin成员变量,您仍然可以访问它。

关于c++ - IP地址控制C++ ASSERT(:: IsWindow(m_hWnd))错误,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/18736974/

10-13 08:27