(1)新建一个基于对话框的MFC应用程序3DTextTest,删除对话框中原有控件。
(2)在CMy3DTextTestDlg::OnPaint()中的else段中注释掉CDialogEx::OnPaint();,然后添加代码如下:
else
{
CPaintDC dc(this); // 用于绘制的设备上下文
CString string;
string="3D文字";
CFont m_fontLogo;
m_fontLogo.CreateFont(44, 0, 0, 0, 55, FALSE, FALSE,0,0,0,0,0,0, _T("Arial"));
dc.SetBkMode(TRANSPARENT);
CRect rectText;
GetClientRect(&rectText);
CFont * OldFont = dc.SelectObject(&m_fontLogo);
// draw text in DC
COLORREF OldColor = dc.SetTextColor( ::GetSysColor( COLOR_3DHILIGHT));
dc.DrawText( string, rectText+CPoint(1,1) , DT_SINGLELINE|DT_LEFT|DT_VCENTER|DT_CENTER);
dc.SetTextColor( ::GetSysColor( COLOR_3DSHADOW));
dc.DrawText( string, rectText, DT_SINGLELINE|DT_LEFT|DT_VCENTER|DT_CENTER);
// restore old text color
dc.SetTextColor( OldColor);
// restore old font
dc.SelectObject(OldFont);
//CDialogEx::OnPaint();
}
(3)保存工程并运行,运行结果如图所示: