Visual C++ and MFC Programming 2nd Edition

(Martin Jones) #1

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


BOOL CreateFontIndirect(const LOGFONT* lpLogFont);

When calling this member function, pass the LOGFONT variable as a pointer,
lpLogFont.

To select the selected font, call the CDC::SelectObject() method. Once done, you can use
the new font as you see fit. Here is an example:

void CExoView::OnDraw(CDC* pDC)
{
CFont font;
LOGFONT LogFont;

LogFont.lfStrikeOut = 0;
LogFont.lfUnderline = 0;
LogFont.lfHeight = 42;
LogFont.lfEscapement = 0;
LogFont.lfItalic = TRUE;

font.CreateFontIndirect(&LogFont);
CFont *pFont = pDC->SelectObject(&font);
pDC->TextOut(20, 18, "James Kolowski", 14);

pDC->SelectObject(pFont);
font.DeleteObject();
}

7.4.4 Font Retrieval.......................................................................................


If some text is displaying and you want to get the font properties of that text, you can call
the CDC::GetLogFont() method. Its syntax is:

int GetLogFont(LOGFONT * pLogFont);

To get the current font characteristics on a device context, pass a LOGFONT variable as
pointer to this method. After execution, it returns the LOGFONT argument with these
characteristics. If this method succeeds, it returns TRUE or non-zero. It it fails, it returns
FALSE or 0.

Here is an example:

void CAboutDlg::OnButton1()
{
CFont *font;
Free download pdf