精通
英语
和
开源
,
擅长
开发
与
培训
,
胸怀四海
第一信赖
Needing a quick and dirty colorizing edit control, I went to all of my favorite MFC source sites. Unfortunately, most of what I found was based on CView - not what I needed. I was sad.
Then, I found Randy More's "Syntax Coloring Text Edit Window Class" on CodeGuru. This was a start. Sadly, it had serious problems. So, I sat down and started hacking. Three days later, after replacing at least 90% of the original code, I decided I had something good enough to use. So, here it is.
需要一个快速而五颜六色的着色编辑控件,我去了所有我最喜欢的MFC源站点。不幸的是,我发现的大部分内容都是基于CView- 而不是我需要的东西。我很伤心。
然后,我在CodeGuru上找到了Randy More的“Syntax Coloring Text Edit Window Class” 。这是一个开始。可悲的是,它有严重的问题。所以,我坐下来开始刻苦研究。三天后,在更换至少90%的原始代码后,我认为我有足够的东西可以使用。所以,就有了现在的成果。
Symbol | Rule | Color |
# text | any line that starts with "#" is a comment | green |
@+ | must be the only text on the line | blue, but red if there is any other text on the line |
@- | must be the only text on the line | blue, but red if there is any other text on the line |
@:text | must be at the start of the line | red |
符号 | 规则 | 颜色 |
#text | 任何以“#”开头的行都是注释 | 绿色 |
@ + | 必须是该行上唯一的文字 | 蓝色,但如果线上有任何其他文字,则为红色 |
@ - | 必须是该行上唯一的文字 | 蓝色,但如果线上有任何其他文字,则为红色 |
@:文本 | 必须在行的开头 | 红色 |
m_pColorWnd = new ColorEditWnd( this, //parent window frameRect, //initial size and position ID_EDIT_WND, //id value iTabSize, //size of a tab iFontSize, //font size * 10 (I.E. 100 = 10) csFontName); //the font name
That's it! Well, almost... You also need to write a custom Colorizer object to handle your specific syntax coloring needs. :) In the sample this is demonstrated by the SampleColorizer class. It does the syntax coloring as described above, and calls the base class (CColorizer) to handle keyword coloring.好吧,差不多......你还需要编写一个自定义Colorizer对象来处理你特定的语法着色需求。:)在示例中,这是由SampleColorizer类演示的。它执行如上所述的语法着色,并调用基类(CColorizer)来处理关键字着色。
Here are a few of the interesting member functions:
// clear and set text to pInText void LoadText(const char *pInText);
// get a single string copy of the contents void UnloadText(CString &pText) const;
// number of text lines in the buffer int GetLineCount();
// set selection from char1, line1 to char2, line2 void SetSelection(int charPos1, int line1, int charPos2, int line2);
// replace the current selection with this text void ReplaceSelText(const char *pText);
// en/disable keyboard accelerators void UseKeyboardAccelerators(bool b);