在VC++程序中输出3D空心字
?牐犑紫扔肁ppWizard创建一个单文档应用程序HollowFont。
?牐犎缓蟾鳦HollowFontView类添加如下两个数据成员:
?牐爌ublic??
?牐燙String m_sText?? CFont m_font??
?牐犝饬礁鍪莩稍狈直鸫娣乓允镜奈淖旨拔淖炙褂玫淖痔濉?
?牐犜贑hollowFontView类的构造函数中,我们将m_sText赋初值为“汉字”,并调用CFont类的CreateFontIndirect函数建立合适的字体如下:
?牐燙HollowFontView?煢烠HollowFontView?煟?
?牐燣OGFONT lf?? //lf定义字体的属性
?牐爈f.lfHeight = -80?? //字体字符的高度
?牐爈f.lfWidth = 0?? //字符平均宽度
?牐爈f.lfEscapement =450?? //文本行逆时针旋转45度
?牐爈f.lfOrientation=0?? //字符角度
?牐爈f.lfWeight=FW_HEAVY?? //字符的粗细度
?牐爈f.lfItalic = FALSE?? //倾斜
?牐爈f.lfUnderline = FALSE?? //下划线
?牐爈f.lfStrikeOut = FALSE?? //删除线
?牐爈f.lfCharSet = GB2312_CHARSET??//中文字符集
?牐爈f.lfOutPrecision=OUT_STROKE_PRECIS?? //字体输出结果和要求的匹配程度
?牐爈f.lfClipPrecision=CLIP_STROKE_PRECIS??//如何裁剪落于裁剪区之外的字符
?牐爈f.lfQuality=DRAFT_QUALITY?? //字体属性匹配的精确程度
?牐爈f.lfPitchAndFamily=VARIABLE_PITCH|FF_MODERN?? //字体间距和字体族
?牐爏trcpy?焞f.lfFaceName"楷体_GB2312"?牔? //楷体
?牐爉_font.CreateFontIndirect??&lf?牔?
?牐爉_sText=_T??"汉字"?牔?
?牐犠詈笕缦卤嗉瑿HollowFontView?煢烵nDraw?煟牶?
?牐爒oid CHollowFontView?煢烵nDraw?烠DC* pDC??
?牐燙HollowFontDoc* pDoc = GetDocument?煟牔?
?牐燗SSERT_VALID?焢Doc?牔?
?牐?// TODO?? add draw code for native data here
?牐爄f?焟_font.GetSafeHandle?煟牎?=NULL??//如果成功建立字体
?牐燙Font *pOldFont= ?烠Font*?爌DC→SelectObject??&m_font?牔?
?牐爌DC→SetBkMode?烼RANSPARENT?牔?
?牐爄nt cx=10cy=100??//文本输出位置
?牐燙String sTemp=m_sText??
?牐燾x += 3?? cy += 3?? //以下先输出突出的3D文本
?牐爌DC→SetTextColor?煢煢烥etSysColor?烠OLOR_3DDKSHADOW?牐牔?
?牐爌DC→TextOut?焎x+2cy-2sTemp?牔?
?牐爌DC→TextOut?焎x+2cy+2sTemp?牔?
?牐爌DC→SetTextColor?煢煢烥etSysColor?? COLOR_3DHILIGHT ?牐牔?
?牐爌DC→TextOut?焎x+1cy-2sTemp?牔?
?牐爌DC→TextOut?焎x-2cy+1sTemp?牔?
?牐爌DC→TextOut?焎x-2cy-2sTemp?牔?
?牐爌DC→SetTextColor?煢煢烥etSysColor?烠OLOR_3DSHADOW?牐牔?
?牐爌DC→TextOut?焎x-1cy+1sTemp?牔?
?牐爌DC→TextOut?焎x+1cy-1sTemp?牔?
?牐爌DC→TextOut?焎x+1cy+1sTemp?牔?
?牐爌DC→SetTextColor?煢煢烥etSysColor?烠OLOR_3DLIGHT?牐牔?
?牐爌DC→TextOut?焎xcy-1sTemp?牔?
?牐爌DC→TextOut?焎x-1cysTemp?牔?
?牐爌DC→TextOut?焎x-1cy-1sTemp?牔?
?牐?//然后通过路径对象将以上要输出的文本变成空心
?牐?//向路径输出“汉字”
?牐爌DC→BeginPath?煟牔?
?牐爌DC→TextOut?焎xcysTemp4?牔?
?牐爌DC→EndPath?煟牔?
?牐?//填充路径
?牐爌DC→SetPolyFillMode?焀INDING?牔?//设置填充模式
?牐爌DC→StrokeAndFillPath?煟牔?//绘制路径外观
?牐爌DC→SelectObject?焢OldFont?牔?
?牐牨嘁氩⒅葱谐绦颍峁缤妓尽:衟DC→StrokeAndFillPath一句是先封闭所有的开放路径,然后用当前画刷和填充方式填充区域内部,由于当前画刷是一个实心的白色画刷(WHITE_BRUSH),因此,文字的显示效果就变成了空心,同时该函数用当前画笔勾画路径的轮廓。