Archive: Problems on creating new page in NSIS with checkbox etc


Problems on creating new page in NSIS with checkbox etc
I want to insert a new page in the installation which contains two checkbox client version and server version.on clicking client version nothing special happens as of now. But if server version selected then a browse option should come to select a folder(This is not a installation folder). I am finding some difficulties to do this. I have added two checkbox a text box and browse button.In the onchange of checkbox i make browse and textbox.


But now the problem is
I want only one checkbox to be checked at a time.

When server version checked browse option should appear(which works now) ,but if it is unchecked again then that browse option should disappear.(which does not work because i was not able to write code for that)

If i click next on this page and then come back to same page using back then all controls or checkbox i checked should be as it is. But now those browse options will disappear even if server version checkbox is selected(As i have not done proper coding for this also)

So please help me to do all these things. Also help me if there any other method to do the same


; Script generated by the HM NIS Edit Script Wizard.

; HM NIS Edit Wizard helper defines
!define PRODUCT_NAME "My application"
!define PRODUCT_VERSION "1.0"

Var Dialog
Var Text
Var Text_State
Var Checkbox
Var Checkbox1
Var Checkbox_State
Var Checkbox1_State
var /GLOBAL SOURCETEXT
var /global SOURCE
var /global BROWSESOURCE
; MUI 1.67 compatible ------
!include "MUI.nsh"
!include nsDialogs.nsh

; MUI Settings
!define MUI_ABORTWARNING
!define MUI_ICON "${NSISDIR}\Contrib\Graphics\Icons\modern-install.ico"
!define MUI_UNICON "${NSISDIR}\Contrib\Graphics\Icons\modern-uninstall.ico"

; Welcome page
!insertmacro MUI_PAGE_WELCOME
Page custom InstallPageCreate checkinstdir
; Directory page
!insertmacro MUI_PAGE_DIRECTORY
; Instfiles page
!insertmacro MUI_PAGE_INSTFILES
; Finish page
!insertmacro MUI_PAGE_FINISH

; Uninstaller pages
!insertmacro MUI_UNPAGE_INSTFILES

; Language files
!insertmacro MUI_LANGUAGE "English"

; MUI end ------

Name "${PRODUCT_NAME} ${PRODUCT_VERSION}"
OutFile "Setup.exe"
InstallDir "$PROGRAMFILES\My application"
ShowInstDetails show
ShowUnInstDetails show
Var InstallPageDialog
Var InstallPage.DirRequest
Var InstallPage.BrowseButton
Var mui.WelcomePage
Var mui.WelcomePage1
Var mui.WelcomePage.Image1
Var mui.WelcomePage.Title
Var mui.WelcomePage.Text
Var ImageHandle
Var mui.WelcomePage.Title.Font
Var LINK
Var LINK.Font
Var clickinstall
Var mui.WelcomePage.Image.Bitmap
var checked
var checked1
Var CheckBox.Font
var mui.WelcomePage1.Title1
var mui.WelcomePage.Title.Font1
Function InstallPageCreate

nsDialogs::Create 1044
Pop $mui.WelcomePage
nsDialogs::SetRTL $(^RTL)
SetCtlColors $mui.WelcomePage 0xffffff 0xffffff

${NSD_CreateLabel} 120u 70u 140u 14u "Choose the intallation method"
Pop $clickinstall
SetCtlColors $clickinstall "" "ffffff"

${NSD_CreateCheckbox} 120u 90u 100% 10u "&Client version"
Pop $CheckBox
CreateFont $CheckBox.Font "$(^Font)" "08" "500"
SetCtlColors $CheckBox "" "FFFFFF"
SendMessage $CheckBox ${WM_SETFONT} $CheckBox.Font 0
GetFunctionAddress $0 OnCheckbox1
nsDialogs::OnClick $CheckBox $0

${NSD_CreateCheckbox} 120u 100u 100% 10u "&Server version"
Pop $CheckBox1
CreateFont $CheckBox.Font "$(^Font)" "08" "500"
SetCtlColors $CheckBox1 "" "FFFFFF"
SendMessage $CheckBox1 ${WM_SETFONT} $CheckBox.Font 0
GetFunctionAddress $0 OnCheckbox2
nsDialogs::OnClick $CheckBox1 $0

