简体   繁体   中英

When I am clicking on "Finish" button or close button at the top right corner of the custom page, page is not closing using NSIS

I am facing a weird problem, I have added a new custom page (MyAbruptPage). When clicking on "Finish" button or close button at the top right corner of this custom page, page is not closing.

Scenario:

When Installing the software, if something went wrong and installation hasn't done properly it shows a MessageBox from INSTFILES page. Upon click on "OK" on the message box It is navigating to the "Abrupt" page. In the Abrupt Page it is showing "Finish" button, but when clicked on "Finish" the page is not closing instead it is showing a pop-up message (Are you sure you want to close?). Even when i clicked on close button in the top right corner also i am getting the same pop-up message. I don't want that message and the dialog should be closed when clicked on "Finish" button.

Observations:

I am thinking that the problem is due to the sequence of the pages. Because here i have used two custom pages (MyInfoPage, And MyAbruptPage).

If I replace the first page (MyInfoPage) with MyAbruptPage. Then I am not seeing any issue when clicking on "Finish" button in the Abrupt Page.

Below is my code snippet showing pages and its sequence:

Page Custom MyInfoPage   ; First Custom page

!define MUI_PAGE_CUSTOMFUNCTION_SHOW WelShow
!insertmacro MUI_PAGE_WELCOME

!define MUI_PAGE_CUSTOMFUNCTION_SHOW MyLicenseShowCallback
!insertmacro MUI_PAGE_LICENSE

!define MUI_PAGE_CUSTOMFUNCTION_SHOW MyDirectoryShowCallback
!insertmacro MUI_PAGE_DIRECTORY

Page Custom MyAbruptPage    ; Second Custom Page

!define MUI_PAGE_CUSTOMFUNCTION_SHOW AbruptShow
!define MUI_PAGE_CUSTOMFUNCTION_LEAVE AbruptLeave
!insertmacro MUI_PAGE_INSTFILES

!insertmacro MUI_PAGE_FINISH

; Below is my code for the Abrupt page

Function AbruptShow
StrCpy $IsOnAbruptPage 1
GetDlgItem $0 $HWNDPARENT 3
ShowWindow $0 0 
FunctionEnd

Function AbruptLeave
StrCpy $IsOnAbruptPage 0
FunctionEnd

Function MyAbruptPage
${IfThen} $IsOnAbruptPage == "" ${|} Abort ${|}
GetDlgItem $0 $HWNDPARENT 1
ShowWindow $0 0 ; Hide Next button

GetDlgItem $0 $HWNDPARENT 3
ShowWindow $0 0 ; Hide Back button

GetDlgItem $0 $HWNDPARENT 2
${NSD_SetText} $0 "Finish"

nsDialogs::Create 1044
Pop $0
${NSD_CreateLabel} 120u 10u 195u ${MUI_WELCOMEPAGE_TITLE_HEIGHT}u "$(AbruptTitle)"
    Pop $AbruptPageTitle
    ;SetCtlColors $InterruptPageTitle "" "${MUI_BGCOLOR}"
    CreateFont $AbruptPageFont "$(^Font)" "12" "700"
    SendMessage $AbruptPageTitle ${WM_SETFONT} $AbruptPageFont 0

 ${NSD_CreateLabel} 120u ${MUI_WELCOMEPAGE_TEXT_TOP}u 195u 130u "$(AbruptText)"
    Pop $AbruptPageText
 Pop $0

nsDialogs::Show
${NSD_FreeImage} $ImageHandle
FunctionEnd

Below is the section and from here Message box is popping up and navigating to the Abrupt screen:

;!insertmacro MUI_LANGUAGE "English" 

Section MySection

SetOutPath $INSTDIR

MessageBox MB_OK|MB_ICONEXCLAMATION "Installation hasn't done properly" IDOK

Call AbruptLeave
        SendMessage $HWNDPARENT 0x408 -1 ""
        Abort 

SectionEnd

;Below is the code for the custompage "MyInfoPage"

Function MyInfoPage

${IfThen} $PageId == "" ${|} Abort ${|}
StrCpy $PageId 0
GetDlgItem $0 $HWNDPARENT 1
ShowWindow $0 0 ; Hide Next button
GetDlgItem $0 $HWNDPARENT 2
${NSD_SetText} $0 "Finish"

nsDialogs::Create 1044
Pop $0

