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…

[sourcecode language=’cpp’]void CMyDlg::OnPaint()
// Default first

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[/sourcecode]

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.

One thought on “Drawing shadowed text using windows API?

Appreciate your comments...