【发布时间】:2019-11-04 16:10:31
【问题描述】:
有没有办法将安装程序的部分 MUI_HEADER_TEXT 设置为粗体?
我在 ${NSD_CreateLabel} 上看到了字体示例,但没有看到标题文本。
!insertmacro MUI_HEADER_TEXT "Main" "带有BOLD的子文本"
【问题讨论】:
标签: installation nsis
有没有办法将安装程序的部分 MUI_HEADER_TEXT 设置为粗体?
我在 ${NSD_CreateLabel} 上看到了字体示例,但没有看到标题文本。
!insertmacro MUI_HEADER_TEXT "Main" "带有BOLD的子文本"
【问题讨论】:
标签: installation nsis
【讨论】:
Windows 通常不支持在单个控件中使用不同的字体。标题文本也是一个标签(MUIv2 中的$mui.Header.SubText)。
有些人在需要以粗体显示的部分时会使用两个标签,但要使它们正确对齐有点麻烦,并且无法对标题文本执行此操作,因为当您从 Welcome/ 切换时 MUI 需要隐藏/显示这些完成样式页面到“正常”页面。
唯一支持部分粗体文本的控件是 RichEdit 控件和 it can be done,带有一点黑客:
!define MUI_CUSTOMFUNCTION_GUIINIT MyGuiInit
!include MUI2.nsh
Page Custom MyPageCreate
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_PAGE_FINISH
!insertmacro MUI_LANGUAGE English
!include Util.nsh
Function MyGuiInit
!ifndef NSIS_CONFIG_LICENSEPAGE
System::Call 'KERNEL32::LoadLibrary(t "RichEd20")'
System::Call 'KERNEL32::LoadLibrary(t "RichEd32")'
!endif
StrCpy $0 $HWNDPARENT
ShowWindow $mui.Header.SubText 0
StrCpy $2 $mui.Header.SubText
System::Call 'USER32::GetWindowRect(p$2, @r1)'
${IntPtrOp} $3 $1 + 8
System::Call 'USER32::MapWindowPoints(p0,p$2,p$3,i1)'
System::Call '*$1(&i4i,&i4i,&i4i.r5,&i4i.r6)' ;w&h
System::Call 'USER32::MapWindowPoints(p0,p$0,p$1,i1)'
System::Call '*$1(&i4i.r3,&i4i.r4)' ;l&t
;Try both richedit classes
StrCpy $7 "RichEdit20A"
createRich:
System::Call 'USER32::CreateWindowEx(i ${WS_EX_TRANSPARENT},tr7,p0,\
i ${WS_VISIBLE}|${WS_CHILD}|${WS_CLIPSIBLINGS}|${ES_READONLY}|${ES_MULTILINE}|${ES_WANTRETURN},\
i $3,i $4,i $5,i $6,p $0,p0,p0,p0)i.s'
pop $mui.Header.SubText
${If} $mui.Header.SubText = 0
${AndIf} $7 == "RichEdit20A"
StrCpy $7 "RichEdit"
goto createRich
${EndIf}
System::Call USER32::BringWindowToTop(p$mui.Header.SubText)
!define /IfNDef /Math EM_SETCHARFORMAT ${WM_USER} + 68
!define /IfNDef LF_FACESIZE 32
!define /IfNDef CFM_COLOR 0x40000000
; Forcing color does not work?
#System::Call '*$1(&l4,i${CFM_COLOR},i0,i,i,i0x${MUI_BGCOLOR},&i1,&i1,&i2,&m${LF_FACESIZE})'
#SendMessage $mui.Header.SubText ${EM_SETCHARFORMAT} 0 $1 $9
#SendMessage $mui.Header.SubText ${EM_SETBKGNDCOLOR} 0 0x${MUI_BGCOLOR}
SendMessage $2 ${WM_GETFONT} 0 0 $1
SendMessage $mui.Header.SubText ${WM_SETFONT} $1 1
FunctionEnd
Function MyPageCreate
!insertmacro MUI_HEADER_TEXT "Main" "{\rtf1{Subtext with a \b Bold \b0 }"
nsDialogs::Create 1018
Pop $0
nsDialogs::Show
FunctionEnd
【讨论】: