MiniUtilityFramework(九):CText和TEXT

  //========================================================================
  //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接口比较多,不过大多数都只是用来设置文字显示的形式:

 

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

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值