如何使用CDC设置字体 [英] How to set font using CDC

查看:282
本文介绍了如何使用CDC设置字体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我在设置字体属性到CStatic控件时遇到问题。我有静态控件,我在使用SetWindowText登录时设置用户名。我抓住鼠标悬停并改变它的颜色。我正在处理OnMouseMove,OnMouseHover和OnMouseLeave事件。我使用DrawText / DrawTextEx在OnPaint中绘制文本。但我想将字体设置为它,并且还希望将文本垂直居中对齐。但我无法做到。

请建议如何处理控制文本的字体和对齐方式。



DrawTextEx(pDC-> GetSafeHdc(),text.GetBuffer( ),text.GetLength(),rc,DT_EDITCONTROL | DT_CENTER | DT_VCENTER,NULL);





Regds

SNI

Hi,

I have problem in setting up font attributes to CStatic control. I have static control where I am setting user name when logged in using SetWindowText. I have trapped mouse hover and changing the color of it. I am handling OnMouseMove,OnMouseHover and OnMouseLeave events. I am drawing text in OnPaint using DrawText / DrawTextEx. But I want to set the font to it and also want to align the text vertically centered. But I am unable to make it.
Pls suggest how to handling Font and Alignment of control text.

DrawTextEx(pDC->GetSafeHdc(),text.GetBuffer(),text.GetLength(),rc,DT_EDITCONTROL | DT_CENTER | DT_VCENTER,NULL);


Regds
SNI

推荐答案

你需要创建字体 [ ^ ]然后选择它进入DC [ ^ ]和设置文本对齐 [ ^ ],在绘制t之前他发短信。此外,如果您使用的是MFC,则使用类对象方法(例如 CDC :: DrawText [ ^ ])而不是纯粹的Win32函数。
You need to create a font[^] and then select it into the DC[^], and set the text alignment[^], before drawing the text. Also, if you are using MFC then use the class object methods (e.g CDC::DrawText[^]) rather than the pure Win32 functions.


这篇关于如何使用CDC设置字体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