Search code examples
nsis

NSIS Custom Page MessageBox jump to next page


Page Custom ModePageCreate ModePageLeave

Function ModePageLeave
    MessageBox MB_YESNO "Installer is now going to uninstall existing software and reinstall software. Database files will be removed. Please confirm to proceed!" IDYES true IDNO false
        true:
        call silentUninst

        false:
        System::Call 'USER32::PostMessage(i$HWNDPARENT,i0x408,i-1,i0)'
        #Abort
FunctionEnd

I have a custom page and in this I want to show a Message box when user clicks next (next from custom page)

Now on clicking next message box appers and takes confirmation from user. Then if user clicks Yes it should go to next page and if No then it should stay on same custom page.

With this code I am getting the same custom page irrespective of clicking Yes or No. Every time I am sticking to custom page only.


Solution

  • From the documentation:

    The leave-function allows you to force the user to stay on the current page using Abort.

    Your code always executes the false: part.

    You could change it to

    Function ModePageLeave
        MessageBox MB_YESNO "Something?" IDYES true IDNO false
            true:
            call silentUninst
            goto done
    
            false:
            System::Call 'USER32::PostMessage(i$HWNDPARENT,i0x408,i-1,i0)'
            done:
    FunctionEnd
    

    but using the official method is much better:

    Page Components
    Page Custom myPageCreate myPageLeave
    Page Directory
    Page Instfiles
    
    Function myPageCreate
    nsDialogs::Create 1018
    Pop $0
    nsDialogs::Show
    FunctionEnd
    
    Function myPageLeave
    MessageBox MB_YESNO "Something?" IDYES goNext
      Abort ; Stay on page
    goNext:
    FunctionEnd