${NSD_CreateLabel} 120u 10u 195u ${MUI_WELCOMEPAGE_TITLE_HEIGHT}u "$(InterruptTitle)"
Pop $InterruptPageTitle   

${NSD_CreateLabel} 120u ${MUI_WELCOMEPAGE_TEXT_TOP}u 195u 130u "$(InterruptText)"
Pop $InterruptPageText

nsDialogs::Show
${NSD_FreeImage} $ImageHandle
FunctionEnd

Function WelShow
StrCpy $PageId 1
GetDlgItem $0 $HWNDPARENT 3
ShowWindow $0 0 ; Hide Back button
FunctionEnd

Function onAbort
${If} $PageId <> 0
    ${If} ${Cmd} ` MessageBox MB_YESNO "Are you sure you want to close?" IDYES `
        SendMessage $HWNDPARENT 0x408 -$PageId ""
    ${EndIf}
    Abort
${EndIf}
FunctionEnd

I have tried by changing the sequence of the pages and every time I am observing different behaviors in both the custom pages. Please help me how to resolve this issue? And the correct way to implement this functionality.

Thank you in advance...

Below is the complete code and it is compiling:

Var PageId
Var PrintBtn
Var Image
Var ImageHandle

Var MyInfoPageTitle
Var MyInfoPageFont
var MyInfoPageText
var IsOnAbruptPage
Var AbruptPageTitle
Var AbruptPageFont
var AbruptPageText

!define MUI_CUSTOMFUNCTION_ABORT onAbort

!include "MUI2.nsh"
!include x64.nsh

Name "MyApp"

OutFile "MyApp.exe"

InstallDir "$PROGRAMFILES32\MyApp"

InstallDirRegKey HKLM "Software\MyApp" "Install_Dir"

RequestExecutionLevel admin

!include LogicLib.nsh

;--------------------------------

Page Custom MyInfoPage


  !define MUI_PAGE_CUSTOMFUNCTION_SHOW WelShow

  !define MUI_TEXT_WELCOME_INFO_TITLE $(welcometitle)
  !define MUI_TEXT_WELCOME_INFO_TEXT $(welcometext)

  !insertmacro MUI_PAGE_WELCOME
  
  !define MUI_PAGE_CUSTOMFUNCTION_SHOW MyLicenseShowCallback

  !define MUI_LICENSEPAGE_CHECKBOX ""
  !define MUI_INNERTEXT_LICENSE_BOTTOM ""
  !define MUI_INNERTEXT_LICENSE_TOP ""
  !define MUI_INNERTEXT_LICENSE_BOTTOM_CHECKBOX ""
  
  !define MUI_TEXT_LICENSE_TITLE $(licensetitle)
  !define MUI_TEXT_LICENSE_SUBTITLE $(licensesubtitle)
  !define MUI_LICENSEPAGE_CHECKBOX_TEXT $(licensecheckboxtext)
  
  !insertmacro MUI_PAGE_LICENSE "C:\Program Files (x86)\NSIS\Docs\Modern UI 2\license.txt"

 !define MUI_PAGE_CUSTOMFUNCTION_SHOW MyDirectoryShowCallback
 
!define MUI_DIRECTORYPAGE_TEXT_TOP $(mydirtoptext)
!define MUI_TEXT_DIRECTORY_TITLE $(mydirtitle)
!define MUI_TEXT_DIRECTORY_SUBTITLE $(mydirsubtitle)

  !insertmacro MUI_PAGE_DIRECTORY
  
  Page Custom MyAbruptPage   

!define MUI_PAGE_CUSTOMFUNCTION_SHOW AbruptShow
!define MUI_PAGE_CUSTOMFUNCTION_LEAVE AbruptLeave


  !insertmacro MUI_PAGE_INSTFILES
   
  !define MUI_TEXT_FINISH_INFO_TITLE $(Finishpagetitle)
  !define MUI_TEXT_FINISH_INFO_TEXT $(Finishpagesubtitle)

  !define MUI_FINISHPAGE_RUN ""
  !define MUI_FINISHPAGE_RUN_TEXT $(FinishonlineReg)

  !insertmacro MUI_PAGE_FINISH

  !insertmacro MUI_UNPAGE_INSTFILES
  
 ;--------------------------------
  !insertmacro MUI_LANGUAGE "English" 

