如何改变按扭控件上的字体

chemo 2003-10-20 09:21:56
在纯Win32下,不用MFC,如何改变按扭控件上的字体?
...全文
42 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
chemo 2003-10-21
  • 打赏
  • 举报
回复
谢谢两位!!
fairyprince 2003-10-20
  • 打赏
  • 举报
回复
LOGFONT tf;
HFONT hFont = (HFONT)SendMessage(hWnd, WM_GETFONT, 0, 0);
if (hFont == NULL)
return;
GetObject(hFont, sizeof(tf), &tf);
char fName[32];
strcpy(fName,"字体名字");
strcpy(tf.lfFaceName,fName);
Fnt=CreateFontIndirect(&tf);
SendMessage(hWnd, WM_SETFONT,hFont, TRUE);

hwnd为想改变的名柄
zxq80 2003-10-20
  • 打赏
  • 举报
回复
如何改变控件的字体
由于控件是也是窗口,用户可以调用CWnd::SetFont指定新字体。该函数用一个Cfont指针,要保证在控件撤消之前不能撤消字体对象。下例将下压按钮的字体改为8点Arial字体:
//Declare font object in class declaration (.H file ).
private : Cfont m_font
// Set font in class implementation (.Cpp file ). Note m_wndButton is a
//member variable added by ClassWizard.DDX routines hook the member
//variable to a dialog button contrlo.
BOOL CSampleDialog::OnInitDialog( )
{

//Create an 8-point Arial font
m_font . CreateFont (MulDiv (8 , -pDC
-> GetDeviceCaps(LOGPIXELSY) ,72). 0 , 0 , 0 , FW_NORMAL , 0 , 0,0, ANSI_CHARSER, OUT_STROKE_PRECIS ,
CLIP_STROKE _PRECIS , DRAFT _QUALITY
VARIABLE_PITCH | FF_SWISS, _T("Arial") )
//Set font for push button .
m_wndButton . SetFont (&m _font )

}

15,979

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 界面
社区管理员
  • 界面
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