How to make Win32 use fonts in the style of Windows XP

I am writing a Win32 application using simple C and WinAPI. MFC or C ++ are not allowed. To get the controls using the appropriate style, I use the manifest as described in the corresponding MSDN article. Everything is in order, and when I change the style of the system, my application also changes the style. But the font used is just ugly. How to force an application to use a standard system font?

+3
source share
1 answer

You can use SystemParametersInfowith parameter SPI_GETNONCLIENTMETRICSto get the current font. SystemParametersInfo will keep track of the current topic and provide font information for captions, menus, and message dialogs. (See Note to GetStockObject http://msdn.microsoft.com/en-us/library/dd144925(VS.85).aspx ). The function will retrieve a structure NONCLIENTMETRICS(see http://msdn.microsoft.com/en-us/library/ff729175(v=VS.85).aspx ) that contains all the necessary information:

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 of creating and installing a font in a window / control, if you know the parameter LOGFONT, see the end of the example for changing the default window font in the win32 windows project , but use LOGFONTnot from GetStockObject(DEFAULT_GUI_FONT), but instead return SystemParametersInfowith the parameter SPI_GETNONCLIENTMETRICS.

+5

Source: https://habr.com/ru/post/1749756/


All Articles