Quantcast
Channel: CPaintDC – bits and bytes
Viewing all articles
Browse latest Browse all 2

How to rotate text using WinAPI?

$
0
0

Simple way to rotate a piece of text is to use a font object… Here is a sample which does this…

void CSomeDlg::OnPaint()
{    
  CPaintDC dc(this);

  // Get existing dlg font    
  CFont NewFont;     
  LOGFONT lgFnt = { 0 };     
  GetFont()->GetLogFont(&lgFnt);

  // Modify this existing font //

  // Face name is important, some font's like MS Sans Serif doesn't work
  strcpy( lgFnt.lfFaceName, "Arial" );

  // Give rotation as multiples of 10, so rotation will be 90 degrees
  lgFnt.lfOrientation = 900;
  lgFnt.lfEscapement =  900;

  // Create a font from this log font     
  VERIFY( NewFont.CreateFontIndirect( &lgFnt ));

  // Save this DC    
  const int DcRestorePoint = dc.SaveDC();      
  dc.SetBkMode( TRANSPARENT );

  // Set this font to DC     
  dc.SelectObject( &NewFont );     
  dc.TextOut( 100,100, _T( "Nibu babu thomas loves Jesus Christ" ));

  // Restore dc to previous state    
  dc.RestoreDC( DcRestorePoint );
}// End OnPaint

Not much of work ! :)

The post How to rotate text using WinAPI? appeared first on bits and bytes.


Viewing all articles
Browse latest Browse all 2

Trending Articles