Home > MFC, Windows API > Drawing outlined text!

Drawing outlined text!

How to draw text like this!

Looks interesting right! Well this is done using plain window’s GDI functions, here is a function which does this!

// Thanks to Charles Petzold!
void CCanvas::DrawOutlineText( CDC& dc, const CString& Text )
  const int RestorePoint = dc.SaveDC();

  // Create new font
  CFont NewFont;
  NewFont.CreatePointFont( 700, TEXT( "Verdana" ), &dc );

  // Use this font
  dc.SelectObject( &NewFont );

  // Brush for pen
  LOGBRUSH lBrushForPen = { 0 };
  lBrushForPen.lbColor = RGB( 200, 150, 100 );
  lBrushForPen.lbHatch = HS_CROSS;
  lBrushForPen.lbStyle = BS_SOLID;

  // New pen for drawing outline text
  CPen OutlinePen;
  OutlinePen.CreatePen( PS_GEOMETRIC | PS_SOLID, 2, &lBrushForPen, 0, 0 );

  // Use this pen
  dc.SelectObject( &OutlinePen );

  dc.SetBkMode( TRANSPARENT );

  // This text is not drawn on screen, but instead each action is being
  // recorded and stored internally as a path, since we called BeginPath
  dc.TextOut( 20, 20, Text );
  // Stop path

  // Now draw outline text

  dc.RestoreDC( RestorePoint );
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: