//========================================================================
  //TITLE:
  //    MiniUtilityFramework(九):CText和TEXT
  //AUTHOR:
  //    norains
  //DATE:
  //    Wednesday 26-March-2009
  //Environment:
  //    VISUAL STUDIO 2005 + WINDOWS CE 5.0
  //========================================================================
  
  CText和微软的Static Control类似,都是用以显示文字信息。最大的不同,可能就在于CText能更方便设置字体的信息,比如:大小,颜色等等。
  
  CText的public接口比较多,不过大多数都只是用来设置文字显示的形式:

class CText { public: //-------------------------------------------------------------------- //Description: // Set all the property for the control // //--------------------------------------------------------------------- BOOL SetProperty(const Text::Property &Property); //-------------------------------------------------------------------- //Description: // Get all the property of the control // //--------------------------------------------------------------------- Text::Property GetProperty(); //-------------------------------------------------------------------- //Description: // Set the strikeOut // //--------------------------------------------------------------------- void SetStrikeOut(BOOL bStrikeOut); //-------------------------------------------------------------------- //Description: // Set the underline // //--------------------------------------------------------------------- void SetUnderline(BOOL bUnderline); //-------------------------------------------------------------------- //Description: // Set the italic // //--------------------------------------------------------------------- void SetItalic(BOOL bItalic); //-------------------------------------------------------------------- //Description: // Specifies the weight of the font in the range 0 through 1000. For example, //400 is normal and 700 is bold. If this value is zero, a default weight is used. // //--------------------------------------------------------------------- BOOL SetWeight(int iWeight); //-------------------------------------------------------------------- //Description: // Get the position as rect // //--------------------------------------------------------------------- RECT GetPosition(); //-------------------------------------------------------------------- //Description: // Set the point size of text // //--------------------------------------------------------------------- void SetPointSize(int iPointSize); //-------------------------------------------------------------------- //Description: // Set Format. // //Parameters: // The value you should see the uFormat of DrawText() //-------------------------------------------------------------------- void SetFormat(UINT uFormat); //-------------------------------------------------------------------- //Description: // Set the background color // //-------------------------------------------------------------------- void SetBkColor(COLORREF crColor); //-------------------------------------------------------------------- //Description: // Set the text color // //-------------------------------------------------------------------- void SetTextColor(COLORREF crColor); //-------------------------------------------------------------------- //Description: // Set the background mode. // //Parameters: // iMode: [in] The value is just like as follow: // OPAQUE -- Background is filled with the current background color before the text, // hatched brush, or pen is drawn. // TRANSPARENT -- Background remains untouched. //-------------------------------------------------------------------- BOOL SetBkMode(int iMode); //-------------------------------------------------------------------- //Description: // Display the text stored. // //-------------------------------------------------------------------- void Draw(HDC hdc); //-------------------------------------------------------------------- //Description: // Set the text. If you want to display the text ,you should call the Display() // //-------------------------------------------------------------------- BOOL SetText(const TSTRING &strText); //-------------------------------------------------------------------- //Description: // Set the control position // //-------------------------------------------------------------------- void SetPosition(const RECT &rcWndPos); //-------------------------------------------------------------------- //Description: // Get the text. // //-------------------------------------------------------------------- TSTRING GetText(); //-------------------------------------------------------------------- //Description: // Set font face name // //-------------------------------------------------------------------- BOOL SetFaceName(const TSTRING &strFaceName); public: CText(); virtual ~CText(); private: Text::Property m_Property;

配置文件可选的字段也不少,但并不复杂:

TYPE:类型,取值必须为TEXT,标明当前控件为TEXT
  
  RECT_POS:该控件在窗口的位置。
  
  POINT_SIZE:字体的大小。
  
  WEIGHT:粗细,取值为0~900。
  
  FORMAT:格式。取值和DrawText的uFormat参数的一致,有如下类型(取自DrawText的说明文档):
    
    DT_BOTTOM         Justifies the text to the bottom of the rectangle. You must combine this value with DT_SINGLELINE.
    
    DT_CALCRECT       Determines the width and height of the rectangle. If the rectangle includes multiple lines of text, DrawText uses the width of the rectangle pointed to by the lpRect parameter and extends the base of the rectangle to bound the last line of text. If the rectangle includes only one line of text, DrawText modifies the right side of the rectangle so that it bounds the last character in the line. In either case, DrawText returns the height of the formatted text but does not draw the text. Before calling DrawText, an application must set the right and bottom members of the RECT structure pointed to by lpRect. These members are updated with the call to DrawText.  
    
    DT_CENTER         Centers text horizontally in the rectangle.
    
