青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

牽著老婆滿街逛

嚴以律己,寬以待人. 三思而后行.
GMail/GTalk: yanglinbo#google.com;
MSN/Email: tx7do#yahoo.com.cn;
QQ: 3 0 3 3 9 6 9 2 0 .

一個有意思的給代碼染色的類:CSyntaxColorizer

可以給C++代碼染色,演示程序運行后如圖所示:



其主頁在:http://mypage.uniserve.com/~jeffsch/computing/visualC++/CSyntaxColorizer.html

Description

The CSyntaxColorizer class described here is a fast and versatile class for the syntax highlighting of code. The class is very simple to use, very fast, and highly flexible. The default highlighting mode is VC++, with comments in green, strings in dark blue, and keywords in light blue. The class exposes several methods that can be used for changing these defaults - and color is not the only option. Highlighted words can be made bold, italic, underlined, and more. The exposed methods take a CHARFORMAT structure as a parameter, so whatever text formatting changes can be made with a CHARFORMAT structure can also be made with the keyword, comment, and string formats in CSyntaxColorizer. As well, you are not limited to a predefined and fixed set of keyword groupings. The keywords can be grouped in any way you like, and then manipulated by group. For example, you could assign all compiler directives the group ID of 723 (or whatever) and then set all keywords with group ID 723 to the color red.

The default groupings for the CSyntaxColorizer class are as follows:

Group 0: VC++ keywords such as for, if, while, void, etc
Group 1: VC++ compiler directives such as #define, #include, etc
Group 2: VC++ compiler pragmas such as once, auto_inline, etc

CSyntaxColorizer maintains member variables, (m_cfDefault, m_cfComment and m_cfString), of type CHARFORMAT. These defaults are used when the class initializes its internal lists, and whenever the keyword, comment or string colors are changed using the methods that take a COLORREF parameter instead of a CHARFORMAT parameter. These default structures have a font of Courier New, 10pt size. Naturally, the class exposes methods for changing the defaults (see below).

Here are the declarations in CSyntaxColorizer.h for the exposed methods:

    void Colorize(long StartChar, long nEndChar, CRichEditCtrl *pCtrl);
void Colorize(CHARRANGE cr, CRichEditCtrl *pCtrl);
void GetCommentStyle(CHARFORMAT &cf) { cf = m_cfComment; };
void GetStringStyle(CHARFORMAT &cf) { cf = m_cfString; };
void GetGroupStyle(int grp, CHARFORMAT &cf);
void GetDefaultStyle(CHARFORMAT &cf) { cf = m_cfDefault; };
void SetCommentStyle(CHARFORMAT cf) { m_cfComment = cf; };
void SetCommentColor(COLORREF cr);
void SetStringStyle(CHARFORMAT cf) { m_cfString = cf; };
void SetStringColor(COLORREF cr);
void SetGroupStyle(int grp, CHARFORMAT cf);
void SetGroupColor(int grp, COLORREF cr);
void SetDefaultStyle(CHARFORMAT cf) { m_cfDefault = cf; };
void AddKeyword(LPCTSTR Keyword, CHARFORMAT cf, int grp = 0);
void AddKeyword(LPCTSTR Keyword, COLORREF cr, int grp = 0);
void ClearKeywordList();
CString GetKeywordList();
CString GetKeywordList(int grp);

[Back to Top]

Using CSyntaxColorizer

The simplest and quickest way to use this class is to first declare it, then call one of the overloaded Colorize member functions. For example, this code

    CSyntaxColorizer sc;
sc.Colorize(0, -1, &m_cRichEditCtrl);
first creates the object, then calls its Colorize method, which in this case colorizes all of the text in the specified rich edit box, using CSyntaxColorizer's default font, keyword groupings, and colors described above.

If you don't like the default colors, you can change them:

    sc.SetCommentColor(RGB(255,0,0));
sc.SetStringColor(RGB(0,255,0));
sc.SetGroupColor(nMyGroup,RGB(0,0,255));
The preceding methods change the color using the CHARFORMAT structures that would be returned by their respective "Get..." methods.

If it's more than just colors you don't like, then you can set the CHARFORMAT structures using

    sc.SetCommentStyle(cfMyStyle);
sc.SetStringStyle(cfMyStyle);
sc.SetGroupStyle(nMyGroup,cfMyStyle);
where cfMyStyle is a CHARFORMAT structure that you have created yourself from scratch, or have retrieved using one of the "Get..." methods and then modified to suit.

Adding keywords is easy too. The two AddKeyword methods each take an LPCTSTR as a parameter. The parameter is a NULL terminated list of words separated by commas. For example,

   sc.AddKeyword("for,if,while", RGB(255,0,0), 4);
will add the three keywords to the sc object's list, give them the color red and place them in group 4, using the CHARFORMAT structure currently in m_cfDefault. You can also send a single word as the LPCTSTR parameter. If the keyword already exists in the list, its color and group attributes are overwritten by those passed in the AddKeyword method. The AddKeyword method that takes a CHARFORMAT as a parameter instead of a COLORREF works in a similar fashion.

A word about comments...

By default, CSyntaxColorizer deals with C++ and Java multiline comments starting with /* and single line comments starting with //. If you want single line comments as in VB, (starting with ' or REM), simply add "REM" as one of the keywords. For example:

    sc.AddKeyword("REM",cfMyStyle,nMyGroup);
CSyntaxColorizer will ignore any style or color settings you specify for the REM keyword, and instead will set them to whatever attributes you have set for the comments. CSyntaxColorizer will automatically treat the ' as the start of a single line comment once "REM" is added to the keyword list. Note: if you add only "REM", then "rem", "Rem", etc will not be recognized - you will have to add these as well.

Where a comment starts with // and ends with '\' + '\n' (the line continuation character immediately followed by a newline character) CSyntaxColorizer will recognize it, and treat the next line as a comment line.

[Back to Top]

Speed

CSyntaxColorizer is pretty fast. Small files under 20K or so are colorized practically instantaneously on my 466MHz machine. Larger files, over 100K, take four or five seconds. CSyntaxColorizer can locate and identify words to be colorized fairly quickly, but the big time hog is not in the algorithm itself - it's in the text formatting functions of CRichEditCtrl. If you comment out the two lines (line #494 & 495)

    pCtrl->SetSel(iStart,iOffset + x);
pCtrl->SetSelectionCharFormat(pskTemp->cf);
then a 100K file takes less than a second, but only comments and strings are colorized.

About the Demo

The demo project is a quick and dirty dialog box with a rich edit control. It has a rather crude editing capablity, the minimum required to show off some of CSyntaxColorizer's abilities. In particular, if you type in \* to start off a multiline comment, only the one line with the cursor on it will be reformatted. In this case, press the "Format" button. As well, you can load files, but you can't save them.

For those of you who don't have Visual C++ or just don't feel like compiling the thing, an executable is also available for download.

Downloads

ColorizerDemo.zip - 32 Kb VC++ project (includes all source code)
ColorizerDemo.exe - 32 Kb Windows executable file only

posted on 2008-04-30 21:48 楊粼波 閱讀(525) 評論(1)  編輯 收藏 引用

評論

# re: 一個有意思的給代碼染色的類:CSyntaxColorizer 2010-08-05 14:13 cosplay

I love your blog so much, and there are just some differences with others'. Hope there will be more wonderful things in your blog. .Happy every day!GFH  回復  更多評論   


只有注冊用戶登錄后才能發表評論。
網站導航: 博客園   IT新聞   BlogJava   博問   Chat2DB   管理


青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            最新日韩中文字幕| 久久久亚洲影院你懂的| 午夜欧美精品| 午夜亚洲伦理| 午夜视频一区| 午夜亚洲性色视频| 久久黄金**| 欧美激情无毛| 国产亚洲精品久| 国产精品激情电影| 国产精品欧美日韩一区| 国产精品一区二区在线观看网站| 国产精品入口| **性色生活片久久毛片| 亚洲激情av| 亚洲欧美电影在线观看| 欧美不卡一区| 亚洲一区自拍| 欧美日韩你懂的| 红桃视频成人| 亚洲伊人一本大道中文字幕| 欧美伊人影院| 99精品视频免费在线观看| 久久精品国产久精国产一老狼| 欧美日韩三区四区| 亚洲国产成人不卡| 欧美亚洲一区二区三区| 日韩亚洲成人av在线| 久久野战av| 影院欧美亚洲| 男女av一区三区二区色多| 亚洲欧美日韩综合| 欧美视频在线观看视频极品 | 久久久久久综合| 亚洲精品一区二区三区四区高清 | 蜜桃av噜噜一区二区三区| 国产一区二区在线观看免费| 亚洲综合久久久久| 亚洲淫性视频| 日韩午夜激情电影| 欧美国产精品久久| 亚洲精品视频一区二区三区| 欧美日韩高清不卡| 午夜在线视频观看日韩17c| 亚洲一区二区三区激情| 国产欧美在线看| 欧美大片免费久久精品三p | 欧美亚洲一区二区在线观看| 亚洲欧美综合v| 亚洲精品韩国| 亚洲美女网站| 国产一区亚洲一区| 亚洲精品一二区| 国产精品综合网站| 亚洲激情偷拍| 国产欧美一区在线| 亚洲国产婷婷| 国模一区二区三区| 夜夜嗨av一区二区三区中文字幕| 国产日韩亚洲欧美| 亚洲精品乱码久久久久久| 黄色一区二区在线观看| 亚洲精品一区久久久久久| 黄色成人精品网站| 亚洲专区一区| 在线一区亚洲| 欧美精品不卡| 亚洲人成小说网站色在线| 国产一区二区丝袜高跟鞋图片| 亚洲最新视频在线| 9色porny自拍视频一区二区| 欧美精品网站| 老牛国产精品一区的观看方式| 欧美激情1区2区| 99精品国产99久久久久久福利| 久久综合图片| 欧美劲爆第一页| 欧美成人午夜| 国产一区二区三区精品欧美日韩一区二区三区| 午夜一级在线看亚洲| 欧美性天天影院| 中文一区二区| 亚洲一区二区三区四区在线观看| 久久久综合精品| 久久中文精品| 亚洲国产高清一区| 欧美高清在线一区二区| 亚洲精品视频在线播放| 亚洲美女色禁图| 亚洲欧美国产毛片在线| 欧美日韩一区二区免费视频| 亚洲免费播放| 亚洲永久精品大片| 亚洲精品一区二区三区不| 亚洲激情一区二区| 亚洲免费观看| 国内成人精品2018免费看 | 久久久久久免费| 欧美成人一二三| 欧美有码在线视频| 99热精品在线| 亚洲福利在线看| 国产区亚洲区欧美区| 欧美国产1区2区| 欧美在线免费看| 国产精品成人久久久久| 欧美高清视频| 欧美日韩成人激情| 欧美日韩一区免费| 国产乱人伦精品一区二区| 国产一区二区高清不卡| 在线看成人片| 亚洲二区视频在线| 亚洲精品一二区| 亚洲色图自拍| 欧美在线视频一区二区| 久久综合九色九九| 亚洲人成绝费网站色www| 亚洲精品日本| 亚洲一二三区在线| 久久阴道视频| 欧美系列亚洲系列| 黄色国产精品| 在线一区二区三区四区| 美女图片一区二区| 亚洲欧美在线网| 国产美女精品一区二区三区| 免费亚洲电影| 亚洲无线一线二线三线区别av| 午夜激情综合网| 一区二区三区回区在观看免费视频| 欧美成人精品不卡视频在线观看 | 亚洲自拍另类| 国产精品美女久久福利网站| 狠狠狠色丁香婷婷综合久久五月| 欧美国产一区二区三区激情无套| 欧美精品电影| 国产亚洲欧美一区二区| 夜夜嗨av一区二区三区网页| 久久激情中文| aa级大片欧美| 欧美久久电影| 亚洲人成在线播放网站岛国| 久久成人免费| 欧美一级片在线播放| 久久久九九九九| 亚洲午夜久久久久久久久电影院 | 日韩视频专区| 免费久久99精品国产自| 久久精品国产久精国产一老狼 | 欧美一二区视频| 国产一区二区三区的电影| 久久久久久午夜| 欧美亚洲一级| 黑人中文字幕一区二区三区 | 午夜久久福利| 久久riav二区三区| 亚洲美女电影在线| 久久不射2019中文字幕| 999亚洲国产精| 亚洲国产另类久久精品| 欧美日韩在线播| 蜜桃av综合| 国产精品乱码人人做人人爱| 鲁大师成人一区二区三区| 欧美精品在线网站| 久久久久成人网| 国产精品久久久久久妇女6080 | 国产精品家教| 久久成人精品| 国产精品久久久久久久久久ktv| 久久夜色撩人精品| 国产精品成人aaaaa网站 | 欧美日韩一区成人| 欧美韩日一区二区| 国产一区二区日韩| 久久久国产精品亚洲一区| 欧美一区在线看| 亚洲福利在线视频| 国产精品成人在线| 欧美自拍偷拍| 亚洲国产精品精华液网站| 99精品国产在热久久下载| 国产精品一区一区| 久久综合给合久久狠狠色| 欧美激情精品久久久| 久久国产黑丝| 欧美先锋影音| 99re亚洲国产精品| 日韩小视频在线观看专区| 销魂美女一区二区三区视频在线| 亚洲二区三区四区| 久久久久一区二区三区四区| 久久久成人精品| 影音先锋久久| 久久经典综合| 蜜臀av性久久久久蜜臀aⅴ四虎| 国产欧美综合在线| 六十路精品视频| 夜夜精品视频|