Поделиться через


CNetAddressCtrl Class

The CNetAddressCtrl class represents the network address control, which you can use to input and validate the format of IPv4, IPv6, and named DNS addresses.

class CNetAddressCtrl : public CEdit

Заметки

The network address control verifies that the format of the address the user enters is correct. The control does not actually connect to the network address. The CNetAddressCtrl::SetAllowType method specifies one or more types of address that the CNetAddressCtrl::GetAddress method can parse and verify. An address can be in the form of an IPv4, IPv6, or named address for a server, network, host, or broadcast message destination. If the format of the address is incorrect, you can use the CNetAddressCtrl::DisplayErrorTip method to display an infotip message box that graphically points to the text box of the network address control and displays a predefined error message.

The CNetAddressCtrl class is derived from the CEdit class. Consequently, the network address control provides access to all Windows edit control messages.

The following figure depicts a dialog that contains a network address control. The text box (1) for the network address control contains an invalid network address. The infotip message (2) is displayed if the network address is invalid.

Диалог с элементом управления сетевым адресом и подсказкой.

Требования

Header: afxcmn.h

This class is supported in Windows Vista and later.

Additional requirements for this class are described in Build Requirements for Windows Vista Common Controls.

Пример

The following code example is a portion of a dialog that validates a network address. The event handlers for three radio buttons specify that the network address can be one of three address types. The user enters an address in the text box of the network control, then presses a button to validate the address. If the address is valid, a success message is displayed; otherwise, the predefined infotip error message is displayed.

void CCNetAddressCtrl_s1Dlg::OnBnClickedRadio1()
{
    m_netAddr.SetAllowType(NET_STRING_IPV4_ADDRESS);
}

void CCNetAddressCtrl_s1Dlg::OnBnClickedRadio2()
{
    m_netAddr.SetAllowType(NET_STRING_IPV6_ADDRESS);
}

void CCNetAddressCtrl_s1Dlg::OnBnClickedRadio3()
{
    m_netAddr.SetAllowType(NET_STRING_NAMED_ADDRESS);
}

void CCNetAddressCtrl_s1Dlg::OnBnClickedButton1()
{
    m_na.pAddrInfo = &m_nai;
    HRESULT rslt = m_netAddr.GetAddress(&m_na);
    if (rslt != S_OK)
        m_netAddr.DisplayErrorTip();
    else
    {
        MessageBox(
            _T("Success!"), _T("Validation Results"));
    }

The following code example from the dialog header file defines the NC_ADDRESS and NET_ADDRESS_INFO variables that are required by the CNetAddressCtrl::GetAddress method.

    NC_ADDRESS m_na;
    NET_ADDRESS_INFO m_nai;

См. также

Основные понятия

CNetAddressCtrl Class

CNetAddressCtrl Members

Hierarchy Chart

CEdit Class