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

Members

Public Constructors

Name

Description

CNetAddressCtrl::CNetAddressCtrl

Constructs a CNetAddressCtrl object.

Public Methods

Name

Description

CNetAddressCtrl::Create

Creates a network address control with specified styles and attaches it to the current CNetAddressCtrl object.

CNetAddressCtrl::CreateEx

Creates a network address control with specified extended styles and attaches it to the current CNetAddressCtrl object.

CNetAddressCtrl::DisplayErrorTip

Displays an error balloon tip when the user enters an unsupported network address in the current network address control.

CNetAddressCtrl::GetAddress

Retrieves a validated and parsed representation of the network address associated with the current network address control.

CNetAddressCtrl::GetAllowType

Retrieves the type of network address that the current network address control can support.

CNetAddressCtrl::SetAllowType

Sets the type of network address that the current network address control can support.

Remarks

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.

Dialog with a network address control and infotip.

Example

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;

Inheritance Hierarchy

CObject

CCmdTarget

CWnd

CEdit

CNetAddressCtrl

Requirements

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.

See Also

Reference

CNetAddressCtrl Class

Hierarchy Chart

CEdit Class