IP Address Controls

IP Address Controls


An IP address control allows the user to enter an IP address in an easily understood format. This control also allows the application to obtain the address in numeric form rather than in text form.

arrowy.gifAbout IP Address Controls

arrowy.gifUsing IP Address Controls

arrowy.gifIP Address Control Reference

About IP Address Controls

Microsoft® Internet Explorer Version 4.0 introduces the IP address control, a new control similar to an edit control that allows the user to enter a numeric address in Internet protocol (IP) format. This format consists of four three-digit fields. Each field is treated individually; the field numbers are zero-based and proceed from left to right as shown in this figure.

The four three-digit fields of an IP address control

The control allows only numeric text to be entered in each of the fields. Once three digits have been entered in a given field, keyboard focus is automatically moved to the next field. If filling the entire field is not required by the application, the user can enter fewer than three digits. For example, if the field should only contain 21, typing 21 and pressing the RIGHT ARROW key will take the user to the next field.

The default range for each field is 0 to 255, but the application can set the range to any values between those limits with the IPM_SETRANGE message.

Note The IP address control is implemented in version 4.71 and later of Comctl32.dll.

Using IP Address Controls

This section describes how to implement an IP address control in your application.

Initializing an IP Address Control

To use an IP address control, call InitCommonControlsEx with the ICC_INTERNET_CLASSES flag set in the dwICC member of the INITCOMMONCONTROLSEX structure.

Creating an IP Address Control

Use the CreateWindow or the CreateWindowEx API to create an IP address control. The class name for the control is WC_IPADDRESS, which is defined in Commctrl.h. No IP address control-specific styles exist; however, because this is a child control, use the WS_CHILD style as a minimum.

Is an IP Address Control an Edit Control?

An IP address control is not an edit control and it will not respond to EM_ messages. It will, however, send the owner window the following edit control notifications through the WM_COMMAND message. Note that the IP address control will also send private IPN_ notifications through the WM_NOTIFY message.

Notification Reason for notification
EN_SETFOCUS Sent when the IP address control gains the keyboard focus.
EN_KILLFOCUS Sent when the IP address control loses the keyboard focus.
EN_CHANGE Sent when any field in the IP address control changes. Like the EN_CHANGE notification from a standard edit control, this notification is received after the screen has been updated.

IP Address Control Reference

This section contains information about the following API elements used with IP address controls.

Messages
IPM_CLEARADDRESS
IPM_GETADDRESS
IPM_ISBLANK
IPM_SETADDRESS
IPM_SETFOCUS
IPM_SETRANGE

Notifications
IPN_FIELDCHANGED

Utility Macros
MAKEIPRANGE
MAKEIPADDRESS
FIRST_IPADDRESS
SECOND_IPADDRESS
THIRD_IPADDRESS
FOURTH_IPADDRESS

Structures
NMIPADDRESS

Messages

This section contains information about the messages used with IP address controls.

IPM_CLEARADDRESS
IPM_CLEARADDRESS
    wParam = 0;
    lParam = 0;

Clears the contents of the IP address control.

Version 4.71

IPM_GETADDRESS
IPM_GETADDRESS
    wParam = 0;
    lParam = (LPARAM)(LPDWORD)pdwAddr;

Retrieves the address values for all four fields in the IP address control.

pdwAddr
Address of a DWORD value that receives the address. The field 3 value will be contained in bits 0 through 7. The field 2 value will be contained in bits 8 through 15. The field 1 value will be contained in bits 16 through 23. The field 0 value will be contained in bits 24 through 31. The FIRST_IPADDRESS, SECOND_IPADDRESS, THIRD_IPADDRESS, and FOURTH_IPADDRESS macros can also be used to extract the address information. Zero will be returned as the address for any blank fields.

Version 4.71

IPM_ISBLANK
IPM_ISBLANK
    wParam = 0;
    lParam = 0;

Determines if all fields in the IP address control are blank.

Version 4.71

IPM_SETADDRESS
IPM_SETADDRESS
    wParam = 0;
    lParam = (LPARAM)(DWORD)dwAddr;

Sets the address values for all four fields in the IP address control.

dwAddr
DWORD value that contains the new address. The field 3 value is contained in bits 0 through 7. The field 2 value is contained in bits 8 through 15. The field 1 value is contained in bits 16 through 23. The field 0 value is contained in bits 24 through 31. The MAKEIPADDRESS macro can also be used to create the address information.

