Windows API——TextOut()函数学习

1.函数功能

The TextOut function writes a character string at the specified location, using the currently selected font, background color, and text color.

TextOut函数使用当前选定的字体、背景颜色和文本颜色在指定位置写入字符串。

2.函数原型

BOOL TextOutA( HDC hdc, int x, int y, LPCSTR lpString, int c );(普通字符)

BOOL TextOutW( HDC hdc, int x, int y, LPCWSTR lpString, int c );(宽字符)

参数:

hdc:当前DC句柄。

x:指定用于字符串对齐的基准点的逻辑x坐标

y:指定用于字符串对齐的基准点的逻辑y坐标

lpString:A pointer to the string to be drawn. The string does not need to be zero-terminated(不必以\0结尾), because cchString specifies the length of the string.

c:指定字符串的长度。

返回值:

If the function succeeds, the return value is nonzero.

If the function fails, the return value is zero.

3.备注

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 the SetTextAlign function. 

可以使用以下值进行文本对齐。 (只能从影响水平和垂直对齐的标志中选择一个标志。只能选择改变当前位置的两个标志中的一个。)

参数值 描述
TA_BASELINE 参考点将位于文本的基线上。
TA_BOTTOM 参考点将位于边界矩形的底部边缘。
TA_TOP 参考点将位于边界矩形的顶部边缘。
TA_CENTER 参考点将与边界矩形的中心水平位置对齐。
TA_LEFT 参考点将位于边界矩形的左边缘。
TA_RIGHT 参考点将位于边界矩形的右边缘。
TA_NOUPDATECP 每次文本输出调用后,当前位置不会更新。 参考点传递给文本输出函数。
TA_RTLREADING Windows的中东语言版本:文本按从右到左的阅读顺序排列,而不是默认的从左到右的顺序。 仅当选择到设备上下文的字体是希伯来语或阿拉伯语时才适用。
TA_UPDATECP 每次文本输出调用后更新当前位置。 当前位置用作参考点。

4.VS2010字符集的选择

#ifdef UNICODE
#define TextOut  TextOutW
#else
#define TextOut  TextOutA
#endif // !UNICODE

猜你喜欢

转载自blog.csdn.net/Small_SaltedFish/article/details/81097694
今日推荐