Skip to content
⌘ NSIS Forum Archive

Add buttons to MUI_PAGE_DIRECTORY, to preset install directory ?

2 posts

Couin#

Add buttons to MUI_PAGE_DIRECTORY, to preset install directory ?

Hi friends,

I'm Couin from France, and I'm customizing an existing installer script 🙂

I would add some buttons to fill install directory with preset paths :


I tried with ButtonEvents plugin and scripts I found there or there (after fixing error I get at compilation), but I get no buttons at all 🙁​​

Is there somewhere I can get a basic example ? I compiled a lot à examples included in NSIS installation dir, but did not found what I search 🙁

Thanks 🙄​​👍​​
Couin#
Hi,

After a lot of hours to search, I can obtain a correct result with this code (note that it concern only buttons ect , the hear title etc. are not in this code). Perhaps it could be useful for who search to do the same thing.
!include nsDialogs.nsh
!include LogicLib.nsh
!include x64.nsh

Name "MyApp"
OutFile "MyApp.exe"
XPStyle on

Var Dialog
Var Label
Var Path
Var Path_State
Var Browse
Var BtnMusic
Var BtnMusic_State
Var BtnDocs
Var BtnDocs_State
Var BtnAppData
Var BtnAppData_State
Var BtnDesktop
Var BtnDesktop_State
Var BtnPrFiles
Var BtnPrFiles_State
Var BtnPrFilesx
Var BtnPrFilesx_State

Page custom nsDialogsPage nsDialogsPageLeave

Function .onInit

StrCpy $Path_State "$PROGRAMFILES\MyApp"
StrCpy $BtnMusic_State "Music"
StrCpy $BtnDocs_State "Documents"
StrCpy $BtnDesktop_State "Windows Desktop"
StrCpy $BtnAppData_State "Application Data"
StrCpy $BtnPrFiles_State "Program Files"
StrCpy $BtnPrFilesx_State "Program Files (x86)"

FunctionEnd

Function nsDialogsPage

nsDialogs::Create 1018
Pop $Dialog

${If} $Dialog == error
Abort
${EndIf}

${NSD_CreateLabel} 0 0 100% 20u "It will install $(^NameDA) blablabla... "
Pop $Label

${NSD_CreateText} 0 23u 214u 11u $Path_State
Pop $Path

${NSD_CreateButton} 216u 22u 50u 12u "Browse..."
Pop $Browse
${NSD_OnClick} $Browse OnClick_Browse

${NSD_CreateLabel} 0 40u 100% 20u "Or click on button to quickly set"
Pop $Label


${NSD_CreateButton} 23u 60u 70u 15u $BtnMusic_State
Pop $BtnMusic
${NSD_OnClick} $BtnMusic BtnMusic_Click

${NSD_CreateButton} 98u 60u 70u 15u $BtnDocs_State
Pop $BtnDocs
${NSD_OnClick} $BtnDocs BtnDocs_Click

${NSD_CreateButton} 173u 60u 70u 15u $BtnDesktop_State
Pop $BtnDesktop
${NSD_OnClick} $BtnDesktop BtnDesktop_Click


${NSD_CreateButton} 23u 80u 70u 15u $BtnAppData_State
Pop $BtnAppData
${NSD_OnClick} $BtnAppData BtnAppData_Click

${NSD_CreateButton} 98u 80u 70u 15u $BtnPrFiles_State
Pop $BtnPrFiles
${NSD_OnClick} $BtnPrFiles BtnPrFiles_Click

${NSD_CreateButton} 173u 80u 70u 15u $BtnPrFilesx_State
Pop $BtnPrFilesx
${NSD_OnClick} $BtnPrFilesx BtnPrFilesx_Click

${If} ${RunningX64}
EnableWindow $BtnPrFilesx 1
${Else}
EnableWindow $BtnPrFilesx 0
${EndIf}

nsDialogs::Show

FunctionEnd

Function nsDialogsPageLeave
${NSD_GetText} $Path $Path_State
MessageBox MB_OK $Path_State
FunctionEnd

Function ReFillPath
${NSD_SetText} $Path $Path_State
FunctionEnd

Function BtnMusic_Click
StrCpy $Path_State "$MUSIC\MyApp"
Call ReFillPath
FunctionEnd

Function BtnDocs_Click
StrCpy $Path_State "$DOCUMENTS\MyApp"
Call ReFillPath
FunctionEnd

Function BtnDesktop_Click
StrCpy $Path_State "$DESKTOP\MyApp"
Call ReFillPath
FunctionEnd

Function BtnAppData_Click
StrCpy $Path_State "$APPDATA\MyApp"
Call ReFillPath
FunctionEnd

Function BtnPrFiles_Click
StrCpy $Path_State "$PROGRAMFILES64\MyApp"
Call ReFillPath
FunctionEnd

Function BtnPrFilesx_Click
StrCpy $Path_State "$PROGRAMFILES\MyApp"
Call ReFillPath
FunctionEnd

Function OnClick_Browse
nsDialogs::SelectFolderDialog /NOUNLOAD "Please select a target directory" $Path_State
Pop $0
${If} $0 == error
Abort
${EndIf}
StrCpy $Path_State $0
Call ReFillPath
FunctionEnd

Page instfiles

Section ""
MessageBox MB_OK "Blablabla"
SectionEnd
Result:
Click image for larger version

Name:	nsdialog.jpg
Views:	111
Size:	21.9 KB
ID:	4630947

Rest to get the needed and available spaces (will open a new thread for that).