• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 231
  • Last Modified:

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
0
trillo
Asked:
trillo
  • 3
  • 2
1 Solution
 
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
 
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

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now