Default font problem win32 C

Started by
1 comment, last by szecs 12 years, 8 months ago
I am totally lost in windows font handling. I can't, for the life, get the attributes of the currently used (and never altered) font.

I can't use GetObject, because I never changed the font of the DC, so the LOGFONT structure will be empty (or whatever, according to MSDN). I can't use SystemParametersInfo with SPI_GETNONCLIENTMETRICS, because I cannot find the appropriate font, and I am sure it's nowhere near what I want.

It's simpler to explain with code and the output.
[source]LOGFONT cur_font = {0};
HFONT hcur_font,hrotated_font;


NONCLIENTMETRICS Nm;
memset(&Nm,0,sizeof(Nm));
Nm.cbSize=sizeof(NONCLIENTMETRICS);

SystemParametersInfo(SPI_GETNONCLIENTMETRICS,sizeof(NONCLIENTMETRICS),&(Nm),0);

hrotated_font = CreateFontIndirect(&(Nm.lfStatusFont));

hcur_font = (HFONT)SelectObject(hDC, (HFONT)hrotated_font);

TextOut(hDC,500,600,"vertical",(int)strlen("vertical"));


SelectObject(hDC, (HFONT)hcur_font);

TextOut(hDC,500,500,"horizontal",(int)strlen("horizontal"));[/source] And
[source]LOGFONT cur_font = {0};
HFONT hcur_font,hrotated_font;

GetObject(hcur_font=(HFONT)GetCurrentObject(hDC, OBJ_FONT),sizeof(LOGFONT),&cur_font);

hrotated_font = CreateFontIndirect(&cur_font);

SelectObject(hDC, (HFONT)hrotated_font);

TextOut(hDC,500,600,"vertical",(int)strlen("vertical"));


SelectObject(hDC, (HFONT)hcur_font);

TextOut(hDC,500,500,"horizontal",(int)strlen("horizontal"));[/source]

With the first, the output:
[attachment=4990:bugg.JPG]
With the second method, I get a puny little "vertical" text.
The "horizontal" text is the default font (the font that gets displayed if I don't do anything with fonts)

Of course, I could get around this by explicitly defining the font for both texts, but it's just mind boggling that I cannot simply get the attributes of the font that's displayed.....

I am totally lost, thanks for any hints!
Advertisement
Call GetStockObject() with the appropriate font selector.

Wielder of the Sacred Wands
[Work - ArenaNet] [Epoch Language] [Scribblings]

Awwwww.
I've found GetStockObject, but I was blinded by the "anger" and didn't see those parameters.

Thanks!

This topic is closed to new replies.

Advertisement