繁体   English   中英

使用 NSIS 创建安装程序时,如何为 exe 文件指定一个不同于标题栏图标的图标?

[英]How to specify an icon for exe file which is different from the title bar icon when using NSIS to create an installer?

我正在使用 NSIS 创建我自己的安装程序,我知道我们可以使用指令: .define MUI_ICON path_to_icon_file.ico来设置安装程序的图标。 但是它同时设置了标题栏图标和exe文件图标。 如何用不同的图标分别设置它们?

您通常使用相同的图标,但如果必须,您可以强制使用不同的图标:

!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

当 NSIS 3.05 发布时,您可以将图标作为资源嵌入:

!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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM