简体   繁体   中英

NSIS Installer MUI_HEADER_TEXT - Can part of this be bold font?

Is there a way to set part of the installer's MUI_HEADER_TEXT to bold font?

I see examples on ${NSD_CreateLabel} for font but not the header text.

!insertmacro MUI_HEADER_TEXT "Main" "Subtext with a BOLD "

I found out that this is not possible.

I did find a solution for adding custom fonts to labels easily without guess work.

I used this editor and pasted the script in my setup. https://coolsoft.altervista.org

Windows does not generally support different fonts in a single control. The header text is also a label ( $mui.Header.SubText in MUIv2).

Some people use two labels when they require parts in bold but this is a bit of a hack to get them aligned correctly and it cannot be done to the header text because MUI needs to hide/show these when you switch from Welcome/Finish style pages to "normal" pages.

The only control that supports partly bold text is the RichEdit control and it can be done with a bit of hacking:

!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

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.

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