最新消息:

nsDialogs使用RichEdit20A创建RTF富文本框

nsis 永恒心锁 2879浏览 0评论

可以使用别人写好的头文件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 "pythonschool.exe"
BrandingText "WwW.pythonschool.CoM"
loadlanguagefile "${NSISDIR}ContribLanguage filessimpChinese.nlf"
var dialog
var hwnd
var null
Page custom null ; 空页面仅测试
Page custom pythonschool_CreatePage1
Page custom null ; 空页面仅测试
Function .onInit
 InitPluginsDir
FunctionEnd
var RichEditControl
Function pythonschool_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 "pythonschool.rtf"
 ${LoadRTF} "$PLUGINSDIRpythonschool.rtf" $RichEditControl
 nsDialogs::Show
FunctionEnd
Function null
 nsDialogs::Create 1018
 Pop $dialog
 ${NSD_CreateLabel} 0 0 100% 8% "WwW.pythonschool.CoM"
 Pop $null
 nsDialogs::Show
FunctionEnd
Section -pythonschool
SectionEnd

例子二:

!addplugindir "."
!addincludedir "."
!include "nsDialogs.nsh"
!include "winmessages.nsh"
!include "logiclib.nsh"
;!include "MUI2.nsh"
!include "LoadRTF.nsh"
Caption "nsDialogs使用RichEdit20A创建RTF富文本框"
OutFile "pythonschool.exe"
BrandingText "WwW.pythonschool.CoM"
loadlanguagefile "${NSISDIR}ContribLanguage filessimpChinese.nlf"
var dialog
var hwnd
var null
var RICHEDIT
var RADIO_AUTO
var RADIO_MANUAL
Page custom null ; 空页面仅测试
Page custom pythonschool_CreatePage1
Page custom pythonschool_CreatePage2
Page custom null ; 空页面仅测试
Function .onInit
 InitPluginsDir
FunctionEnd
var RichEditControl
Function pythonschool_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 "pythonschool.rtf"
 ${LoadRTF} "$PLUGINSDIRpythonschool.rtf" $RichEditControl
 nsDialogs::Show
FunctionEnd
Function pythonschool_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 "pythonschool.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.pythonschool.CoM"
 Pop $null
 nsDialogs::Show
FunctionEnd
Section -pythonschool
SectionEnd
免责声明:根据《计算机软件保护条例》第十七条规定“为了学习和研究软件内含的设计思想和原理,通过安装、显示、传输或者存储软件等方式使用软件的,可以不经软件著作权人许可,不向其支付报酬。”您需知晓本站所有内容资源均来源于网络,仅供用户交流学习与研究使用,版权归属原版权方所有,版权争议与本站无关,用户本人下载后不能用作商业或非法用途,需在24个小时之内从您的电脑中彻底删除上述内容,否则后果均由用户承担责任;如果您访问和下载此文件,表示您同意只将此文件用于参考、学习而非其他用途,否则一切后果请您自行承担,如果您喜欢该程序,请支持正版软件,购买注册,得到更好的正版服务。丨本站为个人博客非盈利性站点,所有软件信息均来自网络,所有资源仅供学习参考研究目的,并不贩卖软件,不存在任何商业目的及用途。丨本文采用知识共享 署名4.0国际许可协议 [BY-NC-SA] 进行授权BY-NC-SA协议进行授权

转载请注明:永恒心锁-分享互联网 » nsDialogs使用RichEdit20A创建RTF富文本框

发表我的评论
取消评论
表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址