Figure 10: Steps to create an MFC Single Document Interface (SDI) application using class CGlyph to put character outlines on the screen

1) Use MFC AppWizard to create SDI app 'GlyphSDI'.
2) Copy glyph.cpp and glyph.h into the GlyphSDI directory and add glyph.cpp to the project.
3) Towards the top of GlyphSDIDoc.h, just before the definition of class CGlyphSDIDoc, add:

#include "glyph.h"

Also add a public CGlyph member variable inside the class:

// Attributes
public:
   CGlyph m_glyph;

4) Add a public LOGFONT member variable inside the definition of class CGlyphSDIView
   in GlyphSDIView.h:

// Attributes
public:
   LOGFONT m_lf; // keeps track of current font properties

5) Add this code to the CGlyphSDIView constructor in GlyphSDIView.cpp:

CGlyphSDIView::CGlyphSDIView()
{
   // TODO: add construction code here
   // Initial font information.
   memset(&m_lf, 0, sizeof(m_lf));
   m_lf.lfPitchAndFamily = FF_ROMAN;
   m_lf.lfHeight         = 576;
   m_lf.lfCharSet        = ANSI_CHARSET;
   m_lf.lfOutPrecision   = OUT_TT_PRECIS;
   strcpy(m_lf.lfFaceName, "Times New Roman");
}

6) Add this code to CGlyphSDIView's OnDraw method in GlyphSDIView.cpp:

void CGlyphSDIView::OnDraw(CDC* pDC)
{
   CGlyphSDIDoc* pDoc = GetDocument();
   ASSERT_VALID(pDoc);

   // TODO: add draw code for native data here
   // First time through, realize 'B'.
   if (!pDoc->m_glyph.IsRealized())
      pDoc->m_glyph.Realize('B', *pDC, &m_lf);

   // Draw the glyph.
   pDoc->m_glyph.Draw(*pDC, 20, 20);
}

7) Use the class wizard to add an event handler to CGlyphSDIView for the WM_CHAR
   message (call it OnChar()):

void
CGlyphSDIView::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
{
   // TODO: Add your message handler code here and/or call
   // default
   CGlyphSDIDoc* pDoc;
   pDoc = GetDocument();
   ASSERT_VALID(pDoc);
   CDC *pDC = GetDC();  // need a DC to realize the glyph

   // Must realize the glyph for change to take effect.
   pDoc->m_glyph.Realize(nChar, *pDC, &m_lf);

   // Redraw.
   Invalidate();
}