简体   繁体   English

当我单击自定义页面右上角的“完成”按钮或关闭按钮时,页面未使用 NSIS 关闭

[英]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).我面临一个奇怪的问题,我添加了一个新的自定义页面 (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.安装软件时,如果出现问题并且安装没有正确完成,它会显示来自 INSTFILES 页面的 MessageBox。 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?).在 Abrupt Page 中,它显示“Finish”按钮,但是当点击“Finish”时,页面没有关闭,而是显示一个弹出消息(你确定要关闭吗?)。 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).因为在这里我使用了两个自定义页面(MyInfoPage 和 MyAbruptPage)。

If I replace the first page (MyInfoPage) with MyAbruptPage.如果我用 MyAbruptPage 替换第一页 (MyInfoPage)。 Then I am not seeing any issue when clicking on "Finish" button in the Abrupt Page.然后,当单击 Abrupt Page 中的“Finish”按钮时,我没有看到任何问题。

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下面是我的 Abrupt 页面代码

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:下面是该部分,从这里消息框弹出并导航到 Abrupt 屏幕:

;!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" ;下面是自定义页面“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!您看到的MessageBox来自您在onAbort函数中自己的代码!

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:要使您的特殊中止页面无需进一步操作即可退出,当您在该页onAbort时,您onAbortonAbort函数中执行任何操作:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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