Writing Text

You can write text in a given font by selecting the font and using the TextOut function to write it. TextOut writes the characters of the string by using the font that is currently selected in the device context. The following example shows how to write the string This is a sample string:

hDC = GetDC(hWnd);

TextOut(hDC, 10, 10, “This is a sample string”, 23);

ReleaseDC(hWnd, hDC);

In this example, TextOut starts the string at the coordinates (10, 10) and prints all 23 characters of the string.

The default font for a device context is the system font. This is a variable-width font representing characters in the ANSI character set. Its font name is System. Windows uses the system font for menus, window captions, and other text.