⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 color_edit.shtml.htm

📁 mfc资料集合5
💻 HTM
字号:
<HTML>
<HEAD>
   <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
   <META NAME="Author" CONTENT="Zafir Anjum">
   <TITLE>Miscellaneous - Keyword coloring Edit control</TITLE>
</HEAD>
<body background="../fancyhome/back.gif" tppabs="http://www.codeguru.com/fancyhome/back.gif" bgcolor="#FFFFFF" link="#B50029" vlink="#8E2323" alink="#FF0000" bgproperties="fixed">
<table WIDTH="100%">
<tr WIDTH="100%">
<td><A HREF="http://209.66.99.126/cgi/ads.cgi?advert=myad2"><IMG SRC="../../209.66.99.126/advertise2.gif" tppabs="http://209.66.99.126/advertise2.gif" ALT="" BORDER=2></A><td>
</tr>
</table>


<CENTER>
<H3>
<FONT COLOR="#AOAO99">Keyword coloring Edit control</FONT></H3></CENTER>

<HR>



<P>This article was contributed by <A HREF="mailto:keithr@europa.com">Keith Rule</A>. 
<P><A HREF="coloredit.zip" tppabs="http://www.codeguru.com/misc/coloredit.zip">Download</A> the project. 238KB. Note that this is still work in progress and Keith is open to suggestions. This project requires VC++ 5.0 or later, don't expect to have an easy time of build this project under VC++ 4.2 or earlier. </P>

<B><FONT FACE="Arial" SIZE=4><P>About The Project</P>
</B></FONT><P>This project implements a simple color encoding text editor, which is similar to the editor found in Visual C++ or Visual Basic. It allows the developer to configure the encoding of keywords and comments. This project is an MDI application.</P>
<P><IMG SRC="coloredit_Image12.gif" tppabs="http://www.codeguru.com/misc/coloredit_Image12.gif"></P>
<B><FONT FACE="Arial" SIZE=4><P>Defining the Color Encoding</P>
</B></FONT><P>The encoding is defined in the constructor for the <I>CDocument</I> derived class <I>CColorEditDoc</I>. The default configuration looks like the following:</P><DIR>
<DIR>

<FONT COLOR="#990000"><PRE>CColorEditDoc::CColorEditDoc() : CUndo(25, 64*1024)
{
&#9;m_text.AddComment(_T("/*"), _T("*/"));
&#9;m_text.AddComment(_T("//"), _T("\n"));
&#9;m_text.AddKeyword(_T("static"));
&#9;m_text.AddKeyword(_T("char"));
&#9;m_text.AddKeyword(_T("short"));
&#9;m_text.AddKeyword(_T("unsigned"));
&#9;&#9;.
&#9;&#9;.
&#9;&#9;.
}</PRE></DIR>
</DIR>

</FONT><P>The definitions for defining a keyword or comment are as follows.</P>
<PRE>&#9;<FONT COLOR="#990000">// Color Coding
&#9;BOOL AddKeyword(const CString&amp; keyword, COLORREF color = RGB(0, 0, 200));
&#9;BOOL AddComment(const CString&amp; begin = _T("//"), const CString&amp; end = _T("\n"), COLORREF color = RGB(0, 200, 0)); </PRE>
</FONT><FONT SIZE=2><P>Notice that you can specify a unique color for every keyword and comment definition.</P>
</FONT><B><FONT FACE="Arial" SIZE=4><P>Goals of the Project</P>
</B></FONT><FONT SIZE=2><P>I wrote this project for three reasons. </P>
<OL>

<LI>I wanted to try out several of the classes found on the </FONT><A HREF="../index.htm" tppabs="http://www.codeguru.com/"><FONT SIZE=2>www.codeguru.com</FONT></A><FONT SIZE=2> webpage.</LI>
<LI>I wanted try out a real example of a worker thread.</LI>
<LI>I wanted to have a Color Encoding Text Editor in my toolbox of royalty free source code.</LI></OL>

<P>However, this project has turned into my toolbox. I've placed many often used techniques in this project such as printing support, cut/copy/paste support, undo/redo, flicker free updates and so forth. I've found myself using the project as a place to pull working code out into other projects. </P>
</FONT><B><FONT FACE="Arial" SIZE=4><P>New Features</P>
</B></FONT><FONT SIZE=2><P>Dragging during a selection will now scroll the window. I've fixed several problems and have one know unresolved bug. Color encoding quotes is now supported.</P>
</FONT><B><FONT FACE="Arial" SIZE=4><P>Known Bugs</P>
</B></FONT><FONT SIZE=2><P>The editor won't scroll beyond 1500 lines on Win95. I suspect this is due to a limitation in the size of the GDI area in MM_TEXT. If anyone has some ideas for working around this, please let me know.</P>
</FONT><B><FONT FACE="Arial" SIZE=4><P>Classes Used</P>
</B></FONT><FONT SIZE=2><P>This project uses the following classes found at www.codeguru.com. </P>
</FONT><B><I><TT><PRE>
CUndo</B></I> - Undo/Redo for <I>CDocument</I> derived classes
<B><I>CMemDC</B></I> - Double buffering class for drawing
<B><I>CSplash255Wnd</B></I> - 256 color splash screen support
<B><I>CToolBarEx</B></I> - Flat toolbar support
<B><I>CRegExp</B></I> - Regular Expression matching
<B><I>CStringEx</B></I> - Extended <I>Cstring
<B>CProgressBar </B></I>- A progress indicator on the status bar.
<B><I>CClockStatusBar</B> </I>- Adds a clock to the status bar.
<B><I>CCreditStatic </B></I>- Scrolls text in a static text field.</PRE>
</TT><FONT SIZE=2><P>In addition it defines the class: </P><DIR>

<B><I><P>CColorString</B></I> - </FONT><I><FONT FACE="Courier New" SIZE=2>CString</I> plus rule based color encoding</FONT><FONT SIZE=2> </P></DIR>

<P>I'm open to adding change request to my ToDo list for this application. Feel free to contact me at </FONT><A HREF="mailto:keithr@europa.com"><FONT SIZE=2>keithr@europa.com</FONT></A><FONT SIZE=2> with suggestions, fixes, or questions.</P>
</FONT><P>












<P>
<HR>
<TABLE BORDER=0 WIDTH="100%" >
<TR>
<TD WIDTH="33%"><FONT SIZE=-1><A HREF="../index.htm" tppabs="http://www.codeguru.com/">Goto HomePage</A></FONT></TD>

<TD WIDTH="33%">
<CENTER><FONT SIZE=-2>&copy; 1997 Zafir Anjum</FONT>&nbsp;</CENTER>
</TD>

<TD WIDTH="34%">
<DIV ALIGN=right><FONT SIZE=-1>Contact me: <A HREF="mailto:zafir@home.com">zafir@home.com</A>&nbsp;</FONT></DIV>
</TD>
</TR>
</TABLE>
<CENTER><FONT SIZE=-2>9028</FONT></CENTER>
</BODY>
</HTML>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -