前言:
现时看官们对“css3写对话框”大体比较重视,同学们都需要知道一些“css3写对话框”的相关内容。那么小编在网络上搜集了一些关于“css3写对话框””的相关文章,希望你们能喜欢,朋友们快快来学习一下吧!1、首先,在ScintillaWnd.h头文件中添加如下代码
HMODULE m_hSciLexerDll;
如下图:
2、在ScintillaWnd.cpp源文件的构造函数和析构函数中添加如下代码
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); }}
这是析构函数
3、为窗口类创建Create函数
打开类向导,选择“ScintillaWnd”类,找到“虚函数”,找到“Create”函数,点击“添加函数”。
添加完“Create”函数,会自动生成一些代码,这些代码不需要改动,保持原样就好。
4、为窗口类添加Init()函数,先在ScintillaWnd.h中添加下面的代码
virtual void Init();
点击图中“小灯泡”,会提示你在ScintillaWnd.cpp文件中创建Init()函数,点击创建。
在创建的Init()函数中添加如下代码
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);}
注意:要在ScintillaWnd.h头文件中包含Scintilla.h和SciLexer.h头文件
为窗口类添加InitScintillaEdit函数,在ScintillaWnd.h中添加下面的代码
void InitScintillaEdit(int nSize, const TCHAR* face);
用同样的方法,在ScintillaWnd.cpp文件中创建InitScintillaEdit函数
在创建的InitScintillaEdit函数添加如下代码
void ScintillaWnd::InitScintillaEdit(int nSize, const TCHAR * face){ setCppSyntax(); Init(); SetDefaultColorFont(nSize, face); UpdateLineNumberWidth();}
为窗口类添加SetDefaultColorFont函数
void SetDefaultColorFont(int nSize, const TCHAR* face);
在创建的SetDefaultColorFont函数添加如下代码
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));}
为窗口类添加SetFold函数
void SetFold(BOOL bFold = TRUE);
在创建的SetFold函数添加如下代码
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 }}
为窗口类添加ToggleFold函数
void ToggleFold(long line);
在创建的SetFold函数添加如下代码
void ScintillaWnd::ToggleFold(long line){ SendMessage(SCI_TOGGLEFOLD, static_cast<WPARAM>(line), 0);}
为窗口类添加GetMarginWidthN函数
int GetMarginWidthN(int margin);
在创建的GetMarginWidthN函数添加如下代码
int ScintillaWnd::GetMarginWidthN(int margin){ return SendMessage(SCI_GETMARGINWIDTHN, static_cast<WPARAM>(margin), 0);}
为窗口类添加SetMarginWidthN函数
void SetMarginWidthN(int margin, int mask);
在创建的SetMarginWidthN函数添加如下代码
void ScintillaWnd::SetMarginWidthN(int margin, int mask){ SendMessage(SCI_SETMARGINWIDTHN, static_cast<WPARAM>(margin), static_cast<LPARAM>(mask));}
为窗口类添加UpdateLineNumberWidth函数
void UpdateLineNumberWidth(void);
在创建的UpdateLineNumberWidth函数添加如下代码
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 显示行号}
为窗口类添加LineFromPosition函数
long LineFromPosition(long pos);
在创建的LineFromPosition函数添加如下代码
long ScintillaWnd::LineFromPosition(long pos){ return SendMessage(SCI_LINEFROMPOSITION, static_cast<WPARAM>(pos), 0);}
ScintillaWnd窗口类的大部分代码已经添加完成,后续还要添加一些代码,下一章会讲在CCppEditorDlg类中添加代码,给CCppEditorDlg类添加完代码后,项目就可以编译运行了,但这只是一个简单的版本,我还会添加功能,到时候再为大家讲解。
(未完待续)
标签: #css3写对话框