Scintilla 3.24在MFC中的使用(动态、静态)
来源:互联网 发布:mysql sql语句编写 编辑:程序博客网 时间:2024/06/06 18:28
Scintilla是一个免费的源代码编辑组件。在这里记录下它在MFC中的使用。
本机环境:Windows XP、Visual Studio 2008 SP1
1.下载Scintilla源代码3.24版本(http://www.scintilla.org/ScintillaDownload.html)。
2.打开VS2008,点击菜单栏"Tools"→"Visual Studio 2008 Command Prompt",cd命令到"..\scintilla\win32"目录,使用以下命令进行编译:
4.从naughter网站下载MFC封装类(http://www.naughter.com/scintilla.html)。
5.新建一个MFC多文档应用程序,名称为TestScintilla。
6.将ScintillaCtrl.h、ScintillaCtrl.cpp、ScintillaDocView.h、ScintillaDocView.cpp拷贝到工程目录下,加入工程。
7.参考ScintillaDemo工程,创建IDD_SCINTILLA_FINDDLGORD和IDD_SCINTILLA_REPLACEDLGORD对话框。
8.在"stdafx.h"文件添加如下代码:
2
3
4
#include <platform.h>
#include <scintilla.h>
#include <SciLexer.h>
2
3
4
5
6
if (m_hSciDLL == NULL)
{
AfxMessageBox(_T("SciLexer DLL is not installed."));
return FALSE;
}
2
3
4
{
FreeLibrary(m_hSciDLL);
}
10.重载CTestScintillaView的OnInitialUpdate方法,代码如下:
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
_T("and and_eq asm auto bitand bitor bool break ")
_T("case catch char class compl const const_cast continue ")
_T("default delete do double dynamic_cast else enum explicit export extern false float for ")
_T("friend goto if inline int long mutable namespace new not not_eq ")
_T("operator or or_eq private protected public ")
_T("register reinterpret_cast return short signed sizeof static static_cast struct switch ")
_T("template this throw true try typedef typeid typename union unsigned using ")
_T("virtual void volatile wchar_t while xor xor_eq ");
void CTestScintillaView::OnInitialUpdate()
{
CScintillaView::OnInitialUpdate();
CScintillaCtrl& rCtrl = GetCtrl();
//Setup the Lexer
rCtrl.SetLexer(SCLEX_CPP);
rCtrl.SetKeyWords(0, cppKeyWords);
//Setup styles
rCtrl.StyleSetFore(STYLE_DEFAULT, RGB(0, 0, 0));
rCtrl.StyleSetBack(STYLE_DEFAULT, RGB(0xff, 0xff, 0xff));
rCtrl.StyleSetSize(STYLE_DEFAULT, 11);
rCtrl.StyleSetFont(STYLE_DEFAULT, "Verdana");
rCtrl.StyleClearAll();
rCtrl.StyleSetFore(SCE_C_DEFAULT, RGB(0, 0, 0));
rCtrl.StyleSetFore(SCE_C_COMMENT, RGB(0, 0x80, 0));
rCtrl.StyleSetFore(SCE_C_COMMENTLINE, RGB(0, 0x80, 0));
rCtrl.StyleSetFore(SCE_C_COMMENTDOC, RGB(0, 0x80, 0));
rCtrl.StyleSetFore(SCE_C_COMMENTLINEDOC, RGB(0, 0x80, 0));
rCtrl.StyleSetFore(SCE_C_COMMENTDOCKEYWORD, RGB(0, 0x80, 0));
rCtrl.StyleSetFore(SCE_C_COMMENTDOCKEYWORDERROR, RGB(0, 0x80, 0));
rCtrl.StyleSetFore(SCE_C_NUMBER, RGB(0, 0x80, 0x80));
rCtrl.StyleSetFore(SCE_C_WORD, RGB(0, 0, 0x80));
rCtrl.StyleSetBold(SCE_C_WORD, 1);
rCtrl.StyleSetFore(SCE_C_STRING, RGB(0x80, 0, 0x80));
rCtrl.StyleSetFore(SCE_C_IDENTIFIER, RGB(0, 0, 0));
rCtrl.StyleSetFore(SCE_C_PREPROCESSOR, RGB(0x80, 0, 0));
rCtrl.StyleSetFore(SCE_C_OPERATOR, RGB(0x80, 0x80, 0));
}
设定C++语法解析器,设定高亮关键字,设定文本风格,再次编译运行,效果如下图所示:
示例代码下载:http://download.csdn.net/detail/akof1314/5069136
静态编译步骤如下:
1.创建一个静态库工程,名称为:ScintillaLib。
2.将scintilla源代码文件夹放到工程目录下,将lexers、lexlib、src、win32目录下的文件添加到工程。
3.工程属性,C/C++→General→Additional Include Directories填入.\scintilla\include;.\scintilla\lexlib;.\scintilla\src
C/C++→Preprocessor→Preprocessor Definitions填入STATIC_BUILD;SCI_LEXER
4.注释掉CheckD2D.cxx文件里面的内容。
5.编译完成。
6.使用上面的测试工程,在CTestScintillaApp的InitInstance函数,加入以下代码:
8.编译运行。
示例代码下载:http://download.csdn.net/detail/akof1314/5069143
排除掉不需要的语言解析器:
1.删除掉"..\scintilla\lexers"目录下不需要的语言解析器对应的Lex*.cxx文件,比如这里只留下LexCPP.cxx文件。
2.打开"..\scintilla\src\Catalogue.cxx"文件,找到如下位置
2
LINK_LEXER(lmCPPNoCase);
2
#**LEXOBJS=\\\n\(\t$(DIR_O)\\\*.obj \\\n\)
2
3
4
5
6
#**LEXOBJS=\\\n\(\t$(DIR_O)\\\*.obj \\\n\)
LEXOBJS=\
$(DIR_O)\LexCPP.obj \
#--Autogenerated -- end of automatically generated section
2
#**\n\($(DIR_O)\\\*.obj: ..\\lexers\\\*.cxx $(LEX_HEADERS)\n\n\)
2
3
4
5
6
7
#**\n\($(DIR_O)\\\*.obj: ..\\lexers\\\*.cxx $(LEX_HEADERS)\n\n\)
$(DIR_O)\LexCPP.obj: ..\lexers\LexCPP.cxx $(LEX_HEADERS)
#--Autogenerated -- end of automatically generated section
参考资料:
1.Scintilla Documentation http://www.scintilla.org/ScintillaDoc.html
2.MFC classes to encapsulate the Scintilla edit control http://www.naughter.com/scintilla.html
3.语法高亮编辑控件Scintilla在MFC中的简单使用 http://www.qingfengju.com/article.asp?id=14
4.用Scintilla让程序支持语法高亮并且编译 http://hi.baidu.com/kxw102/item/b7e701a569d685de5af19138
5.Scintilla开源库使用指南 http://www.cnblogs.com/superanyi/archive/2011/04/07/2008632.html
- Scintilla 3.24在MFC中的使用(动态、静态)
- Scintilla 在MFC中的简易使用(动态、静态)
- Scintilla 在MFC中的简易使用(动态、静态)
- Scintilla 3.2.5在VC中的编译(动态、静态)
- 语法高亮编辑控件Scintilla在MFC中的简单使用
- 语法高亮编辑控件Scintilla在MFC中的简单使用之完整示例
- 语法高亮编辑控件Scintilla在MFC中的简单使用
- 语法高亮编辑控件Scintilla在MFC中的简单使用
- Scintilla在WTL中的简易使用
- “为了能够访问动态链接库中的位图资源,在编译动态链接库时,需要使用MFC静态库”
- CString::MakeLower() ::MakeUpper()在静态链接MFC和动态链接MFC中的区别
- scintilla 中的代码折叠功能的使用
- 在静态库中使用MFC
- 在静态库中使用MFC
- SonicUI在MFC中的使用
- SonicUI在MFC中的使用
- SonicUI在MFC中的使用
- OpenCV在MFC中的使用
- 别了,产品经理的能力模型
- 微软关闭Silverlight官网,该技术逐渐被边缘化
- skia之setXfermode
- Oracle存储过程单步调试方法
- OpenShift免费空间绑定顶级域名
- Scintilla 3.24在MFC中的使用(动态、静态)
- webkit在win32下的编译规则
- c++ 使用MapWinGis读取shp文件
- 摘抄
- WebKit中RefPtr和PassRefPtr的使用
- COM编程基础知识
- 10个最佳翻译平台&英语飙升的好方法
- String里的format在sql中的妙用
- 如何解决安装Ubuntu 12.04后屏幕闪烁的问题