可以使用别人写好的头文件LoadRTF.nsh 载入RTF到富文件框(RichEdit20A创建)头文件LoadRTF.nsh
检查LoadRTF是否#included LoadRTF不能包含两次
!ifndef LoadRTFincluded
/*
Defines used by LoadRTF
*/
!ifndef SF_RTF
!define SF_RTF 2
!endif
!ifndef EM_STREAMIN
!define EM_STREAMIN 1097
!endif
!ifndef EM_EXLIMITTEXT
!define EM_EXLIMITTEXT 1077
!endif
/*
LoadRTF 主函数
Inserted via macro for Installer vs Uninstaller
Loads an RTF file into a RichEdit20a control
Thanks to Anders for all the heavy work
Define/Macro/Functionfication and a CallbackN tweak by Animaether
Usage:
Push Path-to-RTF-file
Push HWND-of-RichEdit20A-control
Call LoadRTF
-or for uninstallers-
Call un.LoadRTF
*/
!macro LoadRTFfunc Un
Function ${Un}LoadRTF
; RichEdit20A.hwnd RTFilePath.string
Exch $0 ; $0 RTFilePath.string ; $0 = RichEdit20A.hwnd
Exch ; RTFilePath.string $0
Exch $1 ; $1 $0 ; $1 = RTFilePath.string
Push $2 ; $2 $1 $0 ; $2 : Callback address
Push $3 ; $3 $2 $1 $0 ; $3 : EDITSTREAM structure
Push $4 ; $4 $3 $2 $1 $0 ; $4 : callbackN identifier from System plugin to check against
Push $R0 ; $R0 $4 $3 $2 $1 $0 ; $R0 : Buffer that receives data from ReadFile()
Push $R1 ; $R1 $R0 $4 $3 $@ $1 $0 ; $R1 : Maximum number of bytes to read using ReadFile()
Push $R2 ; $R2 $R1 $R0 $4 $3 $@ $1 $0 ; $R2 : Number of bytes actually read using ReadFile()
SendMessage $0 ${EM_EXLIMITTEXT} 0 0x7fffffff
System::Get "(i, i .R0, i .R1, i .R2) iss"
Pop $2
System::Call "*(i 0, i 0, k r2) i .r3"
System::Call "user32::SendMessage(i r0, i ${EM_STREAMIN}, i ${SF_RTF}, i r3) i.s"
Pop $4
Push $4
ClearErrors
FileOpen $1 "$1" r ; $1 = RTFile.handle
_loop:
Pop $0 ; $0 = callbackN identifier from System plugin.
StrCmp $0 "$4" 0 _done ; check if System plugin's callbackN matches the stored callbackN
System::Call "kernel32::ReadFile(i $1, i $R0, i $R1, i $R2, i 0)"
Push 0 # callback's return value
System::Call "$2"
goto _loop
_done:
FileClose $1
System::Free $3
System::Free $2
; $R2 $R1 $R0 $4 $3 $2 $1 $0
Pop $R2 ; $R1 $R0 $4 $3 $2 $1 $0
Pop $R1 ; $R0 $4 $3 $2 $1 $0
Pop $R0 ; $4 $3 $2 $1 $0
Pop $4 ; $3 $2 $1 $0
Pop $3 ; $2 $1 $0
Pop $2 ; $1 $0
Pop $1 ; $0
Pop $0 ; -empty-
FunctionEnd
!macroend
!insertmacro LoadRTFfunc ""
!insertmacro LoadRTFfunc "un."
/*
LoadRTF Ease of use functions.
Simplifies usage of LoadRTF.
Usage:
${LoadRTF} "Path-to-RTF-file" HWND-of-RichEdit20A-control
-or for uninstallers-
${un.LoadRTF} "Path-to-RTF-file" HWND-of-RichEdit20A-control
*/
!macro LoadRTF file hwnd
Push "${file}"
Push ${hwnd}
Call LoadRTF
!macroend
!define LoadRTF `!insertmacro LoadRTF`
!macro un.LoadRTF file hwnd
Push "${file}"
Push ${hwnd}
Call un.LoadRTF
!macroend
!define un.LoadRTF `!insertmacro LoadRTF.un`
/* 检查LoadRTF是否#included LoadRTF不能包含两次 */
!define LoadRTFincluded
!endif
例子一:
!addplugindir "."
!addincludedir "."
!include "nsDialogs.nsh"
!include "winmessages.nsh"
!include "logiclib.nsh"
;!include "MUI2.nsh"
!include "LoadRTF.nsh"
Caption "nsDialogs使用RichEdit20A创建RTF富文本框"
OutFile "yhxs3344.exe"
BrandingText "www.yhxs3344.net"
loadlanguagefile "${NSISDIR}ContribLanguage filessimpChinese.nlf"
var dialog
var hwnd
var null
Page custom null ; 空页面仅测试
Page custom yhxs3344_CreatePage1
Page custom null ; 空页面仅测试
Function .onInit
InitPluginsDir
FunctionEnd
var RichEditControl
Function yhxs3344_CreatePage1
nsDialogs::Create 1018
Pop $dialog
nsDialogs::CreateControl "RichEdit20A"
"${DEFAULT_STYLES}|${WS_TABSTOP}|${WS_VSCROLL}|${ES_MULTILINE}|${ES_READONLY}"
"${WS_EX_WINDOWEDGE}|${WS_EX_CLIENTEDGE}"
0 0 100% 100% ""
Pop $RichEditControl
SetOutPath "$PLUGINSDIR"
File "yhxs3344.rtf"
${LoadRTF} "$PLUGINSDIRyhxs3344.rtf" $RichEditControl
nsDialogs::Show
FunctionEnd
Function null
nsDialogs::Create 1018
Pop $dialog
${NSD_CreateLabel} 0 0 100% 8% "www.yhxs3344.net"
Pop $null
nsDialogs::Show
FunctionEnd
Section -yhxs3344
SectionEnd
例子二:
!addplugindir "."
!addincludedir "."
!include "nsDialogs.nsh"
!include "winmessages.nsh"
!include "logiclib.nsh"
;!include "MUI2.nsh"
!include "LoadRTF.nsh"
Caption "nsDialogs使用RichEdit20A创建RTF富文本框"
OutFile "yhxs3344.exe"
BrandingText "www.yhxs3344.net"
loadlanguagefile "${NSISDIR}ContribLanguage filessimpChinese.nlf"
var dialog
var hwnd
var null
var RICHEDIT
var RADIO_AUTO
var RADIO_MANUAL
Page custom null ; 空页面仅测试
Page custom yhxs3344_CreatePage1
Page custom yhxs3344_CreatePage2
Page custom null ; 空页面仅测试
Function .onInit
InitPluginsDir
FunctionEnd
var RichEditControl
Function yhxs3344_CreatePage1
nsDialogs::Create 1018
Pop $dialog
nsDialogs::CreateControl "RichEdit20A"
"${DEFAULT_STYLES}|${WS_TABSTOP}|${WS_VSCROLL}|${ES_MULTILINE}|${ES_READONLY}"
"${WS_EX_WINDOWEDGE}|${WS_EX_CLIENTEDGE}"
0 0 100% 100% ""
Pop $RichEditControl
SetOutPath "$PLUGINSDIR"
File "yhxs3344.rtf"
${LoadRTF} "$PLUGINSDIRyhxs3344.rtf" $RichEditControl
nsDialogs::Show
FunctionEnd
Function yhxs3344_CreatePage2
nsDialogs::Create /NOUNLOAD 1018
Pop $DIALOG
nsDialogs::CreateControl /NOUNLOAD "RichEdit20A"
"${WS_VISIBLE}|${WS_CHILD}|${WS_TABSTOP}|${WS_VSCROLL}|${ES_MULTILINE}"
"${ES_WANTRETURN}|${ES_READONLY} ${__NSD_Text_EXSTYLE}"
0 0 100% 140 ''
Pop $RICHEDIT
CustomLicense::LoadFile "yhxs3344.rtf" $RICHEDIT
;Call LoadLicense
### 单选项: 自动安装 ###
${NSD_CreateRadioButton} 1 150 450 15 "快速安装"
Pop $RADIO_AUTO
${NSD_CreateRadioButton} 1 175 450 15 "自定义安装"
Pop $RADIO_MANUAL
nsDialogs::Show
FunctionEnd
Function null
nsDialogs::Create 1018
Pop $dialog
${NSD_CreateLabel} 0 0 100% 8% "www.yhxs3344.net"
Pop $null
nsDialogs::Show
FunctionEnd
Section -yhxs3344
SectionEnd
THE END
暂无评论内容