簡體   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