Function .onInit
InitPluginsDir

FunctionEnd
Function MyDirectoryShowCallback
StrCpy $PageId 3

GetDlgItem $0 $hwndparent 1 ; 
SendMessage $0 ${WM_SETTEXT} 0 `STR:$(^NextBtn)`
FunctionEnd

Function MyLicenseShowCallback

StrCpy $PageId 2

GetDlgItem $0 $hwndparent 2 
System::Call *(i,i,i,i)p.r1
System::Call 'USER32::GetWindowRect(pr0,pr1)'
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(p$hwndparent,pr1)'
System::Call *$1(i.r2,i.r3)
System::Free $1
IntOp $2 $4 / 5
System::Call 'USER32::CreateWindowEx(i 0,t "Button",t "Print",i ${WS_CHILD}|${WS_VISIBLE}|${WS_TABSTOP},i r2,i r3,i r4,i r5,p $hwndparent,p 0x666,p 0,p 0)p.r0'
StrCpy $PrintBtn $0
SendMessage $hwndparent ${WM_GETFONT} 0 0 $1
SendMessage $0 ${WM_SETFONT} $1 1
ButtonEvent::AddEventHandler 0x666 $0
FunctionEnd

Function WelShow
StrCpy $PageId 1
GetDlgItem $0 $HWNDPARENT 3
ShowWindow $0 0 
FunctionEnd

Function MyInfoPage
${IfThen} $PageId == "" ${|} Abort ${|}
StrCpy $PageId 0
GetDlgItem $0 $HWNDPARENT 1
ShowWindow $0 0 
GetDlgItem $0 $HWNDPARENT 2
${NSD_SetText} $0 "Finish"

nsDialogs::Create 1044
Pop $0

!define MUI_WELCOMEPAGE_TITLE_HEIGHT 38
!define /math MUI_WELCOMEPAGE_TEXT_TOP 17 + ${MUI_WELCOMEPAGE_TITLE_HEIGHT}

${NSD_CreateLabel} 120u 10u 195u 28u "Setup Wizard was interrupted"

    Pop $MyInfoPageTitle
    CreateFont $MyInfoPageFont "$(^Font)" "12" "700"
    SendMessage $MyInfoPageTitle ${WM_SETFONT} $MyInfoPageFont 0
     ${NSD_CreateLabel} 120u ${MUI_WELCOMEPAGE_TEXT_TOP}u 195u 130u "Setup Wizard was interrupted"
    Pop $MyInfoPageText

Pop $0

nsDialogs::Show
${NSD_FreeImage} $ImageHandle
FunctionEnd

Function onAbort
${If} $PageId <> 0
    ${If} ${Cmd} ` MessageBox MB_YESNO "Are you sure you want to CANCEL" IDYES `
        SendMessage $HWNDPARENT 0x408 -$PageId ""
    ${EndIf}
    Abort
${EndIf}
FunctionEnd


Function AbruptShow
StrCpy $IsOnAbruptPage 1
GetDlgItem $0 $HWNDPARENT 3
ShowWindow $0 0 
FunctionEnd

Function AbruptLeave
StrCpy $IsOnAbruptPage 0
FunctionEnd

Function MyAbruptPage
${IfThen} $IsOnAbruptPage == "" ${|} Abort ${|}
GetDlgItem $0 $HWNDPARENT 1
ShowWindow $0 0 

GetDlgItem $0 $HWNDPARENT 3
ShowWindow $0 0 

GetDlgItem $0 $HWNDPARENT 2

${NSD_SetText} $0 "Finish"

nsDialogs::Create 1044
Pop $0

${NSD_CreateLabel} 120u 10u 195u ${MUI_WELCOMEPAGE_TITLE_HEIGHT}u "Setup Wizard ended prematurely"
    Pop $AbruptPageTitle

    CreateFont $AbruptPageFont "$(^Font)" "12" "700"
    SendMessage $AbruptPageTitle ${WM_SETFONT} $AbruptPageFont 0

 ${NSD_CreateLabel} 120u ${MUI_WELCOMEPAGE_TEXT_TOP}u 195u 130u "Setup Wizard ended prematurely"
    Pop $AbruptPageText
 Pop $0

nsDialogs::Show
${NSD_FreeImage} $ImageHandle
FunctionEnd


  SectionIn RO

SetOutPath $INSTDIR