    DT_END_ELLIPSIS   Truncates a text string that is wider than the display rectangle and adds an ellipsis to indicate the truncation.
    
    DT_EXPANDTABS     Expands tab characters. The default number of characters per tab is eight. 
    
    DT_INTERNAL       Uses the system font to calculate text metrics. 
    
    DT_LEFT           Aligns text to the left.
    
    DT_NOCLIP         Draws without clipping. DrawText is somewhat faster when DT_NOCLIP is used.
    
    DT_NOPREFIX       Turns off processing of prefix characters. Normally, DrawText interprets the mnemonic-prefix character & as a directive to underscore the character that follows, and the mnemonic-prefix characters && as a directive to print a single &. By specifying DT_NOPREFIX, this processing is turned off.
    
    DT_RIGHT          Aligns text to the right.
    
    DT_RTLREADING     Layout in right-to-left reading order for bi-directional text when the font selected into the hdc is a Hebrew or Arabic font. The default reading order for all text is left-to-right.
    
    DT_SINGLELINE     Displays text on a single line only. Carriage returns and linefeeds do not break the line.
    
    DT_TABSTOP        Sets tab stops. Bits 8–15, which form the high-order byte of the low-order word, of the uFormat parameter specify the number of characters for each tab. The default number of characters per tab is eight. You cannot use the DT_CALCRECT, DT_EXTERNALLEADING, DT_INTERNAL, DT_NOCLIP, and DT_NOPREFIX values with the DT_TABSTOP value.
    
    DT_TOP            Top-justifies text. You must combine this value with DT_SINGLELINE.
    
    DT_VCENTER        Centers text vertically. You must combine this value with DT_SINGLELINE.
    
    DT_WORD_ELLIPSIS  Truncates any word that does not fit in the display rectangle and adds an ellipsis.
    
    DT_WORDBREAK      Breaks words. DrawText automatically breaks lines between words if a word would extend past the edge of the rectangle specified by the lpRect parameter. A carriage return-linefeed sequence also breaks the line.
  
  COLOR:文本的颜色
  
  TRANSPARENT_MODE:决定背景是否透明。取值为TRUE或FALSE。当为FALSE时,背景颜色为TRANSPARENT_COLOR所确定的数值。
  
  STRING:连接的字符串
  
  FONT_FACE_NAME:字体。注意,该字段指的不是字体的文件名,而是字体名。也就是说,该字段取值不会是FONT的KEY值。该数值可以通过CCommon::GetFontNameFromFile读取相应的字体文件来获得。
  
  ITALIC:斜体
  
  UNDERLINE:下划线
  
  STRIKEOUT:删除线
  
  
  配置文件的字段,和Text::Property中的变量基本上是对应:
  
  namespace Text
  {
   struct Property
   {
    RECT rcWndPos; 
    TSTRING strText;
    UINT uFormat;
    int iPointSize;
    int iBkMode;
    COLORREF crTextColor;
    COLORREF crBkColor;
    int iWeight;
    BOOL bItalic;
    BOOL bUnderline;
    BOOL bStrikeOut;
    TSTRING strFaceName;
   };
  }
  
  如果CText的使用仅仅是用来显示相应的信息,并不打算在代码中对显示信息进行变更,可以在配置文件中设置STRING字段的指向,不仅能够方便地显示文字,还能在调用SetCurLanguage后自动变更显示的内容。如果需要在代码中进行操控,我们只需要通过GetText函数获取相应的对象,然后再调用SetText函数即可:
  
  CText *pText = GetText(TEXT("TXT_EXIT"));
  pText->SetText(TEXT("退出"));
  
  这是一个随着语言的不同,显示不同语言的“导航”的例子:
  [TXT_TITLE_NAVI]
  TYPE=TEXT
  RECT_POS=11,8,162,39
  POINT_SIZE=26
  WEIGHT=700
  FORMAT=DT_LEFT|DT_SINGLELINE|DT_VCENTER
  COLOR=0,255,0
  TRANSPARENT_MODE=TRUE
  FONT_FACE_NAME=kaiti_GB2312
  STRING=STR_NAVI
  
  [STR_NAVI]
  TYPE=STRING
  EN="NAVI"
  CHS="导航"
  CHT="導航"

MiniUtilityFramework(九):CText和TEXT相关推荐

  1. JavaFX UI控件教程(九)之Text Field

    翻译自   Text Field 本章讨论文本字段控件的功能. 的TextField类实现接受并显示文本输入的UI控制.它提供了从用户接收文本输入的功能.与另一个文本输入控件一起,PasswordFi ...

  2. IP-Address TextBox

