我创建了几个自定义页面,如下所示。对于每个页面自定义函数,执行“nsdialog::Create~nsdialog::show”。
并每隔几页调用LoadBannerImage函数 图像放置在每页的固定位置。
我确实lockWindow on~off,但每次我在页面上执行下一个或上一个按钮时,横幅图像都会闪烁并重绘(包括其他控制器也在闪烁)
在低规格虚拟机环境中更加明显。
如何更自然地解决这个现象?
Page custom DisplayWelcomePage
Page custom DisplayInstallationDirPage LeaveInstDirPage
!define MUI_PAGE_CUSTOMFUNCTION_SHOW InstallPage
!insertmacro MUI_PAGE_INSTFILES
Page custom DisplayInstallationFinishPage
;WelcomePage.nsi file
Function DisplayWelcomePage
nsDialogs::Create 1044
Pop $r0
SetCtlColors $r0 0 0xF5F5F5
Push $r0
Call LoadBannerImage
nsDialogs::Show
FuncionEnd
; InstallReadyPage.nsi file
Function DisplayInstallationDirPage
nsDialogs::Create 1044
Pop $r0
SetCtlColors $r0 0 0xF5F5F5
Push $r0
Call LoadBannerImage
nsDialogs::Show
FunctionEnd
Function LoadBannerImage
${NSD_CreateBitmap} 0u 0u 100u 434u ""
Pop $BannerImage
SetCtlColors $BannerImage 0 0xF5F5F5
${NSD_SetBitmap} $BannerImage ${TempBannerFilePath} $8
FunctionEnd
NSIS 页面是主对话框窗口内的一个内部对话框,您创建的任何 NSD 控件都将位于该内部对话框中。控件将在下一页可见之前被销毁,因此闪烁也就不足为奇了。
NSIS 从未被设计为拥有完整的背景图像,但有些人还是这么做了(ExperienceUI、UltraModernUI 和 Graphical Installer)。
如果您坚持自己做,也许可以从在主对话框窗口中添加背景图像开始:
InstallDir $ProgramFiles\MyApp
!define MUI_CUSTOMFUNCTION_GUIINIT myGuiInit
!include MUI2.nsh
!define BMPFILE "bug.bmp"
!define BMPWIDTH 96
!define BMPHEIGHT 96
Var BannerImageControl
Page custom DisplayWelcomePage
Page custom DisplayInstallationDirPage LeaveInstDirPage
!define MUI_PAGE_CUSTOMFUNCTION_SHOW InstallPage
!insertmacro MUI_PAGE_INSTFILES
Page custom DisplayInstallationFinishPage
!insertmacro MUI_LANGUAGE English
!macro ToggleMUIHeader sw
ShowWindow $mui.Header.Text ${sw}
ShowWindow $mui.Header.SubText ${sw}
ShowWindow $mui.Header.Background ${sw}
ShowWindow $mui.Header.Image ${sw}
GetDlgItem $0 $hWndParent 1036
ShowWindow $0 ${sw}
IntOp $0 ${sw} !
ShowWindow $BannerImageControl $0
!macroend
!macro BgPageBegin hWndDlg
!insertmacro ToggleMUIHeader 0
nsDialogs::Create 1044
Pop ${hWndDlg}
SetCtlColors ${hWndDlg} ${MUI_TEXTCOLOR} transparent
!macroend
!macro BgPageShow
nsDialogs::Show
!macroend
Function myGUIInit
InitPluginsDir
File "/oname=$PluginsDir\background.bmp" "${BMPFILE}"
System::Call 'USER32::CreateWindowEx(i0,t"STATIC",p0,i${__NSD_Bitmap_STYLE},i0,i0,i${BMPWIDTH},i${BMPHEIGHT},p$hWndParent,p0,p0,p0)p.r0'
LoadAndSetImage /STRINGID /RESIZETOFITWIDTH $0 0 0x10 "$PluginsDir\background.bmp"
StrCpy $BannerImageControl $0
!insertmacro ToggleMUIHeader 0
FunctionEnd
Function DisplayWelcomePage
!insertmacro BgPageBegin $r0
${NSD_CreateLabel} 10 10u 90% 12u "Hello and welcome to my installer!"
Pop $0
SetCtlColors $0 ${MUI_TEXTCOLOR} transparent
!insertmacro BgPageShow
FunctionEnd
Function DisplayInstallationDirPage
!insertmacro BgPageBegin $r0
${NSD_CreateLabel} 10 0 90% 12u "A directory perhaps?"
Pop $0
SetCtlColors $0 ${MUI_TEXTCOLOR} transparent
${NSD_CreateText} 8u 13u -16u 12u "$InstDir"
Pop $0
!insertmacro BgPageShow
FunctionEnd
Function LeaveInstDirPage
#?
FunctionEnd
Function InstallPage
!insertmacro ToggleMUIHeader 1 ; Make this page look normal
FunctionEnd
Function DisplayInstallationFinishPage
!insertmacro BgPageBegin $r0
${NSD_CreateLabel} 10 10u 90% 12u "Goodbye"
Pop $0
SetCtlColors $0 ${MUI_TEXTCOLOR} transparent
!insertmacro BgPageShow
FunctionEnd
Section
SectionEnd
如果您想要自定义按钮外观,则必须使用 NSIS 皮肤插件之一,不能使用
SetCtlColors
,因为 Windows 不支持自定义按钮颜色。