Archive: React on on Custom page


React on on Custom page
Hello,

I created a custom page which looks like that:


; Ini file generated by the HM NIS Edit IO designer.
[Settings]
NumFields=6

[Field 1]
Type=Groupbox
Text=Licence
Left=16
Right=227
Top=3
Bottom=78

[Field 2]
Type=RadioButton
Text=Demo
Left=26
Right=102
Top=32
Bottom=42

[Field 3]
Type=RadioButton
Text=Single
Left=26
Right=102
Top=46
Bottom=57

[Field 4]
Type=Text
Left=72
Right=202
Top=60
Bottom=73

[Field 5]
Type=Label
Text=Lizenzcode:
Left=26
Right=70
Top=62
Bottom=70

[Field 6]
Type=RadioButton
Text=Floating
Left=26
Right=102
Top=17
Bottom=27




In my Installer I want that the textfield is only enabled wenn the Radiobutton with Single is clicked.

I tried to change color for test purposes but nothing happend:


!include LogicLib.nsh
Page custom licInfoDlg MyCustomLeave


Function MyCustomLeave
# Get control window handle.
!insertmacro INSTALLOPTIONS_READ $R0 "licInfoDlg.ini" "Field 1" "HWND"
# Check if text has been entered in field 1.
!insertmacro INSTALLOPTIONS_READ $R1 "licInfoDlg.ini" "Field 4" "State"
# Make field background red!
${If} $R1 == ""
SetCtlColors $R1 0x000000 0xFF0000
Abort # Go back to page.
# Reset field colours.
${Else}
SetCtlColors $R1 0x000000 0xFFFFFF
${EndIf}
FunctionEnd


This is of course not the whole code but the main for the Custom Page.
How can I implement that the textfield becomes enabled or disabled when a special Radio button is clicked?

I looked for a tutorial but the one on NSIS Page did not help me.

I hope you can give me an Idea or or a code snippet how to make the script work.

You need to add the notify flag to the radio buttons and then create a callback function to enable/disable the text field.

A good example included with NSIS:
${NSISDIR}\Examples\InstallOptions\testnotify.nsi


Thank you for the tipp. Its a good example script.


Regards


Hi all,

i changed my script to as it is done in the example script.
But the textfield 4 still is not disabled when another radiobutton than the Radiobutton 3 is clicked.

I want to become the field disabled when NOT radiobutton 3 is clicked.

Can someone tell me why it does not function? I do not found the failure. The script can be compiled. So there can not be an syntax error or somethink like that.

Here you can see the code:


; Ini file generated by the HM NIS Edit IO designer.
[Settings]
NumFields=6

[Field 1]
Type=Groupbox
Text=Licence
Left=16
Right=227
Top=3
Bottom=78

[Field 2]
Type=RadioButton
Text=Demo
Left=26
Right=102
Top=32
Bottom=41
Flags=NOTIFY

[Field 3]
Type=RadioButton
Text=Single
Left=26
Right=102
Top=46
Bottom=57
Flags=NOTIFY
State=1

[Field 4]
Type=Text
Left=72
Right=202
Top=60
Bottom=73
Flags=

[Field 5]
Type=Label
Text=Lizenzcode:
Left=26
Right=70
Top=62
Bottom=70

[Field 6]
Type=RadioButton
Text=Floating
Left=26
Right=102
Top=17
Bottom=27
Flags=NOTIFY





The part of the script where the field should be disabled:

Page custom licInfoDlg MyCustomLeave

Function MyCustomLeave
# Get control window handle.
ReadINIStr $0 "licinfodlg.ini" "Settings" "State"
StrCmp $0 3 Single ;


Single:
ReadINIStr $0 "licinfodlg.ini" "Field 3" "State"
ReadINIStr $1 "licinfodlg.ini" "Field 4" "HWND"
EnableWindow $1 $0
ReadINIStr $1 "licinfodlg.ini" "Field 4" "HWND2"
EnableWindow $1 $0

StrCmp $0 0 0 +3

WriteINIStr "licinfodlg.ini" "Field 4" "Flags" "DISABLED"
Goto +2

WriteINIStr "licinfodlg.ini" "Field 4" "Flags" ""
Abort


FunctionEnd



I hope someone can help me.

Hello all,

