Posts Tagged ‘CreatePointFont’

Drawing outlined text!

March 21, 2008 Leave a comment

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 );

Changing font of all child controls at one go!

December 6, 2007 Leave a comment

Ever felt the need to change the font of all child controls of a dialog, or a window, and you had to use GetWindow, GetNextWindow and stuff like that to set a font for a window. Well here is an easy way!

// Idea taken from MSDN...
BOOL CSomeDialog::OnInitDialog()
    // I am using a static font for demo purpose only, make sure
    // you have this as a member
    static CFont fnt;
    CDC dc;
    dc.Attach( GetDC()->GetSafeHdc() );
    fnt.CreatePointFont( 100, _T( "Courier new" ), &dc );

    // Set change font message to all child windows
    SendMessageToDescendants( GetSafeHwnd(),
                              MAKELONG(WORD( TRUE ), 0 ),
                              false );
}// End OnInitDialog
%d bloggers like this: