How to show the print dilaog to select the option to print when clicked on "print" from the license agreement installer screen using NSIS - nsis

How to show the print dialog to select the option to print when clicked on "print" from the license agreement installer screen using NSIS.
I want to display the below screen when clicked on "Print" from the License agreement screen.
If i use the below command it is directly printing the page without popping up the Print dialog.

There is no built-in support but you can display this common dialog with the system plug-in:
!include LogicLib.nsh
!define /IfNDef PD_HIDEPRINTTOFILE 0x00100000
!define /IfNDef PD_NOSELECTION 0x00000004
!define /IFNDef PD_USEDEVMODECOPIESANDCOLLATE 0x00040000 ; Just one copy
Function ShowPrintDlg
System::Call '*(p0,p$hwndparent,p0,p0,p,i${PD_HIDEPRINTTOFILE}|${PD_NOSELECTION}|${PD_USEDEVMODECOPIESANDCOLLATE},&i2,&i2,&i2,&i2,&i2,p,p,p,p,p0,p0,p0,p0,&l.r0)p.r1'
System::Call '*$1(ir0)'
System::Call 'COMDLG32::PrintDlg(pr1)i.r0'
${If} $0 <> 0
System::Call '*$1(p,p,p.r3,p.r4,t""r2)'
System::Free $1
System::Call 'KERNEL32::GlobalFree(pr3)'
System::Call 'KERNEL32::GlobalLock(pr4)p.r1'
${If} $1 P<> 0
System::Call '*$1(&i2,&i2.r2,&i2,&i2)'
System::Call '*$1(&i$2,&t999.r2)'
System::Call 'KERNEL32::GlobalUnlock(pr1)'
System::Call 'KERNEL32::GlobalFree(pr4)'
${EndIf}
MessageBox mb_ok 'User wants to print to "$2"'
${Else}
System::Free $1
${EndIf}
FunctionEnd
Page InstFiles
Section
Call ShowPrintDlg
SectionEnd

Related

Is there a way to link a part of text in DetailPrint in NSIS script to point to a file?

Example:
DetailPrint "Errors detected running post installation scripts. Click here to view the results."
Clicking on "here" should take user to specific file"
The log window is just a ListView control and it does not support this.
You can display a message to the user:
Section
; Post install steps...
MessageBox MB_YESNO|MB_ICONQUESTION "There was a problem, view results?" /SD IDNO IDNO skipresults
ExecShell "" "$Temp\InstallError.log"
skipresults:
SectionEnd
Or you can display a custom page with a link on it:
!include nsDialogs.nsh
!include LogicLib.nsh
Page Directory
Page InstFiles
Page Custom myPostFailureCreate
Var PostFailure
Function OpenPostReport
ExecShell ...
FunctionEnd
Function myPostFailureCreate
${If} $PostFailure = 0
Abort
${EndIf}
nsDialogs::Create 1018
Pop $0
${NSD_CreateLabel} 5u 0 80% 12u "Install scripts failed!"
Pop $0
${NSD_CreateLink} 5u 13u 80% 12u "View report"
Pop $1
${NSD_OnClick} $1 OpenPostReport
nsDialogs::Show
FunctionEnd
Section
; Post install steps...
${If} ${Errors}
StrCpy $PostFailure 1
${EndIf}
SectionEnd

Add link to Abort page

As a follow-up to this answer, I'm trying to add the link after issuing Abort command, but for some reason it does not appear, no trace of it when viewed in Spy++.
The idea is to add the link above the progress bar, but somehow the macro does not work. Is there a reason for this that I'm missing and is it possible to add that link after calling Abort? I've read somewhere that Abort command can have different effect so I'm guessing this is one of it.
I've tried to make this sample script as concise as best I can and would greatly appreciate any help as I'm still learning NSIS.
!include "MUI2.nsh"
;--------------------------------
;General
ShowInstDetails hide
SetCompressor /SOLID lzma
;Request application privileges for Windows Vista
RequestExecutionLevel user
;--------------------------------
;Interface Configuration
!define MUI_ABORTWARNING
!define MANUAL_DOWNLOAD_TEXT "Automatic download not working? Click here to download manually."
;--------------------------------
;Macros
!macro AddDownloadLink yCoord
FindWindow $0 "#32770" "" $HWNDPARENT ; Find the inner dialog
System::Call 'USER32::CreateWindowEx(i0, t "STATIC", t "${MANUAL_DOWNLOAD_TEXT}", i${WS_CHILD}|${WS_VISIBLE}|${SS_NOTIFY}, i 1, i ${yCoord}, i 500, i 50, p $0, i 0x666, p 0, p 0)p.s'
Pop $0
SetCtlColors $0 0000ff transparent
CreateFont $1 "$(^Font)" "$(^FontSize)" "400" /UNDERLINE
SendMessage $0 ${WM_SETFONT} $1 1
GetFunctionAddress $1 fnLinkClicked
ButtonEvent::AddEventHandler 0x666 $1
!macroend
;--------------------------------
;Pages
!insertmacro MUI_PAGE_INSTFILES
;--------------------------------
;Languages
!insertmacro MUI_LANGUAGE "English"
;--------------------------------
;Installer Sections
Section
Var /global Filename
StrCpy $Filename "test100Mb.db"
Var /global DownloadUrl
StrCpy $DownloadUrl "http://speedtest.ftp.otenet.gr/files/$Filename"
!insertmacro AddDownloadLink 70
inetc::get /caption "Downloading package" $DownloadUrl "$Filename" /end
Pop $R0 ;Get the return value
StrCmp $R0 "OK" 0 dlfailed
Goto quit
dlfailed:
DetailPrint "Download failed: $R0 $DownloadUrl"
SetDetailsView show
Abort
!insertmacro AddDownloadLink 1
quit:
Quit
SectionEnd
Function fnLinkClicked
ExecShell "open" "$DownloadUrl"
FunctionEnd
Abort stops executing the section(s) code, you must do whatever you need to do before calling Abort.
Adding controls in a section can be problematic because it executes on a different thread and windows are tied to the thread that created them. If you need the window to stick around longer than the install thread you can create it as a hidden window in the instfiles page show callback and simply call ShowWindow in the section when you need to display it...

