Archive: Add Icons to a custom Page


Add Icons to a custom Page
I have created a custom page (for InstallOptionsEx) that contains among other things two fields for images/icons. I have also added two different icons in my file using a small script that injects the second icon to the header then compresses it with upx (using the --compress-icons=0 flag)
In other words in my NSIS file I have

!define MUI_UI "src\custom_header.exe"
!define MUI_ICON "icons\FirstIcon.ico"
!packhdr "$%TEMP%\exehead.dat" 'header.cmd'

and header.cmd is
"%ProgramFiles%\Resource Hacker\ResHacker.exe" -add "%TEMP%\exehead.dat", "%TEMP%\exehead.dat", "%~dps0icons\SecondIcon.ico" , ICONGROUP,104,
upx --best --compress-icons=0 "%TEMP%\exehead.dat"

Once I initiallize the page both images show FirstIcon.ico.

If I change my .ini file that generates the page, so that it points to the exe containing the icons then I get two different icons on the page, but SecondIcon.ico is displayed as if it was 32x32 extraploated to 128x128.

Is there a way to change any of the images on the page before displaying it? I am not sure how to use, say, {STM_SETICON} or something similar.Something like this:
InstallOptionsEx::initDialog /NOUNLOAD "$PLUGINSDIR\${IniFileName}"
Pop $R1
GetDlgItem $0 $R1 1202
SendMessage $0 ${STM_SETICON} ?? ??

I played around with the ?? using the icon index in my file etc but couldn't get it to work ...

I found a thread that suggested (for a different issue though) to use a system call to LoadIcon, but then I am not sure how to pass the information to the SendMessage command ...

:(
Any ideas?

CF

Not tested, but should work.


!define IMAGE_ICON 1
!define LR_LOADFROMFILE 0x10

...

Pop $R1

System::Call `user32::LoadImage(, t "$PLUGINSDIR\SecondIcon.ico", i ${IMAGE_ICON}, , , i ${LR_LOADFROMFILE}) i.R0`
GetDlgItem $R2 $R1 1202
SendMessage $R2 ${STM_SETICON} $R0 0


-Stu

Thanks for the info Afrow UK :)
I had seen in this thread a similar example but I was trying to get the ico from within my installer, without extracting it. Since it already is allocated as a resource, isn't there a way to tell the window to use that specific resource instead of another one?
CF


I think what I am looking for is something like this:

InstallOptionsEx::initDialog /NOUNLOAD "$PLUGINSDIR\${IniFileName}"
Pop $R1
GetDlgItem $0 $R1 1202
System::Call 'kernel32::GetModuleFileNameA(i 0, t .R0, i 1024) i r1'
System::Call 'kernel32::GetModuleHandleA(t R0)i .r2'
System::Call `user32::LoadImage(i r2, t "1", i ${IMAGE_ICON}, , , ) i.R0`
SendMessage $0 ${STM_SETICON} $R0 0
InstallOptionsEx::Show
which does not work since according to this MSDN page
If the image resource is to be loaded by ordinal, use the MAKEINTRESOURCE macro to convert the image ordinal into a form that can be passed to the LoadImage function.
...

:igor:
CF

Got it :)

!define LR_SHARED       0x8000
define IMAGE_ICON 1
InstallOptionsEx::initDialog /NOUNLOAD "$PLUGINSDIR\${IniFileName}"
Pop $R1
GetDlgItem $0 $R1 1202
System::Call 'kernel32::GetModuleFileNameA(i 0, t .R0, i 1024) i r1'
System::Call 'kernel32::GetModuleHandleA(t R0)i .r2'
System::Call `user32::LoadImage(i r2, i 104, i ${IMAGE_ICON}, , , i ${LR_SHARED}) i.R0`
SendMessage $0 ${STM_SETICON} $R0 0
InstallOptionsEx::Show
Note that 104 is the resource ID that I am using for the second icon inside my installer

CF