Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
CNetAddressCtrl Class
Collapse the table of content
Expand the table of content

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




Constructs a CNetAddressCtrl object.




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


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


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


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


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


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

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.

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()

void CCNetAddressCtrl_s1Dlg::OnBnClickedRadio2()

void CCNetAddressCtrl_s1Dlg::OnBnClickedRadio3()

void CCNetAddressCtrl_s1Dlg::OnBnClickedButton1()
	m_na.pAddrInfo = &m_nai;
	HRESULT rslt = m_netAddr.GetAddress(&m_na);
	if (rslt != S_OK)
			_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.


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.

© 2015 Microsoft