Home > Windows API > Drawing shadowed text using windows API?

Drawing shadowed text using windows API?

Is there an API to draw shadowed text? Yes there is one in XP, only limitation is that you should be linking Commctrl32.dll version 6 using your manifest file!

DrawShadowText is the API that I am talking about!

Here is some sample code which does this…

void CMyDlg::OnPaint()
{
   // Default first
   CDialog::OnPaint();

   CStringW csText = _T( "Nibu babu thomas" );
   RECT rcText = { 10, 10, 600, 200 };
   CDC* pDC = GetDC();

   // Create a big font
   CFont TempFont;
   TempFont.CreatePointFont( 400, _T( "Ms Sans Serif" ), pDC );
   CFont* pOldFont = pDC->SelectObject( &TempFont );

   // Draw shadowed text
   VERIFY( DrawShadowText( pDC->GetSafeHdc(),
                           csText, // Text to draw
                           csText.GetLength(), // Length of text
                           &rcText, // Bounding rectangle for the text to be drawn
                           DT_LEFT, // Text alignment
                           RGB( 255, 0, 0 ), // Text color
                           RGB( 122, 122, 122 ), // Shadow color
                           0, // X-Offset of shadow
                           12 )); // Y-Offset of shadow

   // Restore old font
   pDC->SelectObject( pOldFont );

   // Free DC
   ReleaseDC( pDC );
}// End OnPaint

We’ve given X-Offset as zero and Y-Offset a positive value hence the shadow text moves down! Here is a screenshot of the resulting shadowed text!



This API is similar to DrawText except for some additional parameters for drawing a shadow.

Advertisements
  1. No comments yet.
  1. May 5, 2008 at 10:43 am

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s

%d bloggers like this: