Fontsize in Static Ctrl

This must be very easy:

I have a dialog box with a Static control (Static Text). How do I change the font size?
I'm NOT USING MFC !!!

I can obtain a HFONT handle by sending the WM_GETFONT message to the control, and I could send it back with the WM_SETFONT message... but what should I do with that handle to change the font size?... Or am I the complete wrong way?
Thanks
LVL 2
trilloAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

trilloAuthor Commented:
Edited text of question.
0
ZoppoCommented:
Hi trillo,

You'll have to create a new font for a new size, i.e.

HFONT hOrgFont; // get this with WM_GETFONT message
LOGFONT lf;
GetObject( hOrgFont, sizeof( LOGFONT ), (void*)&lf );
lf.lfHeight *= 2;// i.e. double size font
HFONT hNewFont = ::CreateFontIndirect( &lf ); // you should store this handle to delete the font created when not used anymore to avoid resource memory leaks
// use WM_SETFONT with the handle hNewFont to set the font for the control.

hope that helps,

ZOPPO
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
trilloAuthor Commented:
Just what I needed!

I tried what you said and it worked, although my control uses the system font (Ms Sans Serif), and it seems that you can't get the font smaller than default. I could change de typeface in the LOGFONT structure, but how do I handle if that font does not exist in some other machine?

And, by the way, do you how do I change the color of the text in my static control?

Thanks.
0
ZoppoCommented:
Hi trillo,

If the specified font does not exist, the Windows font mapper selects a font which characteristics match the given LOGFONT as near as possible, so for most cases you don't have to worry about it. If you want to find out if a font exist you can use the EnumFontFamilies() API function.

To change the color of the text you'll have to handle the WM_CTLCOLOR message. With this message you recieve a device context handle which you can use to set the text color via SetTextColor(). See help for WM_CTLCOLOR for further infos.

hope that helps,

ZOPPO
0
trilloAuthor Commented:
Thanks a lot.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.