Home > Software engineering >  Multiple nsDialogs image-icons in one custom NSIS page
Multiple nsDialogs image-icons in one custom NSIS page

Time:12-20

I'm trying to put various images (as icons) in a single custom page using nsDialogs.

This example i provided do that, but it only shows the first image. But if i comment/delete the code for the first image, shows the second one, if i do the same with the second one, it shows the third, and so on.

Screenshot: Custom page with the code provided: Only one icon is shown when are set four with the same code.

For me i am missing something but i have searched for a example of using NSD_CreateIcon/NSD_SetIcon to help with this with any luck. Also i tried to use NSD_CreateBitmap/NSD_SetBitmap instead, but i have the same issue (and i want the icons better because they have transparency).

Here is the code:

Name "Example NSD Icon Test"
Outfile "ExampleNSDiconsTest.exe"

RequestExecutionLevel user
Unicode True
XPStyle on

!include nsDialogs.nsh
!include LogicLib.nsh

Page Custom FirstCreate
Page Custom SecondCreate
Page instfiles

Function .onGuiInit
    InitPluginsDir
    File /oname=$PLUGINSDIR\1.ico "1.ico"
    File /oname=$PLUGINSDIR\2.ico "2.ico"
    File /oname=$PLUGINSDIR\3.ico "3.ico"
    File /oname=$PLUGINSDIR\4.ico "4.ico"
FunctionEnd

Function FirstCreate

    nsDialogs::Create 1018
    
    ${NSD_CreateIcon} 8u 12u 32px 32px
        Pop $1
        ${NSD_SetIcon} $1 "$PLUGINSDIR\1.ico" $R1
    
    ${NSD_CreateIcon} 8u 47u 32px 32px
        Pop $2
        ${NSD_SetIcon} $2 "$PLUGINSDIR\2.ico" $R2
    
    ${NSD_CreateIcon} 8u 60u 32px 32px
        Pop $3
        ${NSD_SetIcon} $3 "$PLUGINSDIR\3.ico" $R3
        
    ${NSD_CreateIcon} 8u 84u 32px 32px
        Pop $4
        ${NSD_SetIcon} $4 "$PLUGINSDIR\4.ico" $R4
    
    nsDialogs::Show
    
FunctionEnd

Function SecondCreate
    nsDialogs::Create 1018
    nsDialogs::Show
FunctionEnd

Section
    
SectionEnd

The full package with the icons and the example can be downloaded here (updated)

Thanks!

Edit:

Doing more testing, i just found that if i create a second custom page using nsDialogs after that first one, totally empty, the first page show only "1", you can go to the second page, go back to the first one, and it shows "1" and "2". I updated everything in this page with the new example.

CodePudding user response:

  1. You are missing a Pop after nsDialogs::Create.
  2. There is no px suffix.
  3. You are missing the last parameter when creating the controls.

RequestExecutionLevel User


!include nsDialogs.nsh

Page Custom FirstCreate

Function .onGUIInit
    InitPluginsDir
    File /oname=$PLUGINSDIR\1.ico "${NSISDIR}\Contrib\Graphics\Icons\llama-blue.ico"
    File /oname=$PLUGINSDIR\2.ico "${NSISDIR}\Contrib\Graphics\Icons\llama-grey.ico"
    File /oname=$PLUGINSDIR\3.ico "${NSISDIR}\Contrib\Graphics\Icons\nsis1-install.ico"
    File /oname=$PLUGINSDIR\4.ico "${NSISDIR}\Contrib\Graphics\Icons\nsis1-uninstall.ico"

FunctionEnd

Function FirstCreate

    nsDialogs::Create 1018
    Pop $0
    
    ${NSD_CreateIcon} 8u 12u 32 32 ""
    Pop $1
    ${NSD_SetIcon} $1 "$PLUGINSDIR\1.ico" $R1
    
    ${NSD_CreateIcon} 8u 47u 32 32 ""
    Pop $2
    ${NSD_SetIcon} $2 "$PLUGINSDIR\2.ico" $R2
    
    ${NSD_CreateIcon} 8u 60u 32 32 ""
    Pop $3
    ${NSD_SetIcon} $3 "$PLUGINSDIR\3.ico" $R3
        
    ${NSD_CreateIcon} 8u 84u 32 32 ""
    Pop $4
    ${NSD_SetIcon} $4 "$PLUGINSDIR\4.ico" $R4
    
    nsDialogs::Show
    ${NSD_FreeIcon} $R1
    ${NSD_FreeIcon} $R2
    ${NSD_FreeIcon} $R3
    ${NSD_FreeIcon} $R4
    
FunctionEnd


Section
SectionEnd
  • Related