windowsinstallationnsis

Flicker Phenomenon When Switching NSIS Custom Pages


I created several Custom pages as below. For each page custom function, do 'nsdialog::Create~nsdialog::show'.

And call the LoadBannerImage function every few pages Images are placed in fixed positions on each page.

I did lockWindow on~off, but every time I did next or prev button on the page The banner image is flickering and redrawing (including other controllers also blinking)

It is more visible in low-spec virtual machine environments.

How can I solve this phenomenon more naturally?

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

Solution

  • A NSIS page is a inner dialog inside the main dialog window and any NSD control you create will live inside this inner dialog. The control will be destroyed before the next page is visible so there is no wonder you get flicker.

    NSIS was never designed to have full background images but some people do it anyway (ExperienceUI, UltraModernUI and Graphical Installer).

    If you insist on doing it yourself, perhaps start by having a background image in the main dialog window:

    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
    

    If you want custom looking buttons, you have to use one of the NSIS skinning plug-ins, you cannot use SetCtlColors because Windows does not support custom button colors.