NsDialogs CreateIPaddress: Difference between revisions

From NSIS Wiki
Jump to navigationJump to search
(New page: == Description == This header is an extension to the existing nsDialogs.nsh header file, and adds the ability to create IP address controls via a new ${NSD_CreateIPaddress} command. IP ad...)
 
Line 19: Line 19:
== Callbacks ==
== Callbacks ==
The IPaddress control only triggers the '${NSD_OnNotify}' callback.  This callback is triggered in two cases:
The IPaddress control only triggers the '${NSD_OnNotify}' callback.  This callback is triggered in two cases:
   * twice after one part of an IP address is entered (once for the entered text, once again for the next part receiving focus).  To separate the two events, set a temporary variable.
   * twice after one part of an IP address is entered (once for the entered text, once again for<br>the next part receiving focus).  To separate the two events, set a temporary variable.
   * once after the IP address control loses focus (user tabs out, clicks out, etc.)
   * once after the IP address control loses focus (user tabs out, clicks out, etc.)



Revision as of 18:45, 8 February 2009

Description

This header is an extension to the existing nsDialogs.nsh header file, and adds the ability to create IP address controls via a new ${NSD_CreateIPaddress} command. IP address controls look like a standard edit (text) control, but separated logically by 3 dots, where each of the 4 parts only accepts numbers within the range 0 .. 255. An IP address control is the logical choice when requiting IP address input.

Attribution

This header is the result of the forum discussion "nsDialogs IP Address Control" ( http://forums.winamp.com/showthread.php?threadid=302172), and credit goes largely to Xokar and Address for the correct system calls and to the nsDialogs header team for the conventions laid out therein.

Header


MD5: 4173a10b2e6dc13e6b2e512868267d53 | Filesize: 688B

Creating

Although typically the various internet controls may already be initialized on your system, it is a good idea to make sure they are indeed initialized. For the IPaddress control, use ${NSD_InitIPaddress} to initialize the control. If used, this should only be needed once (e.g. in .onGuiInit).

Creating the IPaddress control is as simple as creating any other control, using '${NSD_CreateIPaddress} top left width height ""'. Note that the IP address control does not take any label text and is thus left blank.

Writing

You can set the IP address using the existing '${NSD_SetText}' function. For example: '${NSD_SetText} <control> "192.168.0.0"'. The accepted text must be a valid IP address of format #.#.#.# .

Callbacks

The IPaddress control only triggers the '${NSD_OnNotify}' callback. This callback is triggered in two cases:

  * twice after one part of an IP address is entered (once for the entered text, once again for
the next part receiving focus). To separate the two events, set a temporary variable. * once after the IP address control loses focus (user tabs out, clicks out, etc.)

Reading

To read the IP address entered, you can use the existing '${NSD_GetText} <control> <outvar>' convention. The IP address is returned as a single string of format #.#.#.# . If you need to check pieces of the IP address, you will have to manually separate it into the appropriate pieces using existing string manipulation functions.

Example

outfile 'nsdialogs_createIPaddress.exe'
 
!include 'nsdialogs.nsh'
!include 'nsdialogs_createIPaddress.nsh'
 
Page Custom CustomPre
 
Function CustomPre
	nsDialogs::Create 1018
	Pop $R0
 
	${If} $Dialog == error
		Abort
	${EndIf}
 
 
	${NSD_InitIPaddress}
	Pop $0
	IntCmp $0 0 0 +3 +3
	    MessageBox MB_OK "Something went wrong while initializing the IPaddress control"
	    Abort
 
	${NSD_CreateIPaddress} 5% 90% 30% 12u ""
	Pop $0
 
	nsDialogs::Show
FunctionEnd
 
Section
SectionEnd