Archive: Help ! Writing into an Custom Page Input Box


Help ! Writing into an Custom Page Input Box
Hi,

I have a question regarding writing into an input field of a custom page.

I have a custom page with an input box with the codes as seen below;

var \GLOBAL PORTNO #Global variable to hold the Port Number
Page Custom AddOptionShow AddOptionCheck

Function .onInit

!insermacro MUI_INSTALLOPTIONS_EXTRACT_AS "Forms\AddOption.ini" "AddOps"

FunctionEnd

Function AddOptionShow
!insertmacro MUI_INSTALLOPTIONS_INITDIALOG "AddOps"
!insertmacro MUI_INSTALLOPTIONS_SHOW
FunctionEnd

Function AddOptionCheck
/* Link the function to the AddOption.ini */
!insertmacro MUI_INSTALLOPTIONS_READ $PORTNO "AddOps" "Field 2" "State"

${if} $PORTNO == "" #Empty/Blank Port Number
MessageBox MB_OK "Error: Port Number Must Not be empty !"

/* Write back a default Port Number into the Input Box */
!insertmacro MUI_INSTALLOPTIONS_WRITE "AddOps" "Field 2" "8080"
Abort #Back to the Port page

${else}
MessageBox MB_OK "Success! Port Number entered is: $PORT"
goto END
${endif}

END:
FunctionEnd


Based on the codes above, Function AddOptionShow initializes and displays the custom page. Function AddOptionCheck checks the keyed in Port number. If the Port Number is NULL (Blank field), I would get a returned error message and the installer would enter back a default Port number of "8080" into the Port input field

However, the '!insertmacro MUI_INSTALLOPTIONS_WRITE "AddOps" "Field 2" "8080"' does not seem to write 8080 into the Port Input field.

Is there a way which i could write back into the input box after displaying the error message ?

Thanks very much for any ideas or help.


InstallOptions doesn't read the INI file again when you call Abort in the Leave function. If it did, you'd notice a bit of a pause before the dialog was shown. The dialog is still in memory in the Leave function, so you can modify the dialog with SendMessage.

Examples\InstallOptions\testnotify.nsi is a good example.
Check its Leave function where it uses EnableWindow, SendMessage etc to modify the dialog controls.

-Stu


Hey, You can try like this

!insertmacro MUI_INSTALLOPTIONS_WRITE "AddOps" "Field 2" "State" "8080"

The above will work good.


He was missing "State" yes, but it will still not work. Read my message above.

-Stu


Hi,

Sorry for my late reply. Thanks Afrow on your guide.

I was able to use the SendMessage command in NSIS to actually send back a default Port Number to the specific Input box.

But, I would also like to bring your attention to focus issue for the input box. At the moment, when the custom page loads, I would set focus to the Port Number input box to make it easier for the to directly key in the port number, instead of having to drag the mouse cursor into the input box. The sample code is as shown below;


var \GLOBAL PORTNO #Global variable to hold the Port Number
Page Custom AddOptionShow AddOptionCheck

Function .onInit

!insermacro MUI_INSTALLOPTIONS_EXTRACT_AS "Forms\AddOption.ini" "AddOps"

FunctionEnd

Function AddOptionShow
!insertmacro MUI_INSTALLOPTIONS_INITDIALOG "AddOps"

/* Set Focus for the Port Number field */
Push "$PLUGINSDIR\AddOps"
Push "$R0"
Push "2" #the field number of the Port Number Input Box
Call SetFocus #Function to Set Focus to a specific Input Box
!insertmacro MUI_INSTALLOPTIONS_SHOW
FunctionEnd

Function AddOptionCheck
/* Link the function to the AddOption.ini */
!insertmacro MUI_INSTALLOPTIONS_READ $PORTNO "AddOps" "Field 2" "State"

${if} $PORTNO == "" #Empty/Blank Port Number
MessageBox MB_OK "Error: Port Number Must Not be empty !"

/* Write back a default Port Number and SetFocus into the Input Box */
!insertmacro MUI_INSTALLOPTIONS_READ $R1 "AddOps" "Field 2" "HWND"
SendMessage $R1 ${WM_SETFOCUS} 0 0
SendMessage $R1 ${WM_SETTEXT} 0 "STR:8080"

Abort #Back to the Port page

${else}
MessageBox MB_OK "Success! Port Number entered is: $PORT"
goto END
${endif}

END:
FunctionEnd


From the code above, During the custom page loadup, I have used the SetFocus function to set focus into the InputField of the Port Number (http://nsis.sourceforge.net/Set_Focus_to_a_Control)

Once the Next button is pressed, if the Port Number is empty, the error message would be displayed followed by the SendMessage command to populate the PortNumber Input box with a default value (8080) as well as Set Focus into it. This works, the number 8080 is loaded into the Input box and the cursor has been focused into it. But, I can't seem to type into the Port Number box anymore !

I have tried typing some extra numbers into it, but nothing gets typed into it despite the cursor being focused into the PortNumber input box. If I were to remove the 'SendMessage $R1 ${WM_SETFOCUS} 0 0' command, I could type into the PortNumber Input box.

I am not sure where I have gone wrong. Thanks a million for any available help.


You need a Pop $R0 after
!insertmacro MUI_INSTALLOPTIONS_INITDIALOG
See the usage example on that page.

You may also need to call that function again instead of a basic SendMessage with ${WM_SETFOCUS}.

-Stu