MessageBox MB_OK|MB_ICONEXCLAMATION "There is an installation failure. Aborting the installation process" IDOK

Call AbruptLeave
        SendMessage $HWNDPARENT 0x408 -1 ""
        Abort

SectionEnd
  
Section "Uninstall"

SectionEnd

The MessageBox you see is coming from your own code in your onAbort function!

The fact that you are doing

!define MUI_PAGE_CUSTOMFUNCTION_SHOW AbruptShow
!define MUI_PAGE_CUSTOMFUNCTION_LEAVE AbruptLeave

shows that you have don't understand how custom pages work.

To make your special abort page quit without further action you simple have to do nothing in your onAbort function when you are on that page:

Var PageId
var IsOnAbruptPage
!define MUI_CUSTOMFUNCTION_ABORT onAbort
!include "MUI2.nsh"
!include LogicLib.nsh
Name "MyApp"

#OutFile "MyApp.exe"
InstallDir "$temp\MyApp"
#RequestExecutionLevel admin
OutFile Test.exe
RequestExecutionLevel user


;--------------------------------
Page Custom MyInfoPage
!define MUI_PAGE_CUSTOMFUNCTION_SHOW WelShow
!insertmacro MUI_PAGE_WELCOME
!define MUI_PAGE_CUSTOMFUNCTION_SHOW MyLicenseShowCallback
!insertmacro MUI_PAGE_LICENSE "${__FILE__}"
!define MUI_PAGE_CUSTOMFUNCTION_SHOW MyDirectoryShowCallback
!insertmacro MUI_PAGE_DIRECTORY
Page Custom MyAbruptPage 
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_PAGE_FINISH
;--------------------------------
!insertmacro MUI_LANGUAGE "English" 

Function MyDirectoryShowCallback
StrCpy $PageId 3
GetDlgItem $0 $hwndparent 1 ; 
SendMessage $0 ${WM_SETTEXT} 0 `STR:$(^NextBtn)`
FunctionEnd

Function MyLicenseShowCallback
StrCpy $PageId 2
FunctionEnd

Function WelShow
StrCpy $PageId 1
GetDlgItem $0 $HWNDPARENT 3
ShowWindow $0 0 
FunctionEnd


Function MyInfoPage
${IfThen} $PageId == "" ${|} Abort ${|}
StrCpy $PageId 0
GetDlgItem $0 $HWNDPARENT 1
ShowWindow $0 0 
GetDlgItem $0 $HWNDPARENT 2
${NSD_SetText} $0 "Finish"
nsDialogs::Create 1044
Pop $0
${NSD_CreateLabel} 120u 10u 195u 28u "Setup Wizard was interrupted"
Pop $0
nsDialogs::Show
FunctionEnd

Function onAbort
${If} $IsOnAbruptPage <> 0 ; If on aborted page
    Return                 ; allow simple exit
${EndIf}
${If} $PageId <> 0
    ${If} ${Cmd} ` MessageBox MB_YESNO "Are you sure you want to CANCEL" IDYES `
        SendMessage $HWNDPARENT 0x408 -$PageId ""
    ${EndIf}
    Abort
${EndIf}
FunctionEnd

Function GoToAbruptPage
StrCpy $IsOnAbruptPage 1
SendMessage $HWNDPARENT 0x408 -1 ""
Abort
FunctionEnd

Function MyAbruptPage
${IfThen} $IsOnAbruptPage == "" ${|} Abort ${|}
GetDlgItem $0 $HWNDPARENT 1
ShowWindow $0 0 
GetDlgItem $0 $HWNDPARENT 3
ShowWindow $0 0 
GetDlgItem $0 $HWNDPARENT 2
${NSD_SetText} $0 "Finish"
nsDialogs::Create 1044
Pop $0
${NSD_CreateLabel} 120u 10u 195u 20u "Setup Wizard ended prematurely"
Pop $0
${NSD_CreateLabel} 120u 120u 195u 20u "Setup Wizard ended prematurely"
Pop $0
nsDialogs::Show
FunctionEnd

;--------------------------------
Section "$(^Name) (required)"
SectionIn RO
SetOutPath $INSTDIR

MessageBox MB_OK|MB_ICONEXCLAMATION "There is an installation failure. Aborting the installation process" IDOK
Call GoToAbruptPage
SectionEnd

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM