views:

57

answers:

2

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?

A: 

Been a long long time since I worked Win32 but I think this discussion may help

renick
+1  A: 

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 http://stackoverflow.com/questions/2885454/change-the-default-window-font-in-a-win32-windows-project/2887783#2887783, but use do LOGFONT not from GetStockObject(DEFAULT_GUI_FONT), but returned by SystemParametersInfo with SPI_GETNONCLIENTMETRICS parameter instead.

Oleg
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.
Semen Semenych
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