How to Create an IP Address Control

This topic demonstrates how to create an instance of an IP address control.

What you need to know

Technologies

Prerequisites

  • C/C++
  • Windows User Interface Programming

Instructions

Before creating an IP address control, load the common controls DLL by calling InitCommonControlsEx. Then use the CreateWindow or the CreateWindowEx function to create an instance IP address control. The class name for the control is WC_IPADDRESS. Use the WS_CHILD style, because there is no specific style constant associated with the IP address control.

In the following C++ code example, the application-defined function first calls InitCommonControlsEx and sets the dwICC member of the INITCOMMONCONTROLSEX structure to ICC_INTERNET_CLASSES, which specifies the IP address class. It then calls CreateWindowEx to create an instance of the IP address control.

// CreateIPAdressFld - creates a IPAddress control.
// Returns the handle to the new control
// TO DO:  calling procedure needs to check whether the handle is NULL, in case 
// of an error in creation.
// int xcoord, ycoord the coordinates of location of the control in the parent window
// HINST hInst is the global handle to the application instance.
// HWND  hWndParent is the handle to the control's parent window. 
//
//
HWND CreateIPAddressFld (HWND hwndParent, int xcoord, int ycoord) 
{     
     
    INITCOMMONCONTROLSEX icex;
    
    // Ensure that the common control DLL is loaded. 
    icex.dwSize = sizeof(INITCOMMONCONTROLSEX);
    icex.dwICC  = ICC_INTERNET_CLASSES ;
    InitCommonControlsEx(&icex); 
    
    // Create the IPAddress control.        
    HWND hWndIPAddressFld = CreateWindow(WC_IPADDRESS, 
                                L"", 
                                WS_CHILD | WS_OVERLAPPED | WS_VISIBLE, 
                                xcoord, 
                                ycoord,
                                150, 
                                20,  
                                hwndParent, 
                                NULL, 
                                hInst, 
                                NULL); 
                                
    return (hWndIPAddressFld);
}

IP Address Control Reference

About IP Address Controls

Using IP Address Controls