i modified the code a little bit to test what the cause could be:


Function MyCustomLeave
# Get control window handle.
ReadINIStr $0 "licinfodlg.ini" "Settings" "State"
StrCmp $0 0 done ; Next button?
StrCmp $0 3 Single ; "Install support for X"?


Single:
ReadINIStr $0 "licinfodlg.ini" "Field 3" "State"
ReadINIStr $1 "licinfodlg.ini" "Field 4" "HWND"
EnableWindow $1 $0
ReadINIStr $1 "licinfodlg.ini" "Field 4" "HWND2"
EnableWindow $1 $0

StrCmp $0 0 +2

MessageBox MB_ICONEXCLAMATION|MB_OK "You must select at least one install option!" ;WriteINIStr "licinfodlg.ini" "Field 4" "Flags" "DISABLED"
Abort ;Goto +2

;WriteINIStr "licinfodlg.ini" "Field 4" "Flags" ""
Abort

done:


FunctionEnd

In this case the MessageBox appears

But when I replace the " MessageBox MB_ICONEXCLAMATION|MB_OK "You must select at least one install option!"

with

"WriteINIStr "licinfodlg.ini" "Field 4" "Flags" "DISABLED" "

the field4 is still enabled. What does I have to do to disable the fierld4 when on radiobutton Single is clicked???

EnableWindow should have 2 paramaters: The first is the HWND of the control, the 2nd is a one (1) or zero (0).

Setting the flags is good only for when returning to the page (like if the user goes back, it will remember the state).

Also, use include LogicLib.nsh to make things easier.

Have a look at the attached. (I didn't test, so hopefully, I got it right. But there should be enough comments for you to understand.)

EDIT: Since you already had a radio button with the state set, there would never be a situation in which no selection was made. But, I did add a check to verify that if the 3rd option was checked, it must have something in the box before proceeding.


Hi!

Thank you for the example script.

I have done this now (its not the whole script):


!insertmacro INSTALLOPTIONS_READ $R1 "licInfoDlg.ini" "Settings" "State"
ReadINIStr $2 "licinfodlg.ini" "Field 3" "State"

${If} $1 != 0
ReadINIStr $3 "licinfodlg.ini" "Field 4" "HWND"

${If} $2 = 1
; radio button selected so enable the field
MessageBox MB_OK "radio button selected so enable the field"
WriteINIStr "licinfodlg.ini" "Field 4" "Flags" ""
EnableWindow $3 1
${Else}
; not selected, so disable field
MessageBox MB_OK " ; not selected, so disable field"
WriteINIStr "licinfodlg.ini" "Field 4" "Flags" "DISABLED"
EnableWindow $3 0
${EndIf}


But all the time the message "" ; not selected, so disable field" appears. It means it goes into the ELSE whatever radiobutton I click.
I enabled the NOTIFY flag for all radio buttons but nothing changed.
Any idea?

Use !insertmacro INSTALLOPTIONS_READ/WRITE, not Read/WriteINIStr. You have already done so with the first line!?

Stu


Just to elaborate a bit:

The main difference between using the INSTALLOPTIONS_READ/Write macros and the normal Read/WriteIniStr function are that the read/write macros will read the files from $PLUGINSDIR. Calling like you did will read the INI from whatever the current working directory is (which in your case is probably the same directory that your compiled EXE lives in), which is often NOT the directory that gets used by pages during runtime.

I often just use the normal Read/WriteIniStr functions, but I can see how this may be confusing to others. Afrow's suggestion of using the InstallOptions_Read/Write macros for all page functions leaves less room for error (and should have been my first suggestion.) Sorry for the confusion.


Originally posted by Comperio
Just to elaborate a bit:

The main difference between using the INSTALLOPTIONS_READ/Write macros and the normal Read/WriteIniStr function are that the read/write macros will read the files from $PLUGINSDIR.
Hi,

but I never deploy the $PLUGINSDIR but only the executable file which is compiled from the nsis script.
How can then the INSTALLOPTIONS_READ/Write macros work?

thank you so much that seems to be working great any idea on the start in folder part of the shortcuts properties?

thanks again

sorry posted in wrong place :/


You are supposed to extract your INI file using the INSTALLOPTIONS_EXTRACT macro then those macros will work. It is all described in the InstallOptions readme.

Stu