gpt4 book ai didi

c++ - IP 地址控制 C++ ASSERT(::IsWindow(m_hWnd)) 错误

转载 作者:行者123 更新时间:2023-11-28 00:41:18 25 4
gpt4 key购买 nike

我正在尝试从 MFC C++ 中的 IP 地址控件获取 IP 地址。但它返回错误 ASSERT(::IsWindow(m_hWnd));返回 (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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com