ü 字体:渐变字、空心字、立体字、旋转字
渐变字:
// 获得窗口的客户区设备上下文句柄
CClientDC dc(this);
// 更改当前字体
LOGFONT lf;
dc.GetCurrentFont()->GetLogFont(&lf);
CFont font, *pOldFont;
lf.lfCharSet=134;
lf.lfHeight=-150;
lf.lfWidth=0;
strcpy(lf.lfFaceName, "隶书");
font.CreateFontIndirect(&lf);
pOldFont=dc.SelectObject(&font);
dc.SetBkMode(TRANSPARENT);
// 更改当前画笔为空
CPen pen(PS_NULL, 1, RGB(255, 0, 0)), *pOldPen;
pOldPen=dc.SelectObject(&pen);
// 更改当前刷子
CBrush
br, *pOldBrush;
pOldBrush=dc.SelectObject(&
br);
// 开始一个路径
dc.BeginPath();
dc.TextOut(10, 10, "渐变字");
dc.EndPath();
// 绘制渐变效果
dc.SelectClipPath(RGN_COPY);
for (int i=255; i>0; i--)
{
int iRadius=(600*i)/255;
dc.SelectObject(pOldBrush);
br.DeleteObject();
br.CreateSolidBrush(RGB(255, i, 0));
dc.SelectObject(&
br);
dc.Ellipse(-iRadius, -iRadius/3, iRadius, iRadius/3);
}
// 恢复设备上下文的原有设置
dc.SelectObject(pOldFont);
dc.SelectObject(pOldPen);
dc.SelectObject(pOldBrush);
空心字:
// 获得窗口的客户区设备上下文句柄
CClientDC dc(this);
// 更改当前字体
LOGFONT lf;
dc.GetCurrentFont()->GetLogFont(&lf);
CFont font;
CFont *pOldFont; // 保存设备上下文最初使用的字体对象
lf.lfCharSet=134;
lf.lfHeight=-150;
lf.lfWidth=0;
strcpy(lf.lfFaceName, "隶书");
font.CreateFontIndirect(&lf);
pOldFont=dc.SelectObject(&font);
dc.SetBkMode(TRANSPARENT);
// 更改当前画笔
CPen pen(PS_SOLID, 1, RGB(255, 0, 0));
CPen *pOldPen;
pOldPen=dc.SelectObject(&pen);
// 开始一个路径
dc.BeginPath();
dc.TextOut(10, 130, "空心字");
dc.EndPath();
// 绘制路径
dc.StrokePath();
// 恢复设备上下文的原有设置
dc.SelectObject(pOldFont);
dc.SelectObject(pOldPen);
立体字:在实现3D文字时一般不使用缺省的字体设置,而是通过对字体的设置而使产生的3D文字在视觉上更美观
// 获得窗口的客户区设备上下文句柄
CClientDC dc(this);
//定义字体属性
LOGFONT lf;
lf.lfHeight = 50;
lf.lfWidth = 0;
lf.lfEscapement = 0;
lf.lfOrientation = 0;
lf.lfWeight = FW_HEAVY;
lf.lfItalic = FALSE;
lf.lfUnderline = FALSE;
lf.lfStrikeOut = FALSE;
lf.lfCharSet = GB2312_CHARSET;
strcpy(lf.lfFaceName,"幼圆");
//创建字体
CFont font;
font.CreateFontIndirect(&lf);
//更改当前字体
CFont *pOldFont = dc.SelectObject(&font);
//绘制字体
dc.SetBkMode(TRANSPARENT);
dc.SetTextColor(::GetSysColor(COLOR_3DDKSHADOW));
dc.TextOut(10,10,"立体字");
dc.SetTextColor(::GetSysColor(COLOR_3DHILIGHT));
dc.TextOut(13,7,"立体字");
//恢复设备上下文的原有设置
dc.SelectObject(pOldFont);
旋转字:通过设置字体与X轴的倾斜角度(十分之一度为一个单位)
// 获得窗口的客户区设备上下文句柄
CClientDC dc(this);
//定义字体属性
LOGFONT lf;
lf.lfHeight = 50;
lf.lfWidth = 0;
lf.lfEscapement = 300; //倾斜30度,十分之一度为单位
lf.lfOrientation = 0;
lf.lfWeight = FW_HEAVY;
lf.lfItalic = FALSE;
lf.lfUnderline = FALSE;
lf.lfStrikeOut = FALSE;
lf.lfCharSet = GB2312_CHARSET;
strcpy(lf.lfFaceName,"幼圆");
//创建字体
CFont font;
font.CreateFontIndirect(&lf);
//更改当前字体
CFont *pOldFont = dc.SelectObject(&font);
//绘制字体
dc.SetBkMode(TRANSPARENT);
dc.SetTextColor(RGB(255,0,0));
dc.TextOut(10,300,"旋转的字体");
//恢复设备上下文的原有设置
dc.SelectObject(pOldFont);