Sending the IPM_SETRANGE method to an IP Address control sets the valid input range. The range restricts which IP address are allowed to be entered in the control. If an out-of-range address is entered, the offending fields are adjusted to fall within range. (To clear the range, set the range of all four fields to 0-255, which is the range for all IP addresses.)
If successful, the message returns a non-zero value. If an error occured, the message returns zero.
None.
Const IPM_SETRANGE = &H467
When the form loads, create an IP Address control and place it in the upper-left corner of the window. Restrict entries to the range 128.10.0.0 to 128.11.255.255. It is not necessary to prepare any controls for this example, since the IP Address control is created programmatically when the form loads.
' This code is licensed according to the terms and conditions listed here.
' Declarations and such needed for the example:
' (Copy them to the (declarations) section of a module.)
Public Type INITCOMMONCONTROLSEX_TYPE
dwSize As Long
dwICC As Long
End Type
Public Declare Function InitCommonControlsEx Lib "comctl32.dll" (lpInitCtrls As _
INITCOMMONCONTROLSEX_TYPE) As Long
Public Const ICC_INTERNET_CLASSES = &H800
Public Declare Function CreateWindowEx Lib "user32.dll" Alias "CreateWindowExA" (ByVal dwExStyle As Long, _
ByVal lpClassName As String, ByVal lpWindowName As String, ByVal dwStyle As Long, ByVal x _
As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hWndParent As Long, _
ByVal hMenu As Long, ByVal hInstance As Long, lpParam As Any) As Long
Public Const WC_IPADDRESS = "SysIPAddress32"
Public Const WS_CHILD = &H40000000
Public Const WS_VISIBLE = &H10000000
Public Declare Function DestroyWindow Lib "user32.dll" (ByVal hWnd As Long) As Long
Public Declare Function SendMessage Lib "user32.dll" Alias "SendMessageA" (ByVal hWnd As Long, ByVal Msg _
As Long, wParam As Any, lParam As Any) As Long
Public Const IPM_SETRANGE = &H467
' Define a useful API macro.
Public Function MAKEIPRANGE (ByVal low As Byte, ByVal high As Byte) As Long
MAKEIPRANGE = low + CLng(high) * &H100
End Function
' *** Place the following code inside the form window. ***
Private hIPControl As Long ' handle to the IP Address control
' When the form is initialized, create an IP Address control in the
' upper-left corner of the form.
Private Sub Form_Initialize()
Dim comctls As INITCOMMONCONTROLSEX_TYPE ' identifies the control to register
Dim retval As Long ' generic return value
' Register the IP Address control window class.
With comctls
.dwSize = Len(comctls)
.dwICC = ICC_INTERNET_CLASSES
End With
retval = InitCommonControlsEx(comctls)
' Create the IP Address control in the corner of the window.
hIPControl = CreateWindowEx(0, WC_IPADDRESS, "", WS_CHILD Or WS_VISIBLE, 0, 0, 125, 20, _
Me.hWnd, 0, App.hInstance, ByVal CLng(0))
' Restrict the range of valid IP address to 128.10.0.0 to 128.11.255.255.
' (We only have to set the first two fields' range, since 0-255 is the default.)
retval = SendMessage(hIPControl, IPM_SETRANGE, ByVal CLng(0), ByVal MAKEIPRANGE(128, 128))
retval = SendMessage(hIPControl, IPM_SETRANGE, ByVal CLng(1), ByVal MAKEIPRANGE(10, 11))
End Sub
' Destroy the IP Address control when the form closes.
Private Sub Form_Unload(Cancel As Integer)
Dim retval As Long ' return value
retval = DestroyWindow(hIPControl)
End Sub
Back to the Message list.
Back to the Reference section.
Last Modified: October 29, 2000
This page is copyright © 2000 Paul Kuliniewicz.
Copyright Information Revised October 29, 2000
Go back to the Windows API Guide home page.
E-mail: vbapi@vbapi.com Send Encrypted E-Mail
This page is at http://www.vbapi.com/ref/i/ipm_setrange.html