Archive: adding 3rd checkbox


adding 3rd checkbox
how do i add a 3rd checkbox to the finish page?

so far i have this

!define MUI_FINISHPAGE_RUN
!define MUI_FINISHPAGE_RUN_NOTCHECKED
!define MUI_FINISHPAGE_RUN_TEXT "Run Age of Empires Expansion"
!define MUI_FINISHPAGE_RUN_FUNCTION "runfile"
!define MUI_FINISHPAGE_SHOWREADME
!define MUI_FINISHPAGE_SHOWREADME_NOTCHECKED
!define MUI_FINISHPAGE_SHOWREADME_TEXT "Create Desktop Shortcut"
!define MUI_FINISHPAGE_SHOWREADME_FUNCTION "scdesktop"

Function "runfile"
Exec "$INSTDIR\EMPIRESX.EXE"
FunctionEnd

Function "scdesktop"
CreateShortCut "$DESKTOP\Age of Empires Expansion.lnk" "$INSTDIR\EMPIRESX.EXE"
FunctionEnd

You have to change some functions related to the finish page. Put the code below before inserting the macro MUI_PAGE_FINISH:


!define MUI_WELCOMEFINISHPAGE_CUSTOMFUNCTION_INIT InitFinishPage
!define MUI_PAGE_CUSTOMFUNCTION_SHOW ShowFinishPage
!define MUI_PAGE_CUSTOMFUNCTION_LEAVE LeaveFinishPage
The first define is the secret behind the checkbox insertion. "InitFinishPage" is the function to be called when the InstallOptions INI file for the page is written.

Just one more piece of information: The INI file for the page is called "iospecial.ini" and it's located in the $PLUGINSDIR. Also, this page contains 5 controls (with all the options you specified), so all you need to do in this function is:


Function InitFinishPage
!insertmacro MUI_INSTALLOPTIONS_WRITE "ioSpecial.ini" "Settings" "NumFields" "6"
!insertmacro MUI_INSTALLOPTIONS_WRITE "ioSpecial.ini" "Field 6" "Type" "CheckBox"
!insertmacro MUI_INSTALLOPTIONS_WRITE "ioSpecial.ini" "Field 6" "Left" "120"
!insertmacro MUI_INSTALLOPTIONS_WRITE "ioSpecial.ini" "Field 6" "Right" "315"
!insertmacro MUI_INSTALLOPTIONS_WRITE "ioSpecial.ini" "Field 6" "Top" "160"
!insertmacro MUI_INSTALLOPTIONS_WRITE "ioSpecial.ini" "Field 6" "Right" "170"
!insertmacro MUI_INSTALLOPTIONS_WRITE "ioSpecial.ini" "Field 6" "State" "0"
;line above: Initial state of the control: 0=Unchecked, 1=Checked
FunctionEnd
There are still things missing. There is still no repainting of the background of the control to the color white. This you'll do in the "ShowFinishPage" of the page:


Function ShowFinishPage
GetDlgItem $MUI_TEMP1 $MUI_HWND 1205 ;ID for the 6th InstallOptions control
SetCtlColors $MUI_TEMP1 "" "${MUI_BGCOLOR}"
FunctionEnd
The "${MUI_BGCOLOR}" define is the background color of the page, which will be set to white by default. The $MUI_TEMP1 variable is a Modern UI temporary variable, which can be changed if you want to. Also, the $MUI_HWND variable holds the dialog handle for the InstallOptions page, needed for the GetDlgItem to detect the item and paint the background.

One last thing: You need to verify the state of the CheckBox before going out of the page. To do that, use the "LeaveFinishPage" function:


Function LeaveFinishPage
!insertmacro MUI_INSTALLOPTIONS_READ $MUI_TEMP1 "ioSpecial.ini" "Field 6" "State"
StrCmp $MUI_TEMP1 1 Checked Unchecked
Checked:
;Put your code for when the checkbox is checked here
Goto end
Unchecked:
;Put your code for when the checkbox is unchecked here
end:
FunctionEnd
Put the codes to execute when the checkbox is unchecked or checked and all done!

You may have noted the use of !insertmacro MUI_INSTALLOPTIONS_WRITE and !insertmacro MUI_INSTALLOPTIONS_READ. Those are replacements for WriteINIFile and ReadINIFile respectively. The difference is that the file "iospecial.ini" is in $PLUGINSDIR, and these macros write/read only to/from files inside $PLUGINSDIR, so they are made for this occasion.

I didn't test those codes. If they don't work, at least I showed my point...

(EDIT: Just for curiosity, what did you create for Age of Empires? Or are you trying to put back old utilities for it? Hmmm...)

Hi, thanks for the detailed answer, although I'm quite new at this (i've only had nsis for a couple of days). I received the following error

  unknown variable/constant "MUI_HWND" detected, ignoring (D:\My Documents\aoex.nsi:79)


Also, where would I place the text for checkbox? Do I changed "Field 6"?

Many thanks.

I do believe that his piece of code is the only bit not working:

Function ShowFinishPage
GetDlgItem $MUI_TEMP1 $MUI_HWND 1205 ;ID for the 6th InstallOptions control
SetCtlColors $MUI_TEMP1 "" "${MUI_BGCOLOR}"
FunctionEnd


If i set the state manually in the script to 1 it will perform the function I request once I've clicked Finish. It just doesn't seem to be drawing the checkbox onto the page.

Error

 unknown variable/constant "MUI_HWND" detected, ignoring (D:\My Documents\aoex.nsi:79)


(EDIT: Just for curiosity, what did you create for Age of Empires? Or are you trying to put back old utilities for it? Hmmm...)
3rd party apps like CTY Editor, AI Editor, extra campaigns etc

Also, where would I place the text for checkbox? Do I changed "Field 6"?
Whoops, just add this line below to the "InitFinishPage":

!insertmacro MUI_INSTALLOPTIONS_WRITE "ioSpecial.ini" "Field 6" "Text" "Checkbox Text" ;Change this for the text desired
Now for the second error, that wasn't supposed to happen. It is mentioned in the Modern UI documentation that this variable is available in the Show function for this page. Try updating your NSIS to 2.08 if you have an older version.

Originally posted by deguix
Whoops, just add this line below to the "InitFinishPage":

!insertmacro MUI_INSTALLOPTIONS_WRITE "ioSpecial.ini" "Field 6" "Text" "Checkbox Text" ;Change this for the text desired

Yep, I figured that one out :P

Now for the second error, that wasn't supposed to happen. It is mentioned in the Modern UI documentation that this variable is available in the Show function for this page. Try updating your NSIS to 2.08 if you have an older version.
Yes, I have version 2.08 but the error still exists :(

Also, when checking the ioSpecial.ini in the temp folder at runtime, the NumFields value under [Settings] is still set to 5 and not 6

Did you put the functions below the Modern UI settings? Please attach a script that reproduces the problem.


Looks like it is above the page macros.

-Stu


Ok I solved the error, I didn't have a WELCOME page, so I had to insert one

!insertmacro MUI_PAGE_WELCOME
is there any way around that?

Even now that there are no errors, the 3rd checkbox is still not showing up.. I have attached a sample script

Thanks

Move:

!insertmacro MUI_PAGE_FINISH

; Uninstaller pages
!insertmacro MUI_UNPAGE_INSTFILES

Above all the functions and just below:

!define MUI_FINISHPAGE_SHOWREADME_FUNCTION "runfile2"

Edit: and you want this before it too:
!define MUI_WELCOMEFINISHPAGE_CUSTOMFUNCTION_INIT InitFinishPage
!define MUI_PAGE_CUSTOMFUNCTION_SHOW ShowFinishPage
!define MUI_PAGE_CUSTOMFUNCTION_LEAVE LeaveFinishPage

-Stu


The functions have to be after the !insertmacro MUI_PAGE_FINISH because the $MUI_HWND variable is not yet defined before it.

To fix the checkbox not showing correctly, remove the line:


!define MUI_WELCOMEFINISHPAGE_CUSTOMFUNCTION_INIT InitFinishPage


Add this line in its place:

!define MUI_PAGE_CUSTOMFUNCTION_PRE PreFinishPage


And rename the function "InitFinishPage" to "PreFinishPage".

The difference between those 2 defines is that the MUI_WELCOMEFINISHPAGE_CUSTOMFUNCTION_INIT specifies the function which is executed before everything, so future !insertmacro MUI_INSTALLOPTIONS_WRITE macros will overwrite the settings you put, and the MUI_PAGE_CUSTOMFUNCTION_PRE is after the page created the INI file structure.

I'm sure that I've done everything you said above, but the checkbox still is not appearing.

Could you please attach a working, modified version of my testapp.nsi

Thanks.


Ah, it isn't working now because you put a bigger value in the "Top" INI value of the control than the "Bottom" value. The point (0,0) of a dialog is in the top-left corner of it. My first code about the dimensions would make it appear. To make the checkbox placement more natural with the other checkboxes, put the top value as "130" and bottom value as "140".


Thank you! It is now working..

Sorry for being so n00bish :P, thanks for the great support, much appreciated! especially deguix :)