NsDialogs CreateIPaddress: Difference between revisions
m (Reverted edits by 174.36.179.105 to last version by Kichik) |
|||
Line 1: | Line 1: | ||
== 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. | |||
ofer | |||
== Attribution == | == Attribution == |
Revision as of 06:39, 24 October 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. ofer
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
- Main download link: nsDialogs_createIPaddress.zip (688 bytes).
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.)
If you want to do some type of validation on the IP address entered once the control loses focus you will have to get the focus of the current control and compare that to the four hwnds of each of the IP address fields.
You can get each of the fields using:
FindWindow $Field4 "" "" $IPAddressControl FindWindow $Field3 "" "" $IPAddressControl $Field4 FindWindow $Field2 "" "" $IPAddressControl $Field3 FindWindow $Field1 "" "" $IPAddressControl $Field2
You can get the hwnd of the control that currently has focus using:
System::Call "user32::GetFocus(v) i.r0" ; $0 now contains the hwnd
Using this information you can check if, after a notification, one of the 4 IP address fields has focus, or whether focus was lost from all the IP address fields; using LogicLib: <hightlight-nsis> ${Select} $0 ${Case} $Field1 ${Case} $Field2 ${Case} $Field3 ${Case} $Field4 ${Default} ; process here ${EndSelect} </hightlight-nsis>
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
Styling
Note that due to the nature of the control, you can only apply limited styling. For example, changing the background color of the control will result in an incorrectly painted control, while attempts to change the background color of any of the 4 fields will result in a crash.