Jump to content
  • Advertisement
Sign in to follow this  
szecs

Default font problem win32 C

This topic is 2468 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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!

Share this post


Link to post
Share on other sites
Advertisement
Awwwww.
I've found GetStockObject, but I was blinded by the "anger" and didn't see those parameters.

Thanks!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!