Old 25th June 2010, 09:04   #1
oldfriend
Member
 
Join Date: May 2008
Location: Ukraine
Posts: 93
Exclamation 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.
oldfriend is offline   Reply With Quote
Old 25th June 2010, 09:54   #2
MSG
Major Dude
 
Join Date: Oct 2006
Posts: 1,892
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.
MSG is offline   Reply With Quote
Old 25th June 2010, 10:00   #3
oldfriend
Member
 
Join Date: May 2008
Location: Ukraine
Posts: 93
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.
oldfriend is offline   Reply With Quote
Old 25th June 2010, 10:48   #4
Afrow UK
Moderator
 
Afrow UK's Avatar
 
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,434
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
Afrow UK is offline   Reply With Quote
Old 25th June 2010, 16:18   #5
oldfriend
Member
 
Join Date: May 2008
Location: Ukraine
Posts: 93
Seems have to place my code here.

Actually it is simple by itself

PHP Code:
        Var /GLOBAL CheckVar1 // Initialized in the .onInit 
        
Var /GLOBAL CheckVar2 // Initialized in the .onInit

Function MyCustomPage
        
${if} $CheckVar1 == "1"
               
ReadINIStr $"$PLUGINSDIR\NewPage.ini" "Field 7" "HWND"
               
EnableWindow $0 1
        
${Else}
               
ReadINIStr $"$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 $"$PLUGINSDIR\NewPage.ini" "Field 1" "State"
        
StrCmp $0 1 checked1 unchecked1

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

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

checkbox2clicked
:
        
ReadINIStr $"$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.
oldfriend is offline   Reply With Quote
Old 25th June 2010, 17:05   #6
Afrow UK
Moderator
 
Afrow UK's Avatar
 
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,434
As I said, use the macro from nsDialogs to check/uncheck dynamically.

Stu
Afrow UK is offline   Reply With Quote
Old 25th June 2010, 17:50   #7
oldfriend
Member
 
Join Date: May 2008
Location: Ukraine
Posts: 93
Solved the problem by modifying Function MyCustomPage

PHP Code:
Function MyCustomPage
        
${if} $CheckVar1 == "1"
               
WriteIniStr $PLUGINSDIR\NewPage.ini "Field 7" "Flags" "Enabled"
        
${Else}
               
WriteIniStr $PLUGINSDIR\NewPage.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.
oldfriend is offline   Reply With Quote
Old 26th June 2010, 13:43   #8
Afrow UK
Moderator
 
Afrow UK's Avatar
 
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,434
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
Afrow UK is offline   Reply With Quote
Old 28th June 2010, 18:01   #9
oldfriend
Member
 
Join Date: May 2008
Location: Ukraine
Posts: 93
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?
oldfriend is offline   Reply With Quote
Old 28th June 2010, 18:35   #10
Afrow UK
Moderator
 
Afrow UK's Avatar
 
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,434
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
Afrow UK is offline   Reply With Quote
Old 28th June 2010, 21:44   #11
oldfriend
Member
 
Join Date: May 2008
Location: Ukraine
Posts: 93
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.
oldfriend is offline   Reply With Quote
Old 29th June 2010, 10:50   #12
Afrow UK
Moderator
 
Afrow UK's Avatar
 
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,434
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
Afrow UK is offline   Reply With Quote
Old 29th June 2010, 21:05   #13
oldfriend
Member
 
Join Date: May 2008
Location: Ukraine
Posts: 93
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.


PHP Code:
VAR /GLOBAL MAIN_CHB /*should be initilized before in the .onInit for example */

Function CustomPage
        
!insertmacro INSTALLOPTIONS_INITDIALOG "CustomPage.ini"

        
${if} $MAIN_CHB == "0"
                 
ReadINIStr $"$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 $"$PLUGINSDIR\CustomPage.ini" "Field 1" "State"
        
StrCmp $0 1 checked1 unchecked1

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

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

        Abort

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

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

        Abort

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

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

unchecked2
:
        
ReadINIStr $"$PLUGINSDIR\CustomPage.ini" "Field 7" "State"
        
StrCpy $Secondary "0"
        
Abort
next
:
        
StrCmp $Main 0 exit install
FunctionEnd 
oldfriend is offline   Reply With Quote
Reply
Go Back   Winamp & Shoutcast Forums > Developer Center > NSIS Discussion

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump