在 Windows GUI 中更改静态文本框的字体大小 [英] Changing the font size of a static textbox in a Windows GUI

查看:78
本文介绍了在 Windows GUI 中更改静态文本框的字体大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在用 C++ 编写的 Windows GUI 应用程序中更改静态文本框的字体大小?

how do you change the font size of a static text box in a Windows GUI application written in C++?

HWND hText = CreateWindowW(L"EDIT", L"enter some text", WS_VISIBLE | WS_CHILD | ES_RIGHT, 100, 100, 100, 50, hWnd, NULL, NULL, NULL);

我是否需要制作另一个窗口消息

do i have to make another Window message

推荐答案

正如@RbMm 所说,使用 CreateFontWM_SETFONT 可以实现这一点.并且官方文档也有相应的介绍.

As @RbMm said that, use CreateFont and WM_SETFONT can achieve this. And the official documents also have corresponding introduction.

更改编辑控件使用的字体.

应用程序可以更改编辑控件使用的字体发送 WM_SETFONT 消息.大多数应用程序都会这样做处理 WM_INITDIALOG 消息.改变字体不会更改编辑控件的大小;发送的应用程序WM_SETFONT 消息可能需要检索文本的字体规格并重新计算编辑控件的大小.更多有关字体和字体规格的信息,请参阅字体和文本.

An application can change the font that an edit control uses by sending the WM_SETFONT message. Most applications do this while processing the WM_INITDIALOG message. Changing the font does not change the size of the edit control; applications that send the WM_SETFONT message may have to retrieve the font metrics for the text and recalculate the size of the edit control. For more information about fonts and font metrics, see Fonts and Text.

最少的代码:

LOGFONT logfont; 
ZeroMemory(&logfont, sizeof(LOGFONT));
logfont.lfCharSet = DEFAULT_CHARSET;
logfont.lfHeight = -20; 
HFONT hFont = CreateFontIndirect(&logfont);

SendMessage(hText, WM_SETFONT, (WPARAM)hFont, TRUE);

这篇关于在 Windows GUI 中更改静态文本框的字体大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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