// ScintillaWnd.cpp: 实现文件
//
#include "stdafx.h"
#include "CppCodeEditor.h"
#include "ScintillaWnd.h"
// ScintillaWnd
IMPLEMENT_DYNAMIC(ScintillaWnd, CWnd)
ScintillaWnd::ScintillaWnd()
{
m_hSciLexerDll = NULL;
m_hSciLexerDll = LoadLibrary(_T("SciLexer.dll"));
if (NULL == m_hSciLexerDll)
{
AfxMessageBox(_T("LoadLibrary SciLexer.dll failure..."));
}
}
ScintillaWnd::~ScintillaWnd()
{
if (NULL != m_hWnd)
{
DestroyWindow();
}
if (m_hSciLexerDll != NULL)
{
FreeLibrary(m_hSciLexerDll);
}
}
BEGIN_MESSAGE_MAP(ScintillaWnd, CWnd)
END_MESSAGE_MAP()
// ScintillaWnd 消息处理程序
void ScintillaWnd::Init()
{
// clear all text styles
SendMessage(SCI_CLEARDOCUMENTSTYLE, 0, 0);
// set the number of styling bits to 7 - the asp/html views need a lot of styling - default is 5
// If you leave the default you will see twiggle lines instead of ASP code
SendMessage(SCI_SETSTYLEBITS, 7, 0);
// set the display for indetation guides to on - this displays virtical dotted lines from the beginning of
// a code block to the end of the block
SendMessage(SCI_SETINDENTATIONGUIDES, TRUE, 0);
// set tabwidth to 4
SendMessage(SCI_SETTABWIDTH, 4, 0);
// set indention to 4
SendMessage(SCI_SETINDENT, 4, 0);
// set the caret blinking time to 400 milliseconds
SendMessage(SCI_SETCARETPERIOD, 400, 0);
// display fold margins
SetFold();
// hide SelectionMargin
SendMessage(SCI_SETMARGINWIDTHN, 1, 0);
// set markersymbol for marker type 0 - bookmark
SendMessage(SCI_MARKERDEFINE, 0, SC_MARK_CIRCLE);
// set the forground color for some styles
SendMessage(SCI_STYLESETFORE, 0, RGB(0, 0, 0));
SendMessage(SCI_STYLESETFORE, 2, RGB(0, 64, 0));
SendMessage(SCI_STYLESETFORE, 5, RGB(0, 0, 255));
SendMessage(SCI_STYLESETFORE, 6, RGB(200, 20, 0));
SendMessage(SCI_STYLESETFORE, 9, RGB(0, 0, 255));
SendMessage(SCI_STYLESETFORE, 10, RGB(255, 0, 64));
SendMessage(SCI_STYLESETFORE, 11, RGB(0, 0, 0));
// set the backgroundcolor of brace highlights
SendMessage(SCI_STYLESETBACK, STYLE_BRACELIGHT, RGB(0, 255, 0));
// set end of line mode to CRLF
SendMessage(SCI_CONVERTEOLS, 2, 0);
SendMessage(SCI_SETEOLMODE, 2, 0);
// SendMessage(SCI_SETVIEWEOL, TRUE, 0);
//显示当前行的淡黄色背景
SendMessage(SCI_SETCARETLINEVISIBLE, TRUE, 0);
SendMessage(SCI_SETCARETLINEBACK, RGB(255, 255, 0), 0);
SendMessage(SCI_SETCARETLINEBACKALPHA, 100, 0);
}
void ScintillaWnd::InitScintillaEdit(int nSize, const TCHAR * face)
{
setCppSyntax();
Init();
SetDefaultColorFont(nSize, face);
UpdateLineNumberWidth();
}
void ScintillaWnd::SetDefaultColorFont(int nSize, const TCHAR * face)
{
SendMessage(SCI_SETSELFORE, TRUE, RGB(255, 255, 255));
//选中行的颜色
SendMessage(SCI_SETSELBACK, TRUE, RGB(10, 36, 106));
//默认文本颜色
SendMessage(SCI_STYLESETFORE, STYLE_DEFAULT, RGB(0x00, 0x00, 0x00));
SendMessage(SCI_STYLESETBACK, STYLE_DEFAULT, RGB(0xff, 0xff, 0xff));
SendMessage(SCI_STYLESETSIZE, STYLE_DEFAULT, nSize);
SendMessage(SCI_STYLESETFONT, STYLE_DEFAULT, reinterpret_cast<LPARAM>(face));
}
void ScintillaWnd::SetFold(BOOL bFold)
{
if (bFold)
{
// source folding section
// tell the lexer that we want folding information - the lexer supplies "folding levels"
SendMessage(SCI_SETPROPERTY, (WPARAM) "fold", (LPARAM)"1");
SendMessage(SCI_SETPROPERTY, (WPARAM) "fold.html", (LPARAM)"1");
SendMessage(SCI_SETPROPERTY, (WPARAM) "fold.html.preprocessor", (LPARAM)"1");
SendMessage(SCI_SETPROPERTY, (WPARAM) "fold.comment", (LPARAM)"1");
SendMessage(SCI_SETPROPERTY, (WPARAM) "fold.at.else", (LPARAM)"1");
SendMessage(SCI_SETPROPERTY, (WPARAM) "fold.flags", (LPARAM)"1");
SendMessage(SCI_SETPROPERTY, (WPARAM) "fold.preprocessor", (LPARAM)"1");
SendMessage(SCI_SETPROPERTY, (WPARAM) "styling.within.preprocessor", (LPARAM)"1");
SetMarginWidthN(2, 16); //SendMessage( SCI_SETMARGINWIDTHN, 2, 16 ); // FoldMargin
SendMessage(SCI_SETMARGINTYPEN, 2, SC_MARGIN_SYMBOL);//页边类型
SendMessage(SCI_SETMARGINMASKN, 2, SC_MASK_FOLDERS); //页边掩码
SendMessage(SCI_SETMARGINWIDTHN, 2, 16); //页边宽度
SendMessage(SCI_SETMARGINSENSITIVEN, 2, TRUE); //响应鼠标消息
// 折叠标签样式
SendMessage(SCI_MARKERDEFINE, SC_MARKNUM_FOLDER, SC_MARK_CIRCLEPLUS);
SendMessage(SCI_MARKERDEFINE, SC_MARKNUM_FOLDEROPEN, SC_MARK_CIRCLEMINUS);
SendMessage(SCI_MARKERDEFINE, SC_MARKNUM_FOLDEREND, SC_MARK_CIRCLEPLUSCONNECTED);
SendMessage(SCI_MARKERDEFINE, SC_MARKNUM_FOLDEROPENMID, SC_MARK_CIRCLEMINUSCONNECTED);
SendMessage(SCI_MARKERDEFINE, SC_MARKNUM_FOLDERMIDTAIL, SC_MARK_TCORNERCURVE);
SendMessage(SCI_MARKERDEFINE, SC_MARKNUM_FOLDERSUB, SC_MARK_VLINE);
SendMessage(SCI_MARKERDEFINE, SC_MARKNUM_FOLDERTAIL, SC_MARK_LCORNERCURVE);
// 折叠标签线颜色
SendMessage(SCI_MARKERSETBACK, SC_MARKNUM_FOLDERSUB, 0xff0000); //蓝色
SendMessage(SCI_MARKERSETBACK, SC_MARKNUM_FOLDERMIDTAIL, 0xff0000);
SendMessage(SCI_MARKERSETBACK, SC_MARKNUM_FOLDERTAIL, 0xff0000);
SendMessage(SCI_SETFOLDFLAGS, 16 | 4, 0); //如果折叠就在折叠行的上下各画一条横线
}
else
{
SetMarginWidthN(2, 0); //SendMessage( SCI_SETMARGINWIDTHN, 2, 0 ); // FoldMargin
}
}
void ScintillaWnd::ToggleFold(long line)
{
SendMessage(SCI_TOGGLEFOLD, static_cast<WPARAM>(line), 0);
}
int ScintillaWnd::GetMarginWidthN(int margin)
{
return SendMessage(SCI_GETMARGINWIDTHN, static_cast<WPARAM>(margin), 0);
}
void ScintillaWnd::SetMarginWidthN(int margin, int mask)
{
SendMessage(SCI_SETMARGINWIDTHN, static_cast<WPARAM>(margin), static_cast<LPARAM>(mask));
}
void ScintillaWnd::UpdateLineNumberWidth(void)
{
//start 显示行号
long iLineMarginWidthNow;
long iLineMarginWidthFit;
long iLineNum = SendMessage(SCI_GETLINECOUNT, 0, 0);
long iLineNumCount = 1;
while (iLineNum != 0)
{
++iLineNumCount;
iLineNum /= 10;
}
iLineMarginWidthNow = SendMessage(SCI_GETMARGINWIDTHN, 0, 0);
long charWidth = SendMessage(SCI_TEXTWIDTH, STYLE_LINENUMBER, (LPARAM)("9"));
iLineMarginWidthFit = charWidth * iLineNumCount;
if (iLineMarginWidthNow != iLineMarginWidthFit)
{
SendMessage(SCI_SETMARGINWIDTHN, 0, iLineMarginWidthFit);
}
//end of 显示行号
}
long ScintillaWnd::LineFromPosition(long pos)
{
return SendMessage(SCI_LINEFROMPOSITION, static_cast<WPARAM>(pos), 0);
}
const char cppKeyWords[] =
"and and_eq asm auto bitand bitor bool break "
"case catch char class compl const const_cast continue "
"default delete do double dynamic_cast else enum explicit export extern false float for "
"friend goto if inline int long mutable namespace new not not_eq "
"operator or or_eq private protected public "
"register reinterpret_cast return short signed sizeof static static_cast struct switch "
"template this throw true try typedef typeid typename union unsigned using "
"virtual void volatile wchar_t while xor xor_eq ";
void ScintillaWnd::setCppSyntax()
{
SendMessage(SCI_SETLEXER, SCLEX_CPP);
SendMessage(SCI_SETKEYWORDS, 0, (LPARAM)cppKeyWords);
// 下面设置各种语法元素前景色
SendMessage(SCI_STYLESETFORE, SCE_C_WORD, 0x00FF0000); //关键字
SendMessage(SCI_STYLESETFORE, SCE_C_STRING, 0x001515A3); //字符串
SendMessage(SCI_STYLESETFORE, SCE_C_CHARACTER, 0x001515A3); //字符
SendMessage(SCI_STYLESETFORE, SCE_C_PREPROCESSOR, 0x00808080);//预编译开关
SendMessage(SCI_STYLESETFORE, SCE_C_COMMENT, 0x00008000);//块注释
SendMessage(SCI_STYLESETFORE, SCE_C_COMMENTLINE, 0x00008000);//行注释
SendMessage(SCI_STYLESETFORE, SCE_C_COMMENTDOC, 0x00008000);//文档注释(/**开头)
SendMessage(SCI_STYLESETFORE, SCE_C_NUMBER, 0x000010ff);//数字
SendMessage(SCI_STYLESETFORE, SCE_C_OPERATOR, 0x0000c0f0);//操作
}
BOOL ScintillaWnd::OpenFile(CString lpFileName)
{
CStdioFile stdFile(lpFileName
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
CppCodeEditor.zip (47个子文件)
CppCodeEditor
.vs
CppCodeEditor
v15
ipch
922c27fc12236ccd.ipch 116.25MB
.suo 29KB
Browse.VC.db 74.34MB
Debug
SciLexer.dll 657KB
CppCodeEditor.exe 232KB
CppCodeEditor.pdb 2.53MB
CppCodeEditor.ilk 1.57MB
CppCodeEditor
ScintillaWnd.h 960B
CppCodeEditor.vcxproj.filters 2KB
SciLexer.dll 657KB
res
CppCodeEditor.ico 66KB
CppCodeEditor.rc2 682B
CppCodeEditor.vcxproj 10KB
CppCodeEditorDlg.h 1KB
CppCodeEditor.h 532B
ScintillaWnd.cpp 10KB
stdafx.h 2KB
Scintilla.h 37KB
CppCodeEditor.cpp 3KB
Debug
CppCodeEditorDlg.obj 94KB
vc141.pdb 8.84MB
ScintillaWnd.obj 46KB
vc141.idb 1.36MB
CppCodeEditor.obj 75KB
stdafx.obj 995KB
CppCodeEditor.res 68KB
CppCodeEditor.log 227B
CppCodeEditor.tlog
CL.write.1.tlog 6KB
rc.command.1.tlog 910B
CppCodeEditor.lastbuildstate 243B
link.command.1.tlog 4KB
CL.read.1.tlog 216KB
CL.command.1.tlog 7KB
rc.read.1.tlog 8KB
link.write.1.tlog 2KB
rc.write.1.tlog 618B
link.read.1.tlog 15KB
CppCodeEditor.pch 54.38MB
stdafx.cpp 182B
CppCodeEditorDlg.cpp 9KB
SciLexer.h 57KB
resource.h 2KB
targetver.h 299B
CppCodeEditor.rc 12KB
CppCodeEditor.aps 107KB
CppCodeEditor.vcxproj.user 236B
CppCodeEditor.sln 1KB
共 47 条
- 1
资源评论
qq_35297690
- 粉丝: 1
- 资源: 3
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功