使用nsDialogs自定义现有NSIS MUI2页面
我想包括自定义控件来完成页面,这取决于是否设置了IfRebootFlag,但我不知道为什么会创建一些控件但不显示它们 $hWnd是每个添加的控件的一个数字!=0,这意味着所有控件都已创建。控件的位置似乎还可以。。。它肯定不在左边的图像后面,因为左边的坐标足够高,可以将控件置于图像之外 我试了好几个小时,不知道哪一个可能是问题使用nsDialogs自定义现有NSIS MUI2页面,nsis,nsdialogs,Nsis,Nsdialogs,我想包括自定义控件来完成页面,这取决于是否设置了IfRebootFlag,但我不知道为什么会创建一些控件但不显示它们 $hWnd是每个添加的控件的一个数字!=0,这意味着所有控件都已创建。控件的位置似乎还可以。。。它肯定不在左边的图像后面,因为左边的坐标足够高,可以将控件置于图像之外 我试了好几个小时,不知道哪一个可能是问题 ;-------------------------------- ;Header Files !include nsDialogs.nsh !include Logic
;--------------------------------
;Header Files
!include nsDialogs.nsh
!include LogicLib.nsh
!include MUI2.nsh
Name App
OutFile ctmFinishPage.exe
XPStyle on
;--------------------------------
;General
!define MUI_FINISHPAGE_NOREBOOTSUPPORT
;--------------------------------
;Variables
Var hWndChkBoxRunApp
Var hWndChkBoxLinkApp
Var hWndHlineReboot
Var hWndLblReboot
Var hWndRadBtnRebootNow
Var hWndRadBtnRebootLater
Var ctlLeft
Var ctlTop
Var ctlWidht
Var ctlHeight
Var ctlText
;--------------------------------
;Pages
;install pages
!insertmacro MUI_PAGE_INSTFILES
!define MUI_PAGE_CUSTOMFUNCTION_SHOW MyFinishShow
!define MUI_PAGE_CUSTOMFUNCTION_LEAVE MyFinishLeave
!insertmacro MUI_PAGE_FINISH
;--------------------------------
;Languages
!insertmacro MUI_LANGUAGE "English"
;--------------------------------
;Installer Sections
Section
SetRebootFlag true
SectionEnd
;--------------------------------
;Functions
Function MyFinishShow
;add custom Reboot section to Finish page (MUI_FINISHPAGE_NOREBOOTSUPPORT flag is required)
IfRebootFlag 0 noreboot
StrCpy $ctlLeft 120u
StrCpy $ctlWidht 61%
StrCpy $0 50
StrCpy $ctlTop $0u
StrCpy $R0 10
StrCpy $ctlHeight $R0u
StrCpy $ctlText "Create Desktop shortcut"
${NSD_CreateCheckBox} $ctlLeft $ctlTop $ctlWidht $ctlHeight $ctlText
Pop $hWndChkBoxLinkApp
SetCtlColors $hWndChkBoxLinkApp "" "ffffff"
${NSD_SetState} $hWndChkBoxLinkApp ${BST_CHECKED}
StrCpy $1 117
StrCpy $ctlTop $1u
StrCpy $R1 1
StrCpy $ctlHeight $R1u
StrCpy $ctlText ""
${NSD_CreateHLine} $ctlLeft $ctlTop $ctlWidht $ctlHeight $ctlText
Pop $hWndHlineReboot
IntOp $R1 $R1 + 4
IntOp $2 $1 + $R1
StrCpy $ctlTop $2u
StrCpy $R2 25
StrCpy $ctlHeight $R2u
StrCpy $ctlText "Your computer must be restarted in order to complete the installation of App. Do you want to reboot now?"
${NSD_CreateLabel} $ctlLeft $ctlTop $ctlWidht $ctlHeight $ctlText
Pop $hWndLblReboot
SetCtlColors $hWndLblReboot "" "ffffff"
IntOp $R2 $R2 + 8
IntOp $3 $2 + $R2
StrCpy $ctlTop $3u
StrCpy $R3 10
StrCpy $ctlHeight $R3u
StrCpy $ctlText "Reboot now"
${NSD_CreateRadioButton} $ctlLeft $ctlTop $ctlWidht $ctlHeight $ctlText
Pop $hWndRadBtnRebootNow
SetCtlColors $hWndRadBtnRebootNow "" "ffffff"
${NSD_SetState} $hWndRadBtnRebootNow ${BST_CHECKED}
IntOp $R3 $R3 + 9
IntOp $4 $3 + $R3
StrCpy $ctlTop $4u
StrCpy $R4 10
StrCpy $ctlHeight $R4u
StrCpy $ctlText "I want to manually reboot later"
${NSD_CreateRadioButton} $ctlLeft $ctlTop $ctlWidht $ctlHeight $ctlText
Pop $hWndRadBtnRebootLater
SetCtlColors $hWndRadBtnRebootLater "" "ffffff"
${NSD_SetState} $hWndRadBtnRebootLater ${BST_UNCHECKED}
${NSD_OnChange} $hWndChkBoxLinkApp ToggleChkBoxState
${NSD_OnChange} $hWndRadBtnRebootNow ToggleRadBtnState
${NSD_OnChange} $hWndRadBtnRebootLater ToggleRadBtnState
Goto end
noreboot:
StrCpy $ctlLeft 120u
StrCpy $ctlWidht 61%
StrCpy $0 110
StrCpy $ctlTop $0u
StrCpy $R0 10
StrCpy $ctlHeight $R0u
StrCpy $ctlText "Run App"
${NSD_CreateCheckBox} $ctlLeft $ctlTop $ctlWidht $ctlHeight $ctlText
Pop $hWndChkBoxRunApp
SetCtlColors $hWndChkBoxRunApp "" "ffffff"
${NSD_SetState} $hWndChkBoxRunApp ${BST_UNCHECKED}
IntOp $R0 $R0 + 9
IntOp $1 $0 + $R0
StrCpy $ctlTop $1u
StrCpy $R1 10
StrCpy $ctlHeight $R1u
StrCpy $ctlText "Create Desktop"
${NSD_CreateCheckBox} $ctlLeft $ctlTop $ctlWidht $ctlHeight $ctlText
Pop $hWndChkBoxLinkApp
SetCtlColors $hWndChkBoxLinkApp "" "ffffff"
${NSD_SetState} $hWndChkBoxLinkApp ${BST_CHECKED}
${NSD_OnChange} $hWndChkBoxRunApp ToggleChkBoxState
${NSD_OnChange} $hWndChkBoxLinkApp ToggleChkBoxState
end:
FunctionEnd
Function MyFinishLeave
;reboot the PC if radio button for "Reboot Now" option is checked (MUI_FINISHPAGE_NOREBOOTSUPPORT flag needed)
IfRebootFlag 0 noreboot
${NSD_GetState} $hWndChkBoxLinkApp $0
${If} $0 == ${BST_CHECKED}
Call CreateDesktopShortcut
${EndIf}
${NSD_GetState} $hWndRadBtnRebootNow $0
${If} $0 == ${BST_CHECKED}
;Reboot
MessageBox MB_OK "Reboot..."
${EndIf}
Goto end
noreboot:
${NSD_GetState} $hWndChkBoxRunApp $0
${If} $0 == ${BST_CHECKED}
Call LaunchAppFile
${EndIf}
${NSD_GetState} $hWndChkBoxLinkApp $0
${If} $0 == ${BST_CHECKED}
Call CreateDesktopShortcut
${EndIf}
end:
FunctionEnd
Function ToggleChkBoxState
;manage Reboot radio buttons state. If one is checked, the other one is not checked and the other way around
Pop $1 ;$1 = $hWndChkBoxRunApp/LinkApp
${NSD_GetState} $1 $0
${If} $0 == ${BST_CHECKED}
${NSD_SetState} $1 ${BST_UNCHECKED}
${Else}
${NSD_SetState} $1 ${BST_CHECKED}
${EndIf}
FunctionEnd
Function ToggleRadBtnState
;manage Reboot radio buttons state. If one is checked, the other one is not checked and the other way around
Pop $1 ;$1 = $hWndRadBtnRebootNow/Later
${NSD_GetState} $1 $0
${If} $0 == ${BST_CHECKED}
${If} $1 == $hWndRadBtnRebootNow
${NSD_SetState} $hWndRadBtnRebootLater ${BST_UNCHECKED}
${Else}
${NSD_SetState} $hWndRadBtnRebootNow ${BST_UNCHECKED}
${EndIf}
${Else}
${If} $1 == $hWndRadBtnRebootNow
${NSD_SetState} $hWndRadBtnRebootLater ${BST_CHECKED}
${Else}
${NSD_SetState} $hWndRadBtnRebootNow ${BST_CHECKED}
${EndIf}
${EndIf}
FunctionEnd
Function LaunchAppFile
;create a file batch at runtime for launching an excel instance pointing to the App file name
MessageBox MB_OK "App launched at runtime..."
FunctionEnd
Function CreateDesktopShortcut
;create App shortcut on DESKTOP folder with custom icon
MessageBox MB_OK "Desktop Shortcut created..."
FunctionEnd
显示完成页面期间未收到错误消息
编辑:使用User32::SetWindowPos API函数解决,以便修改自定义控件的Z顺序
!define HWND_TOP 0
!define SWP_NOSIZE 0x0001
!define SWP_NOMOVE 0x0002
System::Call "User32::SetWindowPos(i, i, i, i, i, i, i) b ($hWndCtmCtl, ${HWND_TOP}, 0, 0, 0, 0, ${SWP_NOSIZE}|${SWP_NOMOVE})"
$mui.FinishPage.Text
mui静态控件和${mui\u FinishPage\u Text}
文本显示在某些控件的顶部
把它藏起来
Function MyFinishShow
ShowWindow $mui.FinishPage.Text 0
...
或者,如果希望保留文本并在其下查看控件,请将其设置为透明。如果要保留文本,使其不重叠,则必须将复选框向下移动一点
Function MyFinishShow
SetCtlColors $mui.FinishPage.Text "${MUI_TEXTCOLOR}" transparent
...
非常感谢你的建议,今晚我会尽力去做的。无论如何,恢复问题。。。是否可以添加自定义控件,指定它们必须显示在所有其他控件的顶部?(只是为了理解…就像你可以用office suite中的“置于前面”命令一样)子控件的Z顺序往往很脆弱,最好不要重叠控件。“最好不要重叠控件”。。。如果不修改mui.FinishPage.Text窗口的大小,则无法进行简单的修改。自定义控件所需的页面区域与该大小不兼容。我可以通过改变第一个控件的y属性来进行一些试验,直到我有可能选择它。结果。。。mui.FinishPage.Text的窗口高度太大,无法满足我的需要。根据您的建议,我可以尝试调整mui.FinishPage.Text窗口的高度,以使其符合我的需要。您认为如何?您可以在自己的标签控件中使用其文本,也可以在自己的标签控件中使用不同的文本。