开发者

How to get Win32 to use Windows XP style fonts

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 ar开发者_如何转开发ticle. 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?


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;

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