转载自:http://blog.csdn.net/norains/article/details/3957123

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="導航"

转载于:https://www.cnblogs.com/hao507/articles/2276502.html

【转载】MiniUtilityFramework(九):CText和TEXT相关推荐

  1. 转载——背包九讲(原文链接已不可考)

    浙大崔添翼对背包问题的讲解,观点很高也很深刻,特此转载. 背包九讲 目录  第一讲 01背包问题  第二讲 完全背包问题  第三讲 多重背包问题  第四讲 混合三种背包问题  第五讲 二维费用的背包问 ...

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

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

  3. CSS中的text-shadow。

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

  4. CSS3-文本-text-shadow

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

  5. 史诗般的数据提取任务

    Special thanks to the person on twitter who messaged me with this question and is letting me use it ...

  6. jira 史诗 故事 任务_史诗般的数据提取任务

    jira 史诗 故事 任务 Special thanks to the person on twitter who messaged me with this question and is lett ...

  7. 如何避免自由软件项目中的需求变更

    Photo by John Schnobrich on Unsplash John Schnobrich在Unsplash上的照片 A decade ago, when I signed up on ...

  8. python文本编辑器_python最好的ide和文本编辑器

    python文本编辑器 I cannot stress enough how important the right IDE (Integrated Development Environment) ...

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

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

  10. CSS3的文字阴影—text-shadow

    前段时间整理了CSS3中的渐变Gradient.透明度RGBA.边框圆角box-radius三个新属性的使用方法,这几次继续整理了有关于CSS3的text-shadow的使用方法.今天特意花了点时间贴 ...

最新文章

  1. (转)PHP框架大比武
  2. PostgreSQL 10.1 手册_前言_2. PostgreSQL简史
  3. python基础代码事例-python基础第三章
  4. Spring MVC 拦截器 interceptor 详解
  5. Vue body样式修改
  6. springboot page size过大导致内存溢出_Spring Boot 内存泄露怎么办呢?看这里看这里!!...
  7. CentOS 6.0安装ipvsadm 1.26错误笔录
  8. IBM计划未来四年在美聘用2000名退伍军人
  9. 扯淡!C语言怎么可能被淘汰呢?
  10. 对话框弹出的位置引发的问题showdialog
  11. PGM:部分有向模型之条件随机场与链图模型
  12. 声音文件格式、常见的数字音频格式
  13. 32位计算机装64位操作系统,电脑装32位还是64位系统与硬件有关系吗
  14. Netlink的简单例子
  15. JavaScript面向对象学习深拷贝、浅拷贝(三)
  16. 社交网络中的Link Prediction
  17. Pandas详解十之Dropna滤除缺失数据
  18. webassmbly blazor实现多页签效果
  19. 进入社会看到的一片总结,若有感慨
  20. vulfocus复现:Log4j2远程命令执行2

热门文章

  1. Autojs微信研究:微信自动发送信息机器人最终成品(有效果演示)
  2. Ubuntu Qt 无法覆盖文件 错误解决方法
  3. c语言水电费系统,急求C水电费管理系统
  4. java列名无效_Java:列名无效
  5. openCV 简单实现身高测量(未考虑相机标定,windows)
  6. 使用ARKit编写测量应用程序代码:交互和测量
  7. 程序员年薪30万,被准丈母娘各种刁难,网友说:分手吧!
  8. MFC使用自带的MSXML6.dll解析xml(开发环境vc2010)
  9. Python:计算KDJ指标
  10. 中文句法分析_句法分析StanfordParser+依存句法分析pyhanlp