Archive: Check Box on the Custom page


Check Box on the Custom page
  Hello, Guys.

Sorry if such issue have already been discussed. Hope this will help me to get quick solution.

1. Have my own custom page. There are 2 checkboxes there and one depends on another. Everything is simple like a table.

2. If the FIRST one is checked the SECOND is active.
If the FIRST is unchecked the second becomes enabled.

3. I save states of both checkboxes.

And now the problem. If I press NEXT button and then on the following page at once button BACK window that should be disabled appears active again. The same is when I press BACK button on the sane custom page.

Hope described clear :) How to save the states of the checkboxes?

Thank you.


At the page's leave function, save the state to a variable. Then in the page creation code, do something like:

${NSD_CreateCheckBox}
${If} $variable == 1
setstate 1
${Else}
setstate 0
${EndIf}

etc.


Thank you for your answer.

Custom page is made via ini file, so impossible to make changes (I think)

Also would be good to know how to make PRE and LEAVE functions for custom page.


You can add the NOTIFY flag to check boxes. To check/uncheck them you can use the nsDialogs macros. See the Install Options readme for getting their handles. Alternatively, just switch to nsDialogs :)

Edit: pre and leave functions? If you've used Page Custom then you should know it has two parameters (show function and optional leave function). There is no need for a pre function as that is just the show function before calling a ::Show plug-in function.

Stu


Seems have to place my code here.

Actually it is simple by itself


        Var /GLOBAL CheckVar1 // Initialized in the .onInit 

Var /GLOBAL CheckVar2 // Initialized in the .onInit

>Function MyCustomPage
${if} $CheckVar1 == "1"
ReadINIStr $0 "$PLUGINSDIR\NewPage.ini" "Field 7" "HWND"
EnableWindow $0 1
${Else}
ReadINIStr $0 "$PLUGINSDIR\NewPage.ini" "Field 7" "HWND"
EnableWindow $0 0
${EndIf}

!
insertmacro MUI_HEADER_TEXT "Custom Page" "Please select the option you want."
!insertmacro MUI_INSTALLOPTIONS_DISPLAY "NewPage.ini"
>FunctionEnd

>Function PressButton
ReadINIStr $R0 "$PLUGINSDIR\NewPage.ini" "Settings" "State"

StrCmp $R0 1 checkbox1clicked
StrCmp $R0 7 checkbox2clicked
StrCmp $R0 0 next next

checkbox1clicked:
ReadINIStr $0 "$PLUGINSDIR\NewPage.ini" "Field 1" "State"
StrCmp $0 1 checked1 unchecked1

checked1:
StrCpy $CheckVar1 "1"
ReadINIStr $0 "$PLUGINSDIR\NewPage.ini" "Field 7" "HWND"
EnableWindow $0 1
Abort

unchecked1:
StrCpy $CheckVar1 "0"
ReadINIStr $0 "$PLUGINSDIR\NewPage.ini" "Field 7" "HWND"
EnableWindow $0 0

checkbox2clicked:
ReadINIStr $0 "$PLUGINSDIR\NewPage.ini" "Field 7" "State"
StrCmp $0 1 checked2 unchecked2

checked2:
StrCpy $CheckVar2 "1"
Abort

unchecked2:
StrCpy $CheckVar2 "0"
Abort

next:
StrCmp $CheckVar1 0 exit install

install:
BringToFront

>exit:
>FunctionEnd
>
Once again: no problem to save the state of checkboxes. Problem is: How to SET this state when the Custom page is loaded again.

As I said, use the macro from nsDialogs to check/uncheck dynamically.

Stu


Solved the problem by modifying Function MyCustomPage


MyCustomPage

${if} $CheckVar1 == "1"
WriteIniStr $PLUGINSDIRNewPage.ini "Field 7" "Flags" "Enabled"
${Else}
WriteIniStr $PLUGINSDIRNewPage.ini "Field 7" "Flags" "Disabled"
${EndIf}

