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

牽著老婆滿街逛

嚴以律己,寬以待人. 三思而后行.
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>
            亚洲一区二区视频在线| 日韩视频免费在线| 99视频国产精品免费观看| 黄色精品免费| 国产日韩欧美一二三区| 国产区精品在线观看| 久久国产一区二区| 国产精品免费福利| 国产精品高潮呻吟视频| 国产日韩欧美高清免费| 伊人久久成人| 日韩亚洲欧美一区| 亚洲男人影院| 久久久久国产精品人| 巨乳诱惑日韩免费av| 欧美国产日韩一区二区| 夜夜精品视频一区二区| 欧美一区二区观看视频| 欧美不卡在线| 国产免费亚洲高清| 亚洲高清一区二| 亚洲一区二区精品在线| 老司机aⅴ在线精品导航| 亚洲精品欧美一区二区三区| 香蕉av777xxx色综合一区| 噜噜噜噜噜久久久久久91| 国产精品sm| 在线看片日韩| 亚洲欧美日韩精品在线| 欧美1区2区| 亚洲校园激情| 欧美激情成人在线| 国产一区三区三区| 亚洲综合国产激情另类一区| 欧美1区3d| 欧美专区第一页| 国产精品你懂的| 亚洲毛片av| 免费短视频成人日韩| 亚洲欧美日本精品| 欧美视频导航| 99精品视频网| 欧美激情中文字幕乱码免费| 欧美怡红院视频| 国产精品外国| 国产精品99久久99久久久二8| 欧美不卡在线视频| 久久精品国产第一区二区三区| 国产精品久久| 一本高清dvd不卡在线观看| 蘑菇福利视频一区播放| 久久不射网站| 狠狠色狠狠色综合日日tαg| 性做久久久久久久免费看| 99综合电影在线视频| 欧美精品综合| 日韩亚洲国产精品| 亚洲人体大胆视频| 欧美专区在线观看| 国外成人免费视频| 久久综合网络一区二区| 久久久www成人免费毛片麻豆| 国产视频久久久久| 久久精品国产综合精品| 99re6这里只有精品视频在线观看| 一区二区三区成人| 久久精品亚洲国产奇米99| 久久躁狠狠躁夜夜爽| 黄色亚洲在线| 久久亚洲一区二区| 久久视频在线免费观看| 亚洲国内欧美| 亚洲精品麻豆| 国产精品美女在线观看| 欧美主播一区二区三区| 欧美尤物巨大精品爽| 精品白丝av| 亚洲狠狠婷婷| 欧美性一区二区| 久久动漫亚洲| 久久综合五月| 中文国产亚洲喷潮| 性欧美精品高清| 亚洲高清不卡一区| 亚洲黄色成人久久久| 欧美日韩国产探花| 午夜精品视频一区| 欧美在线1区| 亚洲精品一区二区三区福利| 国产精品99久久久久久有的能看| 国产精品影视天天线| 欧美gay视频| 国产精品久久国产三级国电话系列| 亚洲主播在线播放| 久久免费视频网站| 亚洲深夜福利在线| 久久久久国产精品厨房| 亚洲伦理久久| 久久成年人视频| 99热在线精品观看| 欧美一区二区三区在线看| 99精品国产在热久久| 久久国产一区二区三区| 亚洲一级在线观看| 免费观看30秒视频久久| 欧美亚洲综合在线| 欧美日韩99| 老司机精品导航| 国产精品免费在线| 亚洲黄色片网站| 国产日韩欧美在线| 99精品视频免费观看| 亚洲福利视频一区二区| 性刺激综合网| 亚洲网址在线| 欧美电影免费观看高清完整版| 欧美综合77777色婷婷| 欧美日韩亚洲一区在线观看| 蜜臀91精品一区二区三区| 国产精品自拍视频| 一区二区日韩| 亚洲午夜久久久| 欧美日韩精品免费 | 一本色道久久综合亚洲精品小说| 午夜国产精品视频| 午夜天堂精品久久久久| 日韩视频在线一区二区| 欧美大片国产精品| 国内精品久久久久伊人av| 中日韩美女免费视频网址在线观看 | 欧美激情一区二区三区在线| 国产一区二区久久| 午夜精品一区二区在线观看| 午夜日韩av| 国产精品一区视频| 欧美一级专区| 久久综合狠狠综合久久激情| 韩国一区二区三区在线观看 | 欧美高清不卡| 亚洲国产精品成人一区二区| 亚洲国产精品激情在线观看| 久热re这里精品视频在线6| 久久久女女女女999久久| 国产日韩专区在线| 欧美一区二区三区在线观看| 久久男女视频| 亚洲国产清纯| 免播放器亚洲一区| 亚洲精品一区在线| 亚洲自拍偷拍视频| 国产欧美日韩精品丝袜高跟鞋| 欧美亚洲在线播放| 欧美成人嫩草网站| 99在线精品观看| 国产精品vip| 欧美在线精品免播放器视频| 模特精品裸拍一区| 亚洲视频在线一区| 国产深夜精品| 欧美韩日亚洲| 亚洲免费伊人电影在线观看av| 欧美中文字幕久久| 亚洲国产日韩一区| 欧美日韩另类在线| 欧美一区视频在线| 亚洲激情不卡| 久久国产精品色婷婷| 亚洲激情综合| 国产精品午夜电影| 免费不卡亚洲欧美| 亚洲一区区二区| 欧美岛国在线观看| 亚洲免费一在线| 在线看一区二区| 国产精品久久久久91| 久热精品视频在线免费观看| 亚洲视频综合| 欧美国产高潮xxxx1819| 亚洲欧美怡红院| 亚洲三级性片| 韩国精品一区二区三区| 欧美日韩国产成人| 久久国产日本精品| av成人手机在线| 欧美夫妇交换俱乐部在线观看| 在线视频你懂得一区二区三区| 国产一区二区三区在线观看网站| 欧美日韩第一区日日骚| 久久久人成影片一区二区三区| 日韩视频一区二区三区| 六月婷婷久久| 欧美精品成人一区二区在线观看| 欧美插天视频在线播放| 日韩一本二本av| 黄网动漫久久久| 国产精品一区二区三区四区| 欧美精品免费在线| 久久先锋影音| 欧美在线999| 亚洲影视中文字幕|