This message does not generate an IPN_FIELDCHANGED notification.

Version 4.71

IPM_SETFOCUS
IPM_SETFOCUS
    wParam = (WPARAM)nField;
    lParam = 0;

Sets the keyboard focus to the specified field in the IP address control. All of the text in that field will be selected.

nField
Zero-based field index to which the focus should be set. If this value is greater than the number of fields, focus is set to the first blank field. If all fields are nonblank, focus is set to the first field.

Version 4.71

IPM_SETRANGE
IPM_SETRANGE
    wParam = (WPARAM)nField;
    lParam = (LPARAM)(WORD)wRange;

Sets the valid range for the specified field in the IP address control.

nField
Zero-based field index to which the range will be applied.
wRange
WORD value that contains the lower limit of the range in the low-order byte and the upper limit in the high-order byte. Both of these values are inclusive. The MAKEIPRANGE macro can also be used to create the range.

If the user enters a value in the field that is outside of this range, the control will send the IPN_FIELDCHANGED notification with the entered value. If the value is still outside of the range after sending the notification, the control will attempt to change the entered value to the closest range limit.

Version 4.71

Notifications

This section contains information about the notification messages sent by IP address controls.

IPN_FIELDCHANGED
IPN_FIELDCHANGED
    lpnmipa = (LPNMIPADDRESS) lParam;

Sent when the user changes a field in the control or moves from one field to another. This notification message is sent in the form of a WM_NOTIFY message.

lpnmipa
Address of an NMIPADDRESS structure that contains information about the changed address. The iValue member of this structure will contain the entered value, even if it is out of the range of the field. You can modify this member to any value that is within the range for the field in response to this notification.

This notification is not sent in response to a IPM_SETADDRESS message.

Version 4.71

Utility Macros

This section contains information about the utility macros used with IP address controls.

MAKEIPRANGE
LPARAM MAKEIPRANGE(
    BYTE low,
    BYTE high
);

Packs two byte values into a single LPARAM suitable for use with the IPM_SETRANGE message.

low
Lower limit of the range.
high
Upper limit of the range.

Version 4.71

MAKEIPADDRESS
LPARAM MAKEIPADDRESS(
    BYTE b0,
    BYTE b1,
    BYTE b2,
    BYTE b3
);

Packs four byte values into a single LPARAM suitable for use with the IPM_SETADDRESS message.

b0
Field 0 address.
b1
Field 1 address.
b2
Field 2 address.
b3
Field 3 address.

Version 4.71

FIRST_IPADDRESS
BYTE FIRST_IPADDRESS(
    LPARAM lParam 
);

Extracts the field 0 value from a packed IP address retrieved with the IPM_GETADDRESS message.

lParam
Packed IP address value.

Version 4.71

SECOND_IPADDRESS
BYTE SECOND_IPADDRESS(
    LPARAM lParam 
);

Extracts the field 1 value from a packed IP address retrieved with the IPM_GETADDRESS message.

lParam
Packed IP address value.

Version 4.71

THIRD_IPADDRESS
BYTE THIRD_IPADDRESS(
    LPARAM lParam 
);

Extracts the field 2 value from a packed IP address retrieved with the IPM_GETADDRESS message.

lParam
Packed IP address value.

Version 4.71

FOURTH_IPADDRESS
BYTE FOURTH_IPADDRESS(
    LPARAM lParam 
);

Extracts the field 3 value from a packed IP address retrieved with the IPM_GETADDRESS message.

lParam
Packed IP address value.

Version 4.71

Structures

This section contains information about the structures used with IP address controls.

NMIPADDRESS
typedef struct tagNMIPADDRESS{
    NMHDR hdr;
    int iField;
    int iValue;
} NMIPADDRESS, *LPNMIPADDRESS;

Contains information for the IPN_FIELDCHANGED notification message.

hdr
NMHDR structure that contains additional information about the notification message.
iField
Zero-based number of the field that was changed.
iValue
New value of the field specified in the iField member. While processing the IPN_FIELDCHANGED notification, this member can be set to any value that is within the range of the field and the control will place this new value in the field.

Version 4.71

© 1997 Microsoft Corporation. All rights reserved. Terms of Use.