DrawText函数与TextOut函数的区别

来源:互联网 发布:淘宝苹果主板哪里来的 编辑:程序博客网 时间:2024/05/29 23:24
TextOut function:The TextOut function writes a character string at the specified location, using the currently selected font, background color, and text color.

BOOL TextOut(
HDC hdc, // 设备描述表句柄
int nXStart, // 字符串的开始位置 x坐标
int nYStart, // 字符串的开始位置 y坐标
LPCTSTR lpString, // 字符串
int cbString // 字符串中字符的个数
);
 The interpretation of the reference point depends on the current text-alignment mode. An application can retrieve this mode by calling the GetTextAlign function; an application can alter this mode by calling theSetTextAlign function. You can use the following values for text alignment. Only one flag can be chosen from those that affect horizontal and vertical alignment. In addition, only one of the two flags that alter the current position can be chosen.

 By default, the current position is not used or updated by this function. However, an application can call theSetTextAlign function with the fMode parameter set to TA_UPDATECP to permit the system to use and update the current position each time the application calls TextOut for a specified device context. When this flag is set, the system ignores the nXStart and nYStart parameters on subsequent TextOut calls.

 When the TextOut function is placed inside a path bracket, the system generates a path for the TrueType text that includes each character plus its character box. The region generated is the character box minus the text, rather than the text itself. You can obtain the region enclosed by the outline of the TrueType text by setting the background mode to transparent before placing the TextOut function in the path bracket. Following is sample code that demonstrates this procedure.

  DrawText function:The DrawText function draws formatted text in the specified rectangle. It formats the text according to the specified method (expanding tabs, justifying characters, breaking lines, and so forth).

int DrawText(HDC hDC, // 设备描述表句柄
LPCTSTR lpString, // 将要绘制的字符串
int nCount, // 字符串的长度
LPRECT lpRect, // 指向矩形结构RECT的指针
UINT uFormat // 正文的绘制选项
);
http://wenku.baidu.com/link?url=8rXg6Zu9zg2KUli03G5em2TuZUj73wQzLCoORcd9M1CslZ77psB0883a_o3WA3y3YSfxQmdqRHE047lmzsC3X0Y6y_YJsMdjqyfDO8jm403

  The DrawText function uses the device context's selected font, text color, and background color to draw the text. Unless the DT_NOCLIP format is used, DrawText clips the text so that it does not appear outside the specified rectangle. Note that text with significant overhang may be clipped, for example, an initial "W" in the text string or text that is in italics. All formatting is assumed to have multiple lines unless the DT_SINGLELINE format is specified.

  To specify additional formatting options, use the DrawTextEx function.

  If the selected font is too large for the specified rectangle, the DrawText function does not attempt to substitute a smaller font.

  The text alignment mode for the device context must include the TA_LEFT, TA_TOP, and TA_NOUPDATECP flags.            

  二者的区别与联系:DrawText其实在内部也调用TextOut的,不过它作了很多内部处理,功能更大一些,比如:TextOut就不支持换行符,而DrawText就支持换行符。所以如果想多行输出,用DrawText肯定要比TextOut要好得多。

  DrawText函数与TextOut函数都是文本输出函数,DrawText函数是格式化输出函数,而TextOut函数不具备这样的功能。可以让文本输出时左对齐,或者右对齐,或者中间对齐,还可以让文本适应输出矩形内,如果超出时可以截断,或者显示为省略号的方式。DrawText函数在表格方式显示时肯定要使用到的函数。




0 0