Visual C++ and MFC Programming 2nd Edition

(Martin Jones) #1

Chapter 8 GDI Orientation and Transformations Visual C++ and MFC Fundamentals


Remember that once an object such as a font has been selected, it remains in the device
context until further notice. For example, if you have created and selected a font, any text
you draw would follow the characteristics of that font. If you want another font, you must
change the previously selected font.

The computer uses the default black color to draw the text. Once again, if you want to
draw text with a different color, you can first call the CDC::SetTextColor() method and
specify the color of your choice.

The CFont::CreateFont() method is used to specify all characteristics of a font in one
step. Alternatively, if you want to specify each font property, you can declare a
LOGFONT variable and initialize it. It is defined as follows:

typedef struct tagLOGFONT {
LONG lfHeight;
LONG lfWidth;
LONG lfEscapement;
LONG lfOrientation;
LONG lfWeight;
BYTE lfItalic;
BYTE lfUnderline;
BYTE lfStrikeOut;
BYTE lfCharSet;
BYTE lfOutPrecision;
BYTE lfClipPrecision;
BYTE lfQuality;
BYTE lfPitchAndFamily;
TCHAR lfFaceName[LF_FACESIZE];
} LOGFONT, *PLOGFONT;

This time, you do not have to provide a value for each member of the structure and even
if you do, you can supply values in the order of your choice. For any member whose
value is not specified, the compiler would use a default value but you may not like some
of the default values. Therefore, you should specify as many values as possible.

After initializing the LOGFONT variable, call the CFont::CreateFontIndirect() method.
Its syntax is:
Free download pdf