Editare

Partajați prin


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.

Syntax

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.

Examples

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.

CNetAddressCtrl::CNetAddressCtrl

Constructs a CNetAddressCtrl object.

CNetAddressCtrl();

Remarks

Use the CNetAddressCtrl::Create or CNetAddressCtrl::CreateEx method to create a network control and attach it to the CNetAddressCtrl object.

CNetAddressCtrl::Create

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

virtual BOOL Create(
    DWORD dwStyle,
    const RECT& rect,
    CWnd* pParentWnd,
    UINT nID);

Parameters

dwStyle
[in] A bitwise combination of styles to be applied to the control. For more information, see Edit Styles.

rect
[in] A reference to a RECT structure that contains the position and size of the control.

pParentWnd
[in] A non-null pointer to a CWnd object that is the parent window of the control.

nID
[in] The ID of the control.

Return Value

TRUE if this method is successful; otherwise, FALSE.

CNetAddressCtrl::CreateEx

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

virtual BOOL CreateEx(
    DWORD dwExStyle,
    DWORD dwStyle,
    const RECT& rect,
    CWnd* pParentWnd,
    UINT nID);

Parameters

dwExStyle
[in] A bitwise combination (OR) of extended styles to be applied to the control. For more information, see the dwExStyle parameter of the CreateWindowEx function.

dwStyle
[in] A bitwise combination (OR) of styles to be applied to the control. For more information, see Edit Styles.

rect
[in] A reference to a RECT structure that contains the position and size of the control.

pParentWnd
[in] A non-null pointer to a CWnd object that is the parent window of the control.

nID
[in] The ID of the control.

Return Value

TRUE if this method is successful; otherwise, FALSE.

CNetAddressCtrl::DisplayErrorTip

Displays an error message in the balloon tip that is associated with the current network address control.

HRESULT DisplayErrorTip();

Return Value

The value S_OK if this method is successful; otherwise, an error code.

Remarks

Use the CNetAddressCtrl::SetAllowType method to specify the types of addresses that the current network address control can support. Use the CNetAddressCtrl::GetAddress method to validate and parse the network address that the user enters. Use the CNetAddressCtrl::DisplayErrorTip method to display an error message infotip if the CNetAddressCtrl::GetAddress method is unsuccessful.

This message invokes the NetAddr_DisplayErrorTip macro, which is described in the Windows SDK. That macro sends the NCM_DISPLAYERRORTIP message.

CNetAddressCtrl::GetAddress

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

HRESULT GetAddress(PNC_ADDRESS pAddress) const;

Parameters

pAddress
[in, out] Pointer to an NC_ADDRESS structure. Set the pAddrInfo member of this structure to the address of a NET_ADDRESS_INFO structure before you call the GetAddress method.

Return Value

The value S_OK if this method is successful; otherwise, a COM error code. For more information about the possible error codes, see the Return Value section of the NetAddr_GetAddress macro.

Remarks

If this method is successful, the NET_ADDRESS_INFO structure contains additional information about the network address.

Use the CNetAddressCtrl::SetAllowType method to specify the types of addresses the current network address control can support. Use the CNetAddressCtrl::GetAddress method to validate and parse the network address that the user enters. Use the CNetAddressCtrl::DisplayErrorTip method to display an error message infotip if the CNetAddressCtrl::GetAddress method is unsuccessful.

This method invokes the NetAddr_GetAddress macro, which is described in the Windows SDK. That macro sends the NCM_GETADDRESS message.

CNetAddressCtrl::GetAllowType

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

DWORD GetAllowType() const;

Return Value

A bitwise combination (OR) of flags that specifies the types of addresses the network address control can support. For more information, see NET_STRING.

Remarks

This message invokes the NetAddr_GetAllowType macro, which is described in the Windows SDK. That macro sends the NCM_GETALLOWTYPE message.

CNetAddressCtrl::SetAllowType

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

HRESULT SetAllowType(DWORD dwAddrMask);

Parameters

dwAddrMask
[in] A bitwise combination (OR) of flags that specifies the types of addresses the network address control can support. For more information, see NET_STRING.

Return Value

S_OK if this method is successful; otherwise, a COM error code.

Remarks

Use the CNetAddressCtrl::SetAllowType method to specify the types of addresses that the current network address control can support. Use the CNetAddressCtrl::GetAddress method to validate and parse the network address that the user enters. Use the CNetAddressCtrl::DisplayErrorTip method to display an error message infotip if the CNetAddressCtrl::GetAddress method is unsuccessful.

This message invokes the NetAddr_SetAllowType macro, which is described in the Windows SDK. That macro sends the NCM_SETALLOWTYPE message.

See also

CNetAddressCtrl Class
Hierarchy Chart
CEdit Class