如何使Win32使用Windows XP样式字体 [英] How to get Win32 to use Windows XP style fonts
问题描述
我正在使用纯C和WinAPI编写Win32应用程序。不允许使用MFC或C ++。为了使控件使用适当的样式进行绘制,我使用了清单,如相应的MSDN文章中所述。一切都很好,当我更改系统样式时,我的应用程序也会更改样式。但是使用的字体很难看。如何强制应用程序使用标准系统字体?
I'm writing a Win32 application using plain C and WinAPI. No MFC or C++ is allowed. To get the controls to draw using the appropriate style, I use a manifest, as described in the corresponding MSDN article. Everything is fine, and when I change the system style, my application changes style as well. But the font used is just ugly. How do I force the application to use the standard system font?
推荐答案
您可以使用 SystemParametersInfo
与 SPI_GETNONCLIENTMETRICS
参数一起检索当前字体。 SystemParametersInfo将考虑当前主题,并提供标题,菜单和消息对话框的字体信息。 (请参见 GetStockObject
http://msdn.microsoft.com/en-us/library/dd144925(VS.85).aspx )。该函数将检索 NONCLIENTMETRICS
结构(请参阅 http://msdn.microsoft.com/en-us/library/ff729175(v = VS.85).aspx ),其中包含您需要的所有信息:
You can use SystemParametersInfo
with SPI_GETNONCLIENTMETRICS
parameter to retrieve the current font. SystemParametersInfo will take into account the current theme and provides font information for captions, menus, and message dialogs. (See remark to GetStockObject
http://msdn.microsoft.com/en-us/library/dd144925(VS.85).aspx). The function will retrieve NONCLIENTMETRICS
structure (see http://msdn.microsoft.com/en-us/library/ff729175(v=VS.85).aspx) which contains all information you needs:
typedef struct tagNONCLIENTMETRICS {
UINT cbSize;
int iBorderWidth;
int iScrollWidth;
int iScrollHeight;
int iCaptionWidth;
int iCaptionHeight;
LOGFONT lfCaptionFont;
int iSmCaptionWidth;
int iSmCaptionHeight;
LOGFONT lfSmCaptionFont;
int iMenuWidth;
int iMenuHeight;
LOGFONT lfMenuFont;
LOGFONT lfStatusFont;
LOGFONT lfMessageFont;
#if (WINVER >= 0x0600)
int iPaddedBorderWidth;
#endif
} NONCLIENTMETRICS, *PNONCLIENTMETRICS, *LPNONCLIENTMETRICS;
如果您知道<$ c $,如何在窗口/控件中创建和设置字体的示例c> LOGFONT 参数请参见示例结尾处的更改Win32 Windows项目中的默认窗口字体,但使用 LOGFONT
而不是使用 GetStockObject(DEFAULT_GUI_FONT)
,但由带有参数 SPI_GETNONCLIENTMETRICS
的 SystemParametersInfo
返回。
An example how to create and a set font in a window/control if you knows LOGFONT
parameter see at the end of the example from change the default window font in a win32 windows project, but use do LOGFONT
not from GetStockObject(DEFAULT_GUI_FONT)
, but returned by SystemParametersInfo
with SPI_GETNONCLIENTMETRICS
parameter instead.
这篇关于如何使Win32使用Windows XP样式字体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!