DrawText 用设备环境中的字体选择、正文颜色和背景颜色来写正文。DrawText裁剪正文,不会出现在指定矩形的外面,除非指定了DT_NOCLIP。除非使用DT_SINGLELINE格式化,否则其余的格式都认为正文有多行。
WINUSERAPI
int
WINAPI
DrawTextA(
__in HDC hdc, //绘图设备上下文
__inout_ecount_opt(cchText) LPCSTR lpchText, //要输出的字符串
__in int cchText, //字符串长度
__inout LPRECT lprc, //绘图区域
__in UINT format); //显示控制模式
WINUSERAPI
int
WINAPI
DrawTextW(
__in HDC hdc,
__inout_ecount_opt(cchText) LPCWSTR lpchText,
__in int cchText,
__inout LPRECT lprc,
__in UINT format);
#ifdef UNICODE
#define DrawText DrawTextW
#else
#define DrawText DrawTextA
#endif // !UNICODE
返回值为int,如果函数调用成功,返回值是正文的高度(逻辑单位)。如果指定了DT_VCENTER或DT_BOTTOM,返回值是lpRect->top到绘制的正文的底部的偏移值。如果函数调用失败,返回值是0
format参数说明:
/*
* DrawText() Format Flags
*/
#define DT_TOP 0x00000000 //顶对齐
#define DT_LEFT 0x00000000 //左对齐
#define DT_CENTER 0x00000001 //横向中间对齐
#define DT_RIGHT 0x00000002 //右对齐
#define DT_VCENTER 0x00000004 //纵向中间对齐
#define DT_BOTTOM 0x00000008 //底部对齐
#define DT_WORDBREAK 0x00000010 //自动换行
#define DT_SINGLELINE 0x00000020 //单行显示
#define DT_EXPANDTABS 0x00000040 // 制表符\t可用
#define DT_TABSTOP