    http://www.codeproject.com/Articles/4693/IP-Address-TextBox 可以下载试用效果.个人感觉功能很强大,但输入时让人不太舒服.可以参考. ntro ...

  3. Paper:《NÜWA: Visual Synthesis Pre-training for Neural visUal World creAtion,女娲:用于神经视觉世界创造的视觉》翻译与解读

    Paper:<NÜWA: Visual Synthesis Pre-training for Neural visUal World creAtion,女娲:用于神经视觉世界创造的视觉>翻 ...

  4. CSS中的text-shadow。

    text-shadow(文字投影),box-shadow(容器投影),border-radius(圆角)这三个属性估计以后用的比较多,记录 一下.目前不支持IE系列(不过可以使用其他方法实现,下文有详 ...

  5. CSS3-文本-text-shadow

    一.text-shadow 语法: text-shadow : none | <length> none | [<shadow>, ] * <shadow> 或no ...

  6. 搭建asp会议签到系统 第三章 会议签到

    搭建asp会议签到系统 第一章 账密登录 第二章 生成会议签到二维码 第三章 会议签到 第四章 会议统计 第三章 会议签到 搭建asp会议签到系统 前言 一.制作checkin前端页面 二.读取并展示 ...

  7. NLP实践——以T5模型为例训练seq2seq模型

    NLP实践--以T5模型为例训练seq2seq模型 0. 介绍 1. 数据下载与加载 2. 创建模型 3. 训练评估函数 4. 模型训练 5. 模型预测 0. 介绍 回顾这两年NLP领域的研究,生成式 ...

  8. VB.NET绘图8---总结

    <VB.NET 绘图基础>吧,因为篇幅实在有点长,计划分成:Graphics章.Pen章.Brush章.Text章.由于涉及到的内容比较多,加之包含比较多的实例代码,所以根据内容的长短把每 ...

  9. 模板引擎Thymeleaf?来这一篇就够用了

    写在前面 模板页面中的 html 上需要声明 Thymeleaf 的命名空间,具体代码如下 <html xmlns:th="http://www.thymeleaf.org" ...

  10. asp毕业设计——基于asp+sqlserver的酒店预定管理系统设计与实现(毕业论文+程序源码)——酒店预定管理系统

    基于asp+sqlserver的酒店预定管理系统设计与实现(毕业论文+程序源码) 大家好,今天给大家介绍基于asp+sqlserver的酒店预定管理系统设计与实现,文章末尾附有本毕业设计的论文和源码下 ...

最新文章

  1. R语言attributes函数(获取属性、设置属性)、attr函数(改变一个属性)、structure函数(改变数据形状)实战
  2. [Python]数据类型、常量、变量和运算符(未完待续)
  3. 波束管理 Beam Management
  4. nrf51822笔记之密码配对过程梳理
  5. 漫画:凌晨2点,老板在工作群@了我...
  6. LeNet-5——CNN经典网络模型详解(pytorch实现)
  7. wordpress 后台慢_WordPress网站优化加速的5个技巧
  8. .Net 3.0 项目与.Net4.0项目之间互相引用的问题.
  9. 天猫魔盘在 deepin-linux中的使用
  10. 为什么Word打印预览的跟实际的不一样呢
  11. kuangbin 简单搜索 A 棋盘问题
  12. python批量发送邮件_EDM营销算法:python自动批量发邮件
  13. 电脑pin码忘了登录不进系统_忘记计算机 PIN 码怎么办?
  14. 关闭windows defender安全中心的方法
  15. 20145236 《Java程序设计》第4周学习总结
  16. 《云边有个小卖部》的优秀读后感作文2100字
  17. 经验 | 本硕985回忆研究生这三年
  18. WORD: 如何在一个word里文档里创建多个目录?
  19. 介绍Namada:链间资产不可知(Asset-agnostic)隐私
  20. python pandas 分类汇总_pandas去重复行并分类汇总的实现方法

热门文章

  1. HackMyvm(九)Gigachad持续更新
  2. python井字格游戏_python实现简单井字棋游戏
  3. 微信小程序申请微信支付0.2费率商户号微信小程序接入开通流程
  4. servlet003:监听器
  5. Android图片转化黑白图片,图像二值化,生成图像二值化后的黑白图像和图像矩阵(无压缩0,1矩阵),可灵活设置二值化值域
  6. 线性电阻软件的伏安特性曲线测试,线性电阻和非线性电阻的伏安特性曲线
  7. 关于企业微信二次开发
  8. 输入一个字符,判断该字符是大写英文字符,小写英文字符,空格,还是其他字符
  9. [翻译] LaTeX Error: Can be used only in preamble
  10. Lookup 组件用法全解