锐英源软件
第一信赖

精通

英语

开源

擅长

开发

培训

胸怀四海 

第一信赖

当前位置:锐英源 / 开源技术 / C++开源英语 / 颜色自由定制Edit控件
服务方向
人工智能数据处理
人工智能培训
kaldi数据准备
小语种语音识别
语音识别标注
语音识别系统
语音识别转文字
kaldi开发技术服务
软件开发
运动控制卡上位机
机械加工软件
软件开发培训
Java 安卓移动开发
VC++
C#软件
汇编和破解
驱动开发
联系方式
固话:0371-63888850
手机:138-0381-0136
Q Q:396806883
微信:ryysoft

颜色自由定制Edit控件

Introduction

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%的原始代码后,我认为我有足够的东西可以使用。所以,就有了现在的成果。

What it does它能做什么

  • Text editing. That's right, you can use it to edit text.
  • Syntax highlighting. Well, more specifically, it can color the text in any way you tell it to. It's up to you (the programmer) to tell it how to color things. It has built-in "keyword" support, but anything more complex than simple word matching is something you'll have to do yourself (which is no big surprise, since there's no way I could possibly know all the different syntaxes people might want to use this with). The sample code shows how to do some simple things aside from just the keyword matching.
  • Full undo/redo support. Just like the VC++ editor, you can undo all the way back to the start and redo all undo's from the last edit.
  • Auto scroll support.
  • Flicker-free scrolling
  • Variable character and line spacing
  • Full select, copy, cut, paste support, with keyboard accelerators and a context menu.
  • Mouse wheel support. Vertical only.
  • 文字编辑。没错,你可以用它来编辑文字。
  • 语法突出显示。嗯,更具体地说,它可以以你告诉它的任何方式为文本着色。由你(程序员)来告诉它如何着色。它具有内置的“关键字”支持,但是比任何简单的单词匹配更复杂的东西都是你必须自己做的事情(这并不是什么大惊喜,因为我无法知道人们用这个来支持的可能想要的所有不同的语法)。示例代码显示了除了关键字匹配之外如何做一些简单的事情。
  • 完全撤消/重做支持。就像VC ++编辑器一样,您可以一直撤消到开始并重做上次编辑中的所有撤消操作。
  • 自动滚动支持。
  • 无闪烁滚动
  • 可变字符和行间距
  • 全键选择,复制,剪切,粘贴支持,键盘快捷键表和上下文菜单。
  • 鼠标滚轮支持。仅垂直。

What it doesn't do不做什么

  • Variable-width font support. This only works with fixed width fonts. I needed a code editor, not a word processor. Adding variable width font support would be a huge undertaking and I'm not interested in doing it.
  • It's not CEdit. Nope, it's a different control altogether. It's not derived from CEdit and it's not a drop-in replacement. It can do many of the same things, but it does them differently. For example, this is a line-based editor; so to set the selection range, you need to specify lines, not just characters like with CEdit.
  • Boring scroll bars. Scroll bar thumb sizing could use some work.
  • Unicode. I don't need it.
  • There might be bugs! Yep, you heard it here first - there might be a bug or two in here. Feel free to let me know if you find anything. Even better, feel free to fix it and tell me what you did. I'll keep the source updated.
  • 可变宽度字体支持。这仅适用于固定宽度字体。我需要一个代码编辑器,而不是文字处理器。添加可变宽度字体支持将是一项艰巨的任务,我对此并不感兴趣。
  • 不但但是CEdit。不,这完全是一个不同的控件。它不是源于CEdit它,也不是替代品。它可以做许多相同的事情,但它会以不同的方式做到。例如,这是一个基于行的编辑器; 所以要设置选择范围,你需要指定行,而不仅仅是像CEdit。
  • 无聊的滚动条。滚动条拇指大小可以起作用。
  • Unicode格式。我不需要它。
  • 可能有错误!是的,你先在这里听到了 - 这里可能有一两个bug。如果您发现任何问题,请随时告诉我。更好的是,随时修理它并告诉我你做了什么。我会保持更新源。

What does the sample do?示例功能?

  • Load and save a text file.
  • Keywords. The sample has a small keyword file ("while", "if", "else", and "for"). These words will be highlighted automatically.
  • The sample colorizer shows off some special syntax handling for the following symbols:
    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
  • 加载并保存文本文件。
  • 关键词。该示例包含一个小关键字文件(“while”,“if”,“else”和“for”)。这些单词将自动突出显示。
  • 示例着色器显示以下符号的一些特殊语法处理:
    符号 规则 颜色
    #text 任何以“#”开头的行都是注释 绿色
    @ + 必须是该行上唯一的文字 蓝色,但如果线上有任何其他文字,则为红色
    @ - 必须是该行上唯一的文字 蓝色,但如果线上有任何其他文字,则为红色
    @:文本 必须在行的开头 红色

How to use it in your app如何在您的应用中使用它

  1. 1、Add these files to your project:将这些文件添加到项目中:
    • ColorEditWnd.cpp.h
    • Colorizer.cpp.h
    • ScriptText.cpp.h
    • UndoFrame.cpp.h
    • 2、Copy the IDR_COLOREDITCTX context menu from the sample into your app. 将IDR_COLOREDITCTX示例中的上下文菜单复制到您的应用中。
    • 3、Copy the IDR_EDIT_ACCELS accelerators from the sample into your app. 将IDR_EDIT_ACCELS样本中的快捷键表复制到您的应用中。
    • 4、Add a ColorEditWnd* member to your dialog class. 将ColorEditWnd*成员添加到对话框类。
    • 5、Add a new resource ID for the control. Go to the resource editor, right-click on your project's resource file. Choose "Resource Symbols". Add a new symbol ID_EDIT_WND. 为控件添加新的资源ID。转到资源编辑器,右键单击项目的资源文件。选择“资源符号”。添加新符号ID_EDIT_WND。
    • 6、Initialize the object in your dialog's OnInitDialog: 在对话框中初始化对象OnInitDialog:
    • 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
    • 7、Delete the object in the dialog destructor对话框析构函数中删除对象

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)来处理关键字着色。

API

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);

 

友情链接
版权所有 Copyright(c)2004-2021 锐英源软件
公司注册号:410105000449586 豫ICP备08007559号 最佳分辨率 1024*768
地址:郑州大学北校区院(文化路97号院)内