سؤال

Me again guys, I've managed to learn up till now about most basics regarding window creation and message system, now I wanted to ask about formatting because I didn't manage to find anything about my particular case on google. Here is what it looks like so far:

The boxes with 0s in them are Static windows since I didn't really get the Rect paint job. I also need it to be dynamic; the boxes will display an element from an int array that I'll transfer over to a wchar_t array for output. Now is it possible to change the font, lets say increase it and make it bold? Or is it only possible using print text function? Any help would be much appreciated since I'm really trying to make this "centered" so to speak.

EDIT: Another question just so I don't make another post: I just noticed that my stupid static windows don't update after I change the values in array I'm printing in them and repaint them. E.g. each zero is contained in wchar_t array[16][15]; and after I print this setup and change lets say array[13][0] = 'A'; nothing happens, is it due to Static window type or is it because of me being noobish and using MoveWindow to repaint them XD?

هل كانت مفيدة؟

المحلول

The windows message WM_SETFONT will do it. First there should be a font created, and then it is used in the parameter for WM_SETFONT. When the font and window have been created, use

SendMessage(wnd, WM_SETFONT, (WPARAM)font, FALSE);

to set the default font for the window.

If you want to use a default windows font, you can create one like this:

HFONT font = NULL;
NONCLIENTMETRICS ncm;
memset(&ncm, 0, sizeof(NONCLIENTMETRICS));
ncm.cbSize = sizeof(NONCLIENTMETRICS);
if(SystemParametersInfo(SPI_GETNONCLIENTMETRICS,
        sizeof(NONCLIENTMETRICS), &ncm, 0)) {
    font = CreateFontIndirect(&ncm.lfMessageFont);
}

There are other default fonts in NONCLIENTMETRICS that you could use. Of course you can also create a font from a typeface name and other information, but there is no guarantee that there is such a font on different systems.

HFONT CreateFont(
  int nHeight,               // height of font
  int nWidth,                // average character width
  int nEscapement,           // angle of escapement
  int nOrientation,          // base-line orientation angle
  int fnWeight,              // font weight
  DWORD fdwItalic,           // italic attribute option
  DWORD fdwUnderline,        // underline attribute option
  DWORD fdwStrikeOut,        // strikeout attribute option
  DWORD fdwCharSet,          // character set identifier
  DWORD fdwOutputPrecision,  // output precision
  DWORD fdwClipPrecision,    // clipping precision
  DWORD fdwQuality,          // output quality
  DWORD fdwPitchAndFamily,   // pitch and family
  LPCTSTR lpszFace           // typeface name
);
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top