BOOL TextOut(hdc, nXStart, nYStart, lpszString, cbString) | |||||
HDC hdc; | /* handle of device context | */ | |||
int nXStart; | /* x-coordinate of starting position | */ | |||
int nYStart; | /* y-coordinate of starting position | */ | |||
LPCSTR lpszString; | /* address of string | */ | |||
int cbString; | /* number of bytes in string | */ |
The TextOut function writes a character string at the specified location, using the currently selected font.
hdc
Identifies the device context.
nXStart
Specifies the logical x-coordinate of the starting point of the string.
nYStart
Specifies the logical y-coordinate of the starting point of the string.
lpszString
Points to the character string to be drawn.
cbString
Specifies the number of bytes in the string.
The return value is nonzero if the function is successful. Otherwise, it is zero.
Character origins are at the upper-left corner of the character cell.
By default, the TextOut function does not use or update the current position. If an application must update the current position when calling TextOut, it can call the SetTextAlign function with the wFlags parameter set to TA_UPDATECP. When this flag is set, Windows ignores the nXStart and nYStart parameters on subsequent calls to the TextOut function, using the current position instead.
The following example uses the GetTextFace function to retrieve the face name of the current font, calls SetTextAlign so that the current position is updated when the TextOut function is called, and then writes some introductory text and the face name by calling TextOut:
int nFaceNameLen;
char aFaceName[80];
nFaceNameLen = GetTextFace(hdc, /* returns length of string */
sizeof(aFaceName), /* size of face-name buffer */
(LPSTR) aFaceName); /* address of face-name buffer */
SetTextAlign(hdc,
TA_UPDATECP); /* updates current position */
MoveTo(hdc, 100, 100); /* sets current position */
TextOut(hdc, 0, 0, /* uses current position for text */
"This is the current face name: ", 31);
TextOut(hdc, 0, 0, aFaceName, nFaceNameLen);
ExtTextOut, GetTextExtent, SetTextAlign, SetTextColor, TabbedTextOut