!
insertmacro MUI_HEADER_TEXT "Custom Page" "Please select the option you want."
!insertmacro MUI_INSTALLOPTIONS_DISPLAY "NewPage.ini"
>FunctionEnd
>
Thanks everybody for help.

Just to explain why your previous code did not work; it was because you needed to place it between INITDIALOG and SHOW rather than before DISPLAY.

Edit: Also sorry for pointing you in the wrong direction (nsDialogs). When you said set the state that implied the check/unchecked state rather than the enabled/disabled state.

Stu


Thanks, Stu. Sorry haven't seen your last answer.

Unfortunately, the problem persists, as my method doesn't work correctly. Disabling checkbox (making it inactive) by WriteIniStr causes next time reading by MUI_INSTALLOPTIONS_DISPLAY a new ini file with actually disabled control (checkbox) and even activating it by EnableWindows does nothing since control doesn't receive notifications.

So problem persists and I still need help.

How to save checkboxes disabled states after quiting and then returning to the custom page?


You want to do both. Write to the INI file and set dynamically. To do it dynamically you have to use InitDialog and Show as I have said already.

Stu


Thanks again, Stu.

Actually I've replaced MUI_INSTALLOPTIONS_DISPLAY with INSTALLOPTIONS_INITDIALOG and INSTALLOPTIONS_SHOW.

But wat is the real difference? As I can see it is impossible to use the in the Page Custome leave function as it causes an error (or quitting installer).

Also from many tests with code and direct change of ini file I don't see any way to change functionality of the control (checkbox in my case) in the Page Custom leave function.

Am I wrong? If so please anybody show me how to do this.


You can change it between InitDialog and Show or in the Leave function. At both times the dialog is in memory. If your code is not working then you are doing something wrong. Perhaps you should just switch to nsDialogs!

Stu


SOLVED! Stu, thank you for your time and patience.

Inattention is the rock on which I've split. Inattention, guys ...

2 checkboxes.
1. If the first one is checked the second one could be checked or unchecked.
2. If the first checkbox unchecked the second is disabled.

The states if checkboxes are saved when the is closed. Actually I have many checkboxes, but adapted it to 1 secondary checkbox.



/*should be initilized before in the .onInit for example */


>Function CustomPage
!insertmacro INSTALLOPTIONS_INITDIALOG "CustomPage.ini"

${if} $MAIN_CHB == "0"
ReadINIStr $0 "$PLUGINSDIR\CustomPage.ini" "Field 7" "HWND"
EnableWindow $0 0
${EndIf}

!insertmacro INSTALLOPTIONS_SHOW
FunctionEnd

>Function CustomPageLeave
ReadINIStr $R0 "$PLUGINSDIR\CustomPage.ini" "Settings" "State"

StrCmp $R0 1 checkbox1clicked
StrCmp $R0 7 checkbox2clicked
StrCmp $R0 0 next next

checkbox1clicked:
ReadINIStr $0 "$PLUGINSDIR\CustomPage.ini" "Field 1" "State"
StrCmp $0 1 checked1 unchecked1

checked1:
StrCpy $Main "1"
StrCpy $Secondary "1"

ReadINIStr $0 "$PLUGINSDIR\CustomPage.ini" "Field 7" "HWND"
SendMessage $0 ${BM_SETCHECK} 1 "0"
EnableWindow $0 1

Abort

unchecked1:
StrCpy $Main "0"
StrCpy $Secondary "0"

ReadINIStr $0 "$PLUGINSDIR\CustomPage.ini" "Field 7" "HWND"
SendMessage $0 ${BM_SETCHECK} 0 "0"
EnableWindow $0 0

Abort

checkbox2clicked:
ReadINIStr $0 "$PLUGINSDIR\CustomPage.ini" "Field 7" "State"
StrCmp $0 1 checked2 unchecked2

checked2:
${If}$Main == "1"
StrCpy $Secondary "1"
${EndIf}
Abort

unchecked2:
ReadINIStr $0 "$PLUGINSDIR\CustomPage.ini" "Field 7" "State"
StrCpy $Secondary "0"
Abort
next:
StrCmp $Main 0 exit install
FunctionEnd
>