${If} $Checkbox_State == ${BST_CHECKED}
${NSD_Check} $Checkbox
${EndIf}
${If} $Checkbox1_State == ${BST_CHECKED}
${NSD_Check} $Checkbox1
${EndIf}

nsDialogs::Show

;Delete image from memory
${NSD_FreeImage} $mui.WelcomePage.Image.Bitmap

FunctionEnd

Function OnCheckbox2

StrCpy $SOURCE "C:\"


${NSD_CreateText} 120u 120u 80u 12u "$SOURCE"

pop $SOURCETEXT
${NSD_CreateBrowseButton} 280u 120u 35u 14u "Browse"
Pop $InstallPage.BrowseButton
${NSD_OnClick} $InstallPage.BrowseButton Browsesource


FunctionEnd
Function OnCheckbox1


FunctionEnd

Function checkinstdir
${NSD_GetText} $Text $Text_State
${NSD_GetState} $Checkbox $Checkbox_State
${If} $Checkbox_State == ${BST_CHECKED}
strcpy $checked 1
${else}
strcpy $checked 0
${Endif}

${NSD_GetState} $Checkbox1 $Checkbox1_State
${If} $Checkbox1_State == ${BST_CHECKED}
strcpy $checked1 1
${else}
strcpy $checked1 0
${Endif}
FunctionEnd

Function Browsesource
nsDialogs::SelectFolderDialog "Select Source Folder" "c:\"
pop $SOURCE
${NSD_SetText} $SOURCETEXT $SOURCE
FunctionEnd



Section "MainSection" SEC01
SectionEnd



Section -Post

SectionEnd




What you're trying to do might not be possible.

I don't think you can make the Browse button disappear without refreshing the page; to refresh the page, leave the page (Next or Back), and then to return to the page, use Back or Next.


You cannot create elements after the Show command. You need to create all components on the page together, and then hide some of them. In the onclick functions you can then unhide the required components and hide others:
http://nsis.sourceforge.net/Docs/Cha...html#4.9.14.17


Hey I did something like this.

It works almost perfectly.There may be changes required to improve code structure.


Originally posted by MSG
You cannot create elements after the Show command. You need to create all components on the page together, and then hide some of them. In the onclick functions you can then unhide the required components and hide others:
http://nsis.sourceforge.net/Docs/Cha...html#4.9.14.17
Thank you for reply. I have done some changes(see here) . Any suggestions from your side to improve it?

Originally posted by winman2004
Any suggestions from your side to improve it?
Very good, however if one one checkbox must be checked and both checkboxes also must not be checked at the same time, why nor use radio buttons?

Please check my code here. I am facing small problem. If a user click on browse button and in folder browse dialog if he clicks cancel instead of selecting path then control will be set to "error" . How can i handle this? I want user to select path compulsorily if he has selected server installation. How can i do it?


Simply check for a proper path in the $SOURCE variable in your page's leave function.


ok how can i display same custom page in the leave function? If i use a leave function for custom page i will give a message to user that path should be selected or some thing else and then i again want to show same custom page. How can i call custom page from the leave function?


Calling 'abort' in the leave function will make the user stay on that page.


Originally posted by MSG
Calling 'abort' in the leave function will make the user stay on that page.
Thank you. I was able to do it. Can i get windows user list in nsis? I want user to select any one of the windows user account from a list. The list must contain all windows user accounts of PC.

http://nsis.sourceforge.net/User_Man...rate_all_users


I am already using NSD_SetImage to display a image on the custom page. It works properly,but only in my pc where the image exists in path. So to include in setup what should i do? Should i include image file by using 'File' option of nsis or is there any method to do it?

But !define MUI_WELCOMEFINISHPAGE_BITMAP "D:\Icons\Welcome.bmp" in welcome page shows image properly in all pc. But how to include or load image in custom page?