NSIS: How do I allow multiple user choice screens that select the sections to install?

I'm attempting to create an installer that asks the user a series of questions to decide which components to install. Each choice (potentially) influences the available options in later choices (else I would just do a normal components page—I don't want to give the user invalid options).
How do I accomplish such a thing? If I just use the components page, all the options are shown, some combinations of which are completely invalid. I don't want to let the user select those. Is it possible to leave out the components page?
Here's a minimal working example of what I'm trying. (Sorry it's long, I couldn't really simplify the dialog code.)
!include nsDialogs.nsh
!include Sections.nsh
Name "mwe"
OutFile "mwe.exe"
InstallDir C:\mwe
Var hwnd
Var Level1Opt
Page custom SelectLevel1Opt ProcessLevel1
Function SelectLevel1Opt
nsDialogs::Create 1018
pop $hwnd
${NSD_CreateLabel} 0 0 100% 12u "Please select level 1 option"
Pop $hwnd
${NSD_CreateRadioButton} 10% 12u 100% 12u "Level 1 A"
Pop $hwnd
nsDialogs::SetUserData $hwnd "Level 1 A"
${NSD_OnClick} $hwnd SetLevel1
${NSD_CreateRadioButton} 10% 24u 100% 12u "Level 1 B"
Pop $hwnd
nsDialogs::SetUserData $hwnd "Level 1 B"
${NSD_OnClick} $hwnd SetLevel1
nsDialogs::Show
FunctionEnd
Function SetLevel1
Pop $hwnd
nsDialogs::GetUserData $hwnd
Pop $Level1Opt
MessageBox MB_OK "Selected: $Level1Opt"
FunctionEnd
Function ProcessLevel1
${If} $Level1Opt == "Level 1 A"
!insertmacro SelectSection Level1A
${ElseIf} $Level1Opt == "Level 1 B"
!insertmacro SelectSection Level1B
${EndIf}
FunctionEnd
Page directory
Page instfiles
Section ""
MessageBox MB_OK "Common Install"
SectionEnd
Section /o "" Level1A
MessageBox MB_OK "Level 1 A"
SectionEnd
Section /o "" Level1B
MessageBox MB_OK "Level 1 B"
SectionEnd
No matter what I choose, neither Level1A nor Level1B sections get run. The selection from the dialog is correctly detected in the handler and the post function. However, selecting the sections isn't causing them to run. Even if I add a components page, neither of them is selected.
I looked in Selection.nsh, and the example it refers to (one-section.nsi) doesn't really do what I want, because it uses the components page. (I also don't understand quite how it works.)
What am I doing wrong? In what way am I misunderstanding the way NSIS is supposed to work?
As idleberg says, the correct syntax is !insertmacro SelectSection ${Level1A} but you get a warning because the section id is not defined until after its Section instruction in your .nsi. You need to move the functions that use ${Level1A} below the sections in your source code:
!include nsDialogs.nsh
!include Sections.nsh
Page custom SelectLevel1Opt ProcessLevel1
Page instfiles
Section ""
MessageBox MB_OK "Common Install"
SectionEnd
Section /o "a" Level1A
MessageBox MB_OK "Level 1 A"
SectionEnd
Section /o "b" Level1B
MessageBox MB_OK "Level 1 B"
SectionEnd
Var hInnerDialog
Var hL1A
Var hL1B
Function SelectLevel1Opt
nsDialogs::Create 1018
pop $hInnerDialog
${NSD_CreateLabel} 0 0 100% 12u "Please select level 1 option"
Pop $0
${NSD_CreateRadioButton} 10% 12u 100% 12u "Level 1 A"
Pop $hL1A
nsDialogs::SetUserData $hL1A ${Level1A} ; Only used by the generic function
${NSD_CreateRadioButton} 10% 24u 100% 12u "Level 1 B"
Pop $hL1B
nsDialogs::SetUserData $hL1B ${Level1B} ; Only used by the generic function
nsDialogs::Show
FunctionEnd
Function ProcessLevel1
${NSD_GetState} $hL1A $1
${If} $1 <> ${BST_UNCHECKED}
!insertmacro SelectSection ${Level1A}
!insertmacro UnselectSection ${Level1B}
${Else}
!insertmacro SelectSection ${Level1B}
!insertmacro UnselectSection ${Level1A}
${EndIf}
FunctionEnd
The ProcessLevel1 function can also be implemented as a loop if there are many radio buttons:
Function ProcessLevel1
StrCpy $0 ""
loop:
FindWindow $0 "${__NSD_RadioButton_CLASS}" "" $hInnerDialog $0
System::Call "USER32::GetWindowLong(p$0,i${GWL_STYLE})i.r1"
IntOp $1 $1 & ${BS_AUTORADIOBUTTON}
${If} $1 = ${BS_AUTORADIOBUTTON} ; Is it a auto radio button?
nsDialogs::GetUserData $0 ; Get the section id
Pop $2
${NSD_GetState} $0 $1
${If} $1 <> ${BST_UNCHECKED}
!insertmacro SelectSection $2
${Else}
!insertmacro UnselectSection $2
${EndIf}
${EndIf}
IntCmp $0 0 "" loop loop
FunctionEnd

NSIS script + Skip button alignment issue

I am trying NSIS script to add "SKIP" button.
I have tested below code and it works well but when I actually integrate with the main code which is having a screen of option "back" "Next" and "Cancel" button. this skip button is not visible at all, it is in extreme right of cancel button and hardly visible.
How can move this "Skip" button towards left side.
Name BtnTest
Outfile test.exe
Installdir "$temp"
RequestExecutionLevel user
BrandingText " " ;Button covers this text
!include nsDialogs.nsh ;For WS_*
!define MUI_CUSTOMFUNCTION_GUIINIT SKIP
Function SKIP
; You are supposed to use ChangeUI (or MUI_UI) and a modified ui file to add new buttons but this example adds the button at run-time...
GetDlgItem $0 $hwndparent 2 ; Find cancel button
System::Call *(i,i,i,i)i.r1
System::Call 'USER32::GetWindowRect(ir0,ir1)'
System::Call *$1(i.r2,i.r3,i.r4,i.r5)
IntOp $5 $5 - $3 ;height
IntOp $4 $4 - $2 ;width
System::Call 'USER32::ScreenToClient(i$hwndparent,ir1)'
System::Call *$1(i.r2,i.r3)
System::Free $1
IntOp $2 $2 + $4 ;x
IntOp $2 $2 + 8 ;x+padding
System::Call 'USER32::CreateWindowEx(i0,t "Button",t "Click Me",i${WS_CHILD}|${WS_VISIBLE}|${WS_TABSTOP},ir2,ir3,ir4,ir5,i $hwndparent,i 0x666,i0,i0)i.r0'
SendMessage $hwndparent ${WM_GETFONT} 0 0 $1
SendMessage $0 ${WM_SETFONT} $1 1
GetFunctionAddress $0 onmybtnclick
ButtonEvent::AddEventHandler 0x666 $0
FunctionEnd
Function onmybtnclick
MessageBox mb_ok "You clicked me!"
FunctionEnd
Page Directory
Page Instfiles
Section
SectionEnd
And also this button appears on all screen How can I display only in one screen.
Change $2 and $3 before the call to CreateWindowEx to change the button position. You can save the handle to the button in another variable after CreateWindowEx but I just used the Id in this example (0x666).
Name BtnTest
Outfile test.exe
Installdir "$temp"
RequestExecutionLevel user
BrandingText " " ;Button covers this text
!include nsDialogs.nsh ;For WS_*
!define MUI_CUSTOMFUNCTION_GUIINIT SKIP
/**/ !include MUI2.nsh #*/
!ifndef MUI_INCLUDED
Function .onGuiInit
Call SKIP
FunctionEnd
!endif
Function SKIP
; You are supposed to use ChangeUI (or MUI_UI) and a modified ui file to add new buttons but this example adds the button at run-time...
GetDlgItem $0 $hwndparent 2 ; Find cancel button
System::Call *(i,i,i,i)i.r1
System::Call 'USER32::GetWindowRect(ir0,ir1)'
System::Call *$1(i.r2,i.r3,i.r4,i.r5)
IntOp $5 $5 - $3 ;height
IntOp $4 $4 - $2 ;width
System::Call 'USER32::ScreenToClient(i$hwndparent,ir1)'
System::Call *$1(i.r2,i.r3)
System::Free $1
!ifdef MUI_INCLUDED
StrCpy $2 15 ; Whatever you feel looks good
!else
IntOp $2 $2 + $4 ;x
IntOp $2 $2 + 8 ;x+padding
!endif
System::Call 'USER32::CreateWindowEx(i0,t "Button",t "Click Me",i${WS_CHILD}|${WS_VISIBLE}|${WS_TABSTOP},ir2,ir3,ir4,ir5,i $hwndparent,i 0x666,i0,i0)i.r0'
SendMessage $hwndparent ${WM_GETFONT} 0 0 $1
SendMessage $0 ${WM_SETFONT} $1 1
GetFunctionAddress $0 onmybtnclick
ButtonEvent::AddEventHandler 0x666 $0
FunctionEnd
Function onmybtnclick
MessageBox mb_ok "You clicked me!"
FunctionEnd
Function HideIt
GetDlgItem $0 $hwndparent 0x666
ShowWindow $0 0
FunctionEnd
Function ShowIt
GetDlgItem $0 $hwndparent 0x666
ShowWindow $0 1
FunctionEnd
!ifdef MUI_INCLUDED
!define MUI_PAGE_CUSTOMFUNCTION_SHOW HideIt
!insertmacro MUI_PAGE_COMPONENTS
!define MUI_PAGE_CUSTOMFUNCTION_SHOW ShowIt
!insertmacro MUI_PAGE_COMPONENTS
!define MUI_PAGE_CUSTOMFUNCTION_SHOW HideIt
!insertmacro MUI_PAGE_COMPONENTS
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_LANGUAGE English
!else
Page Components "" HideIt
Page Components "" ShowIt
Page Components "" HideIt
Page Instfiles
!endif
Section
SectionEnd

How can I get a finish button after a nsDialogs page

I'm trying to create a post install configuration page in my nsis script using nsDialogs. My script for gathering the input and executing the configuration works however I'm never presented with a finish/close/exit button after I'm done. Currently my pages declaration looks like:
Page directory
Page instfiles
Page custom nsDialogsPage nsDialogsPageLeave
How can I get a finish/exit/done button to show after nsDialogsPageLeave executes?
The classic NSIS UI does not have a finish page, the instfiles page is usually the last page and it will show a "finish button" after all the sections have executed. You can set the text of any button to the same string with SendMessage $hwndButton ${WM_SETTEXT} 0 "STR:$(^CloseBtn)" if you want to provide your own finish page.
Most installers request the required information before the instfiles page, if you cannot do this then you might want to use the Modern UI, it will provide a finish page for you:
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_INSTFILES
Page custom nsDialogsPage nsDialogsPageLeave
!insertmacro MUI_PAGE_FINISH
It was a little unclear to me if you wanted two pages; a input page and then a finish page or a combined input/finish page. A combined page is a little weird but it is possible:
!define AppName "Test"
Name "${AppName}"
Outfile "${AppName} setup.exe"
InstallDir $temp
!include LogicLib.nsh
!include WinMessages.nsh
!include nsDialogs.nsh
Var MyEndConfigPageStage
Page Directory
Page InstFiles
Page Custom MyEndConfigPageCreate MyEndConfigPageLeave /EnableCancel
Function MyEndConfigPageCreate
StrCpy $MyEndConfigPageStage 0
GetDlgItem $0 $hwndparent 1
SendMessage $0 ${WM_SETTEXT} 0 "STR:&Apply"
nsDialogs::Create 1018
Pop $0
${NSD_CreateCheckBox} 0 13u 100% -13u "FooBar"
Pop $1
nsDialogs::Show
FunctionEnd
Function MyEndConfigPageLeave
${If} $MyEndConfigPageStage > 0
Return
${EndIf}
${NSD_GetState} $1 $2
ClearErrors
WriteIniStr "$instdir\settings.ini" Dummy "FooBar" $2
${If} ${Errors}
MessageBox mb_iconstop "Unable to apply settings!"
Abort
${EndIf}
IntOp $MyEndConfigPageStage $MyEndConfigPageStage + 1
GetDlgItem $0 $hwndparent 1
SendMessage $0 ${WM_SETTEXT} 0 "STR:$(^CloseBtn)"
GetDlgItem $0 $hwndparent 2
EnableWindow $0 0 ;Disable cancel
EnableWindow $1 0 ;Disable the checkbox
Abort
FunctionEnd
Section
SectionEnd

Resources