Click to See Complete Forum and Search --> : How to change button font
nico27
May 3rd, 2007, 07:08 AM
Hello!
I'm writing a Windows program in C++ using only the Win32 API (no MFC).
My app contains several buttons, but the font used to write the
text on the buttons is too big.
How can I change the font which is used to draw text on a button?
I used CreateFont() already, but found no possiblity to tell the button to use the created font.
Another thing which goes in the same direction:
How can I change the background color of a textbox ("edit" in Win API)?
Thanks for any help!
Nico.
kirants
May 3rd, 2007, 12:11 PM
WM_SETFONT
Make sure the handle returned by CreateFont ( which you will use for the WM_SETFONT message ) is valid throuhgout the lifetime of the button window
Ali Imran
May 5th, 2007, 07:51 AM
Basically the default system font is being used for your controls, and they might be looking BOLD, whic hyou are caling as 'too big'
To normalize the default system font on any kind of window use following if your requirement is not using some non-default font..
HFONT hFont = (HFONT)GetStockObject(DEFAULT_GUI_FONT);
SendMessage(hwnd, WM_SETFONT, (WPARAM)hFont, MAKELPARAM(TRUE, 0));
I hope it helps..
regards
angel_tears
May 5th, 2007, 11:01 AM
can you help me with the variables of CreateFont?
I also want the text font on my buttons to be smaler,but I don't understand which numbers i need to use in order to create the font smaller..
Ali Imran
May 5th, 2007, 11:21 AM
Sorry did not follow what you mean. Here is proto of the function in winapi help manual.
HFONT CreateFont(
int nHeight, // logical height of font
int nWidth, // logical average character width
int nEscapement, // angle of escapement
int nOrientation, // base-line orientation angle
int fnWeight, // font weight
DWORD fdwItalic, // italic attribute flag
DWORD fdwUnderline, // underline attribute flag
DWORD fdwStrikeOut, // strikeout attribute flag
DWORD fdwCharSet, // character set identifier
DWORD fdwOutputPrecision, // output precision
DWORD fdwClipPrecision, // clipping precision
DWORD fdwQuality, // output quality
DWORD fdwPitchAndFamily, // pitch and family
LPCTSTR lpszFace // pointer to typeface name string
);
regards
angel_tears
May 6th, 2007, 07:12 AM
I have seen it,but i dont understand which number I need to use in order to get a small font.
for example,
this variables should be numbers:
int nHeight, // logical height of font
int nWidth, // logical average character width
int nEscapement, // angle of escapement
int nOrientation, // base-line orientation angle
int fnWeight, // font weight
but I don't know which numbers to select so the font will be small..
olivthill
May 7th, 2007, 08:17 AM
In order to have a small font, give a small value to nHeight. The other arguments are used for other purposes.
The value in nHeight depends on the mapping mode. Most of the time (maybe 90%), the MM_TEXT mode is on, but it is safer to enforce it before creating your font with:
SetMapMode(hdc, MM_TEXT);
Then, with MM_TEXT mapping, a small font is a font having its nHeight between 6 and 12.
More info on CreateFont() at http://msdn2.microsoft.com/en-us/library/ms534214.aspx
More info on SetMapMode() at http://msdn2.microsoft.com/en-us/library/ms532673.aspx.
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.