From: Thomas Steinbach on 29 Sep 2009 09:18 Hello, how can I change (in plain C/Win32) the font size of a Sstatic-Text-Control? I know WM_SETFONT, but that's not the key... Thomas
From: Christian ASTOR on 29 Sep 2009 11:24 On 29 sep, 15:18, "Thomas Steinbach" <steinb...(a)gmx-topmail.de> wrote: > Hello, > > how can I change (in plain C/Win32) the font size of a > Sstatic-Text-Control? > I know WM_SETFONT, but that's not the key... You must first test the current font. For example => HFONT hFont, hNewFont; LOGFONT lf; HDC hDC; hFont = (HFONT)SendMessage(hStatic1, WM_GETFONT, 0, 0); if(hDC = GetDC(hStatic1)) { if (hFont == NULL) { hFont = (HFONT) GetStockObject(SYSTEM_FONT); GetObject(hFont, sizeof(LOGFONT),&lf); lf.lfQuality = DEFAULT_QUALITY; lf.lfWidth = 0; } else GetObject(hFont, sizeof(LOGFONT),&lf); lf.lfHeight = -MulDiv(20, GetDeviceCaps(hDC, LOGPIXELSY), 72); hNewFont = CreateFontIndirect(&lf); SendMessage(hStatic1, WM_SETFONT, (WPARAM)hNewFont, MAKELPARAM(TRUE, 0)); ReleaseDC(hStatic1, hDC); }
From: Thomas Steinbach on 29 Sep 2009 17:55 Helloo Christian, > You must first test the current font. > For example => > [...] Great, it's working perfect, but I think it would better to use the real dpi, determined by GetDeviceCaps. eg. My Monitor has 96 dpi. this: lf.lfHeight = -MulDiv(20, GetDeviceCaps(hDC, LOGPIXELSY), 72); becomes this: int dpi = GetDeviceCaps(hDC, LOGPIXELSY); lf.lfHeight = -MulDiv(20, dpi, dpi); Think this should work in both cases 72dpi and 96 dpi and any other resolution Thomas
From: Scott Seligman on 29 Sep 2009 18:55 "Thomas Steinbach" <steinbach(a)gmx-topmail.de> wrote: >lf.lfHeight = -MulDiv(20, GetDeviceCaps(hDC, LOGPIXELSY), 72); > >becomes this: > >int dpi = GetDeviceCaps(hDC, LOGPIXELSY); >lf.lfHeight = -MulDiv(20, dpi, dpi); The 72 refers to the number of points per inch, it's a constant value, from typography, that doesn't change to match your monitor's settings. Your change sets lfHeight to -20 always, irregardless of the current DPI. -- --------- Scott Seligman <scott at <firstname> and michelle dot net> --------- There are fewer great satisfactions than that of self. -- Calhoun in Star Trek: New Frontier: Being Human by Peter David
From: Thomas Steinbach on 30 Sep 2009 04:50 Hello Scott, >> lf.lfHeight = -MulDiv(20, GetDeviceCaps(hDC, LOGPIXELSY), 72); > [...] > The 72 refers to the number of points per inch, it's a constant value, > from typography, that doesn't change to match your monitor's settings. > > Your change sets lfHeight to -20 always, irregardless of the current > DPI. okay. Didn't recognize this. Thank you. Thomas
|
Pages: 1 Prev: IsGUIThread always returns TRUE... Next: Printing in landscape with WinAPI |