From: David Given on
I'm having some trouble making ChooseFont() work sensibly.

- sometimes the LOGFONT structure that I get back won't instantiate into
a logical font correctly --- this particularly seems to be the case for
Terminal fonts. What I end up with appears to be System.

- no matter what style (bold, italic etc) the user selects, I always end
up with a 'regular' font --- even though the documentation says the
style is reflected in the LOGFONT structure.

Do these ring a bell with anyone?

Also, is there any way of suppressing the style and script selectors
completely? They don't really make any sense for my application.

--
┌─── dg@cowlark.com ───── http://www.cowlark.com ─────

│ life←{ ↑1 ⍵∨.^3 4=+/,¯1 0 1∘.⊖¯1 0 1∘.⌽⊂⍵ }
│ --- Conway's Game Of Life, in one line of APL
From: Christian ASTOR on
On 7 fév, 22:12, David Given <d...(a)cowlark.com> wrote:
> I'm having some trouble making ChooseFont() work sensibly.
> - sometimes the LOGFONT structure that I get back won't instantiate into
> a logical font correctly --- this particularly seems to be the case for
> Terminal fonts. What I end up with appears to be System.

> - no matter what style (bold, italic etc) the user selects, I always end
> up with a 'regular' font --- even though the documentation says the
> style is reflected in the LOGFONT structure.

I tested on XP SP2, and it seems to work fine.
For example =>

{
HDC hDC;
hDC = GetDC(NULL);
if (hDC != NULL)
{
static CHOOSEFONT cf;
static LOGFONT lf = {0};
HFONT hFont = 0;
static dwColor = RGB(0,0,0);

memset(&cf, 0, sizeof(cf));
cf.lStructSize = sizeof(cf);
cf.hwndOwner = hWnd;
cf.lpLogFont = &lf;
cf.rgbColors = dwColor;
cf.Flags = CF_SCREENFONTS | CF_EFFECTS | CF_INITTOLOGFONTSTRUCT;
cf.nFontType = SCREEN_FONTTYPE;
if (ChooseFont(&cf))
{
hFont = CreateFontIndirect(&lf);
if (hFont != NULL)
{
dwColor = cf.rgbColors;
HFONT hFontOld = (HFONT)SelectObject(hDC, hFont);
WCHAR sString[] = TEXT("Test Font");
RECT rc = {0, 0, 320, 200};
COLORREF dwColorOld = SetTextColor(hDC, dwColor);
DrawText(hDC, sString, -1, &rc, DT_LEFT | DT_NOPREFIX);
SelectObject(hDC, hFontOld);
DeleteObject(hFont);
SetTextColor(hDC, dwColorOld);
}
}
ReleaseDC(NULL, hDC);
}
}