3

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?

iksemyonov
  • 4,106
  • 1
  • 22
  • 42

1 Answers1

5

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.

Community
  • 1
  • 1
Oleg
  • 220,925
  • 34
  • 403
  • 798
  • One more question regarding the link you gave : is it possible to create the main window as a resource (like WinAPI form)? If yes, then maybe it's not necessary to do the trick from the code. – iksemyonov Jun 12 '10 at 19:45
  • You can use dialog as a main window and save it in the resource. Then you will need only choose th font for the dialog. If your program can be organized as a dialog based, then you will have really no problem with the font. – Oleg Jun 12 '10 at 21:06