Search code examples
nsismodern-uinsdialogs

nsis : How to insert background picture with nsdialog or function in MUI_PAGE_INSTFILES


my code is :

; DIMM_V2 Easy NSIS GUI Script 
!include MUI2.nsh
!define MUI_CUSTOMFUNCTION_GUIINIT dimm_hide
!include "page1.nsdinc"
!include "page2.nsdinc"
!include "page3.nsdinc"
!define MUI_HEADERIMAGE #  need to load custom exe 
!define MUI_UI_HEADERIMAGE ".\dimm_beta_img.exe"  ; dimm 1018 my bmp image ! 
; !define MUI_UI_HEADERIMAGE ".\modern.exe"  ; dimm 1018 my bmp image ! 

; dimm code for switching pages is is inside of pages .nsdinc


Page custom fnc_page1_Show
Page custom fnc_page2_Show
Page custom fnc_page3_Show
 ; Page custom dimm_hide
; !insertmacro MUI_PAGE_WELCOME
; !insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_INSTFILES
; !insertmacro MUI_PAGE_FINISH
!insertmacro MUI_LANGUAGE English
; BringToFront
; Destroy a window.
!macro DestroyWindow HWND IDC
    GetDlgItem $R0 ${HWND} ${IDC}
    System::Call `user32::DestroyWindow(i R0)`
!macroend
; 106 this page is Details Page
Function dimm_hide
; dimm   hide   ; need to hide 1256  /// 1037
!insertmacro DestroyWindow  $HWNDPARENT 1045     # dimm remove line from bottom
!insertmacro DestroyWindow  $HWNDPARENT 1256     # dimm remove line from bottom
!insertmacro DestroyWindow  $HWNDPARENT 1037     # dimm remove line from bottom
!insertmacro DestroyWindow  $HWNDPARENT 1028     # dimm remove line from bottom
FunctionEnd
Section
SectionEnd

Working with the NSIS installer and i want to set a static background image on the MUI_PAGE_INSTFILES page "MUI_PAGE_INSTFILES " thx for any help.

*edit - my others pages are already full bg image, so i want to keep the same designt.

enter image description here

edit -  my others pages are already  full bg image, so i want to keep the same desight .

edit 2 : in this example it is green but it using "commctrl.nsh" and so i dont know how to build all toghether .

code :
!include "MUI2.nsh"
!include "..\CommCtrl.nsh"
Caption "List View"
OutFile example1.exe
 Page custom CreatePage
!insertmacro MUI_LANGUAGE "English"
Section Install
SectionEnd
Function CreatePage
    !insertmacro MUI_HEADER_TEXT "List view control" "A SysListView32 control created by nsDialogs plugin"
  nsDialogs::Create 1018
  Pop $0
  StrCmp $0 error 0 +2
  Abort
  ${NSD_CreateListView} 0u 0u 300u 120u "ListView"
  Pop $1
  SendMessage $1 ${LVM_SETBKCOLOR}     0 0xC7EDCC # green bg for details page
  ; Insert a new item  ${NSD_LV_InsertItem} "hWnd" "iItem" "szText"
  ${NSD_LV_InsertItem} $1 0 "Item 0"
  ${NSD_LV_InsertItem} $1 1 "Item 1"
  nsDialogs::Show
FunctionEnd

Solution

  • You can't use nsDialogs controls on other pages but you can use the image macros:

    RequestExecutionLevel User
    !include "MUI2.nsh"
    !include "WinMessages.nsh"
    !include "nsDialogs.nsh"
    
    !define MUI_PAGE_CUSTOMFUNCTION_SHOW ConfigureInstFilesPage
    !insertmacro MUI_PAGE_INSTFILES
    !insertmacro MUI_LANGUAGE "English"
    
    
    Function ConfigureInstFilesPage
    FindWindow $1 "#32770" "" $HWNDPARENT ; Inner dialog
    System::Call 'USER32::GetClientRect(pr1, @r2)'
    System::Call '*$2(i.r6,i.r7,i.r3,i.r4)'
    ; Tweak $6, $7, $3 and $4 with IntOp and remove ${SS_CENTERIMAGE} if desired
    System::Call 'USER32::CreateWindowEx(i0, t"STATIC", p0, i ${WS_CHILD}|${WS_VISIBLE}|${SS_BITMAP}|${SS_CENTERIMAGE}, ir6, ir7, ir3, ir4, pr1, p0, p0, p0)p.r5'
    File "/OName=$Pluginsdir\ifp.bmp" "${NSISDIR}\Contrib\Graphics\Header\win.bmp"
    ${NSD_SetBitmap} $5 "$Pluginsdir\ifp.bmp" $6
    FunctionEnd 
    
    Section
    Sleep 1234
    SectionEnd
    

    NSIS was never designed to support full background images. The best option is probably to use Graphical Installer but it is possible to hack something up yourself:

    RequestExecutionLevel User
    !include "MUI2.nsh"
    !include "WinMessages.nsh"
    !include "nsDialogs.nsh"
    
    
    #!define MUI_HEADER_TRANSPARENT_TEXT ; Set this if you don't want header text
    !define MUI_TEXTCOLOR 000066
    !define MUI_BGCOLOR 667788
    !define TEXTCOLOR 0x${MUI_TEXTCOLOR}
    #!define BGCOLOR "0x${MUI_BGCOLOR}"
    !define BGCOLOR Transparent ; Setting this to "Transparent" only works partially and requires some hacks...
    
    !define MUI_CUSTOMFUNCTION_GUIINIT GuiInit
    !define MUI_PAGE_CUSTOMFUNCTION_SHOW ConfigureInstFilesPage
    Page custom fnc_page1_Create
    !insertmacro MUI_PAGE_INSTFILES
    Page custom fnc_page1_Create
    !insertmacro MUI_LANGUAGE "English"
    BrandingText " "
    
    Function GuiInit
    GetDlgItem $0 $HWNDPARENT 0x4E8
    ShowWindow $0 0
    GetDlgItem $0 $HWNDPARENT 0x404
    ShowWindow $0 0
    GetDlgItem $0 $HWNDPARENT 0x40b
    ShowWindow $0 0
    GetDlgItem $0 $HWNDPARENT 0x40c
    ShowWindow $0 0
    ShowWindow $mui.Header.Background 0
    ShowWindow $mui.Header.Image 0
    StrCpy $1 $HWNDPARENT
    System::Call 'USER32::GetClientRect(pr1, @r2)'
    System::Call '*$2(i.r6,i.r7,i.r3,i.r4)'
    System::Call 'USER32::CreateWindowEx(i0, t"STATIC", p0, i ${WS_CHILD}|${WS_VISIBLE}|${SS_BITMAP}|${WS_CLIPSIBLINGS}, ir6, ir7, ir3, ir4, pr1, p0, p0, p0)p.r5'
    File "/OName=$Pluginsdir\ifp.bmp" "${NSISDIR}\Contrib\Graphics\Header\win.bmp"
    LoadAndSetImage /STRINGID /RESIZETOFIT $5 0 0x10 "$Pluginsdir\ifp.bmp" $6
    !if ${BGCOLOR} == Transparent
        ${NSD_AddExStyle} $mui.Header.Text ${WS_EX_TRANSPARENT}
        ${NSD_AddExStyle} $mui.Header.SubText ${WS_EX_TRANSPARENT}
    !endif
    FunctionEnd
    
    !macro FixTransparentText
    !if ${BGCOLOR} == Transparent
        System::Call 'USER32::RedrawWindow(p$HWNDPARENT,p0,p0,i4|1|512|128)'
    !endif
    !macroend
    
    !macro PageInit
    SetCtlColors $mui.Header.Text ${TEXTCOLOR} ${BGCOLOR}
    SetCtlColors $mui.Header.SubText ${TEXTCOLOR} ${BGCOLOR}
    FindWindow $1 "#32770" "" $HWNDPARENT ; Inner dialog
    SetCtlColors $1 ${TEXTCOLOR} transparent
    !insertmacro FixTransparentText
    !macroend
    
    
    Function fnc_page1_Create
    nsDialogs::Create 1018
    Pop $0
    ${If} $0 == error
    Abort
    ${EndIf}
    SetCtlColors $0 ${TEXTCOLOR} transparent
    ${NSD_CreateLabel} 0 0 100% 12u "Hello, welcome to nsDialogs!"
    Pop $0
    SetCtlColors $0 ${TEXTCOLOR} transparent
    ${NSD_CreateText} 0 13u 100% 30u "Type something here..."
    Pop $0
    !insertmacro MUI_HEADER_TEXT "Blah" "Blah blah blah"
    !insertmacro PageInit
    nsDialogs::Show
    FunctionEnd
    
    
    Function ConfigureInstFilesPage
    !insertmacro PageInit
    SetCtlColors $mui.InstFilesPage.Text ${TEXTCOLOR} ${BGCOLOR}
    FunctionEnd
    
    
    Section
    DetailPrint Hello
    Sleep 1234
    SectionEnd
    
    Section "-LastSectionToFixRedrawBug"
    !insertmacro MUI_HEADER_TEXT "" ""
    !insertmacro FixTransparentText
    SectionEnd