installationnsisnsis-mui

NSIS: How to get a finish- and a next-button?


I use the MUI_PAGE_INSTFILES. And this page has normally a finish-button, but I have a custom page after it. But I want that you could still finish the installer before the custom page and the next page is only optional. I could also show more code if wished.

!include "MUI2.nsh"

!insertmacro MUI_PAGE_LICENSE $(license)
!insertmacro MUI_PAGE_INSTFILES
Page custom TestSettings

At the moment I have a previous-, next- and cancel-button at the instfile page. But I want a prev-, next- and finish-button.


Solution

  • NSIS was never designed to support this but with the ButtonEvent plug-in you can make it work. I'm just not sure if it makes sense because if the last page is important then some users might skip the page by accident because they are not paying attention.

    !include MUI2.nsh
    !insertmacro MUI_PAGE_LICENSE $(license)
    !define MUI_PAGE_CUSTOMFUNCTION_LEAVE InstFilesLeave
    !insertmacro MUI_PAGE_INSTFILES
    Page custom TestSettings
    !insertmacro MUI_LANGUAGE English
    
    !include WinMessages.nsh
    !include nsDialogs.nsh
    
    Function InstFilesLeave
    GetDlgItem $0 $hWndParent 2
    ShowWindow $0 0
    System::Call 'USER32::GetWindowRect(pr0,@r1)' ; NSIS 3+
    System::Call 'USER32::MapWindowPoints(p0,p $hWndParent, p $1, i 2)'
    System::Call '*$1(i.r2,i.r3,i.r4,i.r5)'
    IntOp $4 $4 - $2
    IntOp $5 $5 - $3
    !define IDC_MYFINISHBTN 1337
    System::Call 'USER32::CreateWindowEx(i 0, t "BUTTON", t "&Finish", i ${DEFAULT_STYLES}|${WS_TABSTOP}, ir2, ir3, i r4, i r5, p $hWndParent, p ${IDC_MYFINISHBTN}, p 0, p 0)p.r1'
    SendMessage $0 ${WM_GETFONT} "" "" $0
    SendMessage $1 ${WM_SETFONT} $0 1
    GetFunctionAddress $0 OnFinishButton
    ButtonEvent::AddEventHandler ${IDC_MYFINISHBTN} $0
    FunctionEnd
    
    Var JustFinish
    
    Function OnFinishButton
    StrCpy $JustFinish 1
    SendMessage $hWndParent ${WM_COMMAND} 1 ""
    FunctionEnd
    
    Function TestSettings
    StrCmp $JustFinish "" +2
        Return
    GetDlgItem $0 $hWndParent ${IDC_MYFINISHBTN}
    ShowWindow $0 0
    GetDlgItem $0 $hWndParent 2
    ShowWindow $0 1
    !insertmacro MUI_HEADER_TEXT "Configure" "Blah blah blah"
    nsDialogs::Create 1018
    Pop $0
    ; ...
    nsDialogs::Show
    FunctionEnd
    

    If your custom page just contains a couple of checkboxes then you can use the MUI Finish page with custom texts instead.