NSIS:如何更改RichEdit背景颜色

时间:2017-08-09 11:26:27

标签: installer nsis richedit

我使用Nsis安装我的项目。我需要更改richEdit背景颜色。我尝试使用SetCtlColors方法,但它没有做任何更改。这是我的代码:

; handle variables
Var hCtl_FirstDialog
Var hCtl_FirstDialog_RichText1
Var hCtl_FirstDialog_Button1


; dialog create function
Function fnc_FirstDialog_Create

  ; === FirstDialog (type: Dialog) ===
  nsDialogs::Create 1018
  Pop $hCtl_FirstDialog
  ${If} $hCtl_FirstDialog == error
    Abort
  ${EndIf}
  !insertmacro MUI_HEADER_TEXT "Dialog title..." "Dialog subtitle..."

  ; === RichText1 (type: RichText) ===
  nsDialogs::CreateControl /NOUNLOAD "RichEdit20A" ${WS_VISIBLE}|${WS_CHILD}|${WS_TABSTOP}|${WS_VSCROLL}|${ES_MULTILINE}|${ES_WANTRETURN} ${WS_EX_STATICEDGE} 12.51u 14.77u 261.32u 92.92u ""
  Pop $hCtl_FirstDialog_RichText1
  ; RichText1 ControlCustomScript
  nsRichEdit::Load $hCtl_FirstDialog_RichText1 D:\temp\NsisProject\EULA.rtf
  SetCtlColors $hCtl_FirstDialog_RichText1 ccff00 ccff00

  ; === Button1 (type: Button) ===
  ${NSD_CreateButton} 225.11u 118.77u 49.37u 14.15u "Button1"
  Pop $hCtl_FirstDialog_Button1
  ${NSD_OnClick} $hCtl_FirstDialog_Button1 FillText

FunctionEnd

; dialog show function
Function fnc_FirstDialog_Show
  Call fnc_FirstDialog_Create
  nsDialogs::Show
FunctionEnd

1 个答案:

答案 0 :(得分:1)

richedit控件不支持SetCtlColors,您必须使用其记录的消息来设置文本格式:

!include nsDialogs.nsh
!include WinMessages.nsh
!define /ifndef /math EM_SETBKGNDCOLOR ${WM_USER} + 67
!define /ifndef /math EM_SETCHARFORMAT ${WM_USER} + 68
!define /ifndef /math EM_SETTEXTEX ${WM_USER} + 97
!define /ifndef ST_SELECTION 2
!define /ifndef CFM_COLOR 0x40000000
!define /ifndef SCF_DEFAULT  0x0000
!define /ifndef SCF_ALL      0x0004

Var hRichEd


Function MyPageCreate
nsDialogs::Create 1018
Pop $0

nsDialogs::CreateControl /NOUNLOAD "RichEdit20A" ${WS_VISIBLE}|${WS_CHILD}|${WS_TABSTOP}|${WS_VSCROLL}|${ES_MULTILINE}|${ES_WANTRETURN} ${WS_EX_STATICEDGE} 12.51u 14.77u 261.32u 92.92u ""
Pop $hRichEd
SendMessage $hRichEd ${EM_SETBKGNDCOLOR} 0 0x00ffcc

!if 1 ; Set default
    System::Call '*(i 60, i ${CFM_COLOR}, i0,i0,i0, i 0xcc00ff, i, &m32)p.r0' ; Note: 60 is the ANSI size
    SendMessage $hRichEd ${EM_SETCHARFORMAT} ${SCF_ALL} $0
    System::Free $0
    ${nsD_SetText} $hRichEd "Text goes here"
!else ; Import RTF
    System::Call '*(i${ST_SELECTION},i0)p.r0'
    SendMessage $hRichEd ${EM_SETTEXTEX} $0 "STR:{\rtf1\ansi\deff0{\colortbl;\red115\green0\blue25;}\cf1 Text goes here}" ; www.pindari.com/rtf1.html
    System::Free $0
    SendMessage $hRichEd ${EM_REPLACESEL} 0 "STR: and more text here"
!endif

nsDialogs::Show
FunctionEnd

Page Custom MyPageCreate