VC中特殊字体的实现(转) C+/VC
[ 2008-7-30 22:33:00 | 发表者 : zihe ]
渐变字:
// 获得窗口的客户区设备上下文句柄
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);