描述
TextOut函数使用当前选择的字体,背景颜色和文本颜色在指定位置写入一个字符串。
C++ 语法
BOOL TextOut( __in HDC hdc, __in int nXStart, __in int nYStart, __in LPCTSTR lpString, __in int cbString ); |
PowerBASIC 语法
FUNCTION TextOutA ( _ BYVAL hdc AS DWORD, _ BYVAL nXStart AS LONG, _ BYVAL nYStart AS LONG, _ BYREF lpString AS ASCIIZ, _ BYVAL cbString AS LONG _ ) AS LONG |
Unicode版本:
FUNCTION TextOutW ( _ BYVAL hdc AS DWORD, _ BYVAL nXStart AS LONG, _ BYVAL nYStart AS LONG, _ BYREF lpString AS WSTRINGZ, _ BYVAL cbString AS LONG _ ) AS LONG |
参数
hdc
[in]处理设备上下文。
nXStart
[in]指定系统用于对齐字符串的参考点的逻辑坐标中的x坐标。
nYStart
[in]指定系统用于对齐字符串的参考点的逻辑坐标中的y坐标。
lpString
[in]指向要绘制的字符串的指针。该字符串不需要为零终止,因为cbString指定字符串的长度。
cbString
[in]指定lpString指向的字符串的长度。
Windows 95/98 / Me:此值不得超过8192。
返回值
如果函数成功,返回值不为零。
如果函数失败,返回值为零。
备注
虽然一般不是真的,Windows 95/98 / Me支持此函数的Unicode版本以及ANSI版本。
参考点的解释取决于当前文本对齐模式。应用程序可以通过调用GetTextAlign函数来检索此模式;应用程序可以通过调用SetTextAlign函数来改变此模式。
默认情况下,此函数不会使用或更新当前位置。但是,应用程序可以将fMode参数设置为TA_UPDATECP来调用SetTextAlign函数,以便每次应用程序为指定的设备上下文调用TextOut时允许系统使用和更新当前位置。设置此标志时,系统会忽略后续TextOut呼叫中的nXStart和nYStart参数。
当TextOut功能放置在路径括号内时,系统会为包含每个字符加上其字符框的TrueType文本生成路径。生成的区域是字符框减去文本,而不是文本本身。将TextOut功能放在路径括号中之前,可以通过将背景模式设置为透明来获取TrueType文本大纲所包含的区域。以下是演示此过程的示例代码。
C++
// Obtain the window's client rectangle
GetClientRect(hwnd, &r);
// THE FIX: by setting the background mode
// to transparent, the region is the text itself
// SetBkMode(hdc, TRANSPARENT);
// Bracket begin a path
BeginPath(hdc);
// Send some text out into the world
TCHAR text[ ] = "Defenestration can be hazardous";
TextOut(hdc,r.left,r.top,text, ARRAYSIZE(text));
// Bracket end a path
EndPath(hdc);
// Derive a region from that path
SelectClipPath(hdc, RGN_AND);
// This generates the same result as SelectClipPath()
// SelectClipRgn(hdc, PathToRegion(hdc));
// Fill the region with grayness
FillRect(hdc, &r, GetStockObject(GRAY_BRUSH));
PowerBASIC
' // Obtain the window's client rectangle
GetClientRect(hwnd, r)
' // THE FIX: by setting the background mode
' // to transparent, the region is the text itself
' // SetBkMode(hdc, %TRANSPARENT)
' // Bracket begin a path
BeginPath(hdc)
' // Send some text out into the world
DIM szText AS ASCIIZ * 256
szText = "Defenestration can be hazardous"
TextOut(hdc, r.nLeft, r.nTop, szText, LEN(szText))
' // Bracket end a path
EndPath(hdc)
' // Derive a region from that path
SelectClipPath(hdc, %RGN_AND)
' // This generates the same result as SelectClipPath()
' // SelectClipRgn(hdc, PathToRegion(hdc))
' // Fill the region with grayness
FillRect(hdc, r, GetStockObject(%GRAY_BRUSH))
Windows 95/98 / Me:虽然Windows 95/98 / Me中存在TextOutW??,但Microsoft Layer for Unicode支持在所有Windows操作系统上提供更一致的行为。
引用文件 #INCLUDE Once
WinGdi.inc(包括Windows.inc)