I'm using NSIS to create my own installer, I know we can use the instruction: .define MUI_ICON path_to_icon_file.ico
to set the icon for the installer. But it sets both the title bar icon and the exe file icon. How can I set them separately with different icons?
You usually use the same icon but you can force a different icon if you must:
!define MUI_ICON "${NSISDIR}\Contrib\Graphics\Icons\modern-install.ico" ; Exe icon
!define CUSTOMWINDOWICON "${NSISDIR}\Contrib\Graphics\Icons\win-install.ico"
!define MUI_CUSTOMFUNCTION_GUIINIT SetMyCustomIcon
!include "MUI2.nsh"
!insertmacro MUI_PAGE_WELCOME
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_LANGUAGE "English"
Function SetMyCustomIcon
InitPluginsDir
File "/oname=$PluginsDir\cust.ico" "${CUSTOMWINDOWICON}"
!define /IfNDef LR_LOADFROMFILE 0x10
!define /IfNDef LR_DEFAULTSIZE 0x40
!define /IfNDef WM_SETICON 0x80
System::Call 'USER32::LoadImage(p 0,t "$PluginsDir\cust.ico", i 1, i 16, i 16, i ${LR_LOADFROMFILE})p.r0'
SendMessage $hWndParent ${WM_SETICON} 0 $0
System::Call 'USER32::LoadImage(p 0,t "$PluginsDir\cust.ico", i 1, i 0, i 0, i ${LR_LOADFROMFILE}|${LR_DEFAULTSIZE})p.r0'
SendMessage $hWndParent ${WM_SETICON} 1 $0
FunctionEnd
When NSIS 3.05 comes out you can embed the icon as a resource:
!define CUSTOMWINDOWICON "${NSISDIR}\Contrib\Graphics\Icons\win-install.ico"
!define MUI_CUSTOMFUNCTION_GUIINIT SetMyCustomIcon
...
PEAddResource "${CUSTOMWINDOWICON}" "#Icon" "#1337"
Function SetMyCustomIcon
!define /IfNDef WM_SETICON 0x80
System::Call 'KERNEL32::GetModuleHandle(p0)p.s'
System::Call 'USER32::LoadImage(p s, i 1337, i 1, i 0, i 0, i 0x8040)p.r0'
SendMessage $hWndParent ${WM_SETICON} 1 $0
FunctionEnd
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.