Pelles C forum
C language => Expert questions => Topic started by: EdPellesC99 on December 09, 2010, 10:15:22 PM
-
Hi I am changing my font using the CreateFont. It all works for me except the calculation for the em size from my point size.
I am getting some sort of default.
Here:
HFONT font;
long lfHeight;\
lfHeight = -MulDiv(12, GetDeviceCaps(hdc, LOGPIXELSY), 72); //... logical height of font that is 12 point will be calculated.
font = CreateFont(lfHeight, //.............................int nHeight, logical height of font
0, //........................................int nWidth, logical average character width
0, //........................................int nEscapement, angle of escapement
0, //........................................int nOrientation, base-line orientation angle
FW_NORMAL, //...................int fnWeight, font weight
FALSE, //...............................DWORD fdwItalic, italic attribute flag
FALSE, //...............................DWORD fdwUnderline, underline attribute flag
FALSE, //...............................DWORD fdwStrikeOut, strikeout attribute flag
ANSI_CHARSET, //.............................DWORD fdwCharSet, character set identifier
OUT_DEFAULT_PRECIS, //.............DWORD fdwOutputPrecision, output precision
CLIP_DEFAULT_PRECIS, //.............DWORD fdwClipPrecision, clipping precision
PROOF_QUALITY, //..........................DWORD fdwQuality, output quality
VARIABLE_PITCH|FF_DECORATIVE, //....DWORD fdwPitchAndFamily, pitch and family
"Comic Sans MS"); //.........................LPCTSTR lpszFace pointer to typeface name string
SelectObject(hdc, font);\
SetTextColor(hdc, RGB(240,240,96));
I am getting my font and all other features I want (proven by changing). But I want to be able to control the text size.
In this line:
lfHeight = -MulDiv(12, GetDeviceCaps(hdc, LOGPIXELSY), 72); //... logical height of font that is 12 point will be calculated.
If a change 12 to 30, my text size does not change! No modification up or down affects the text !
If I ignore calculation and hard code -40 (a "bigger" negative number).... no problem I get a big text size (obviously not 40 pt).
So hard coding a negative integer in .... -10 or -50, and my text size always goes up or down like it should.
font = CreateFont(-40, //.............................int nHeight, logical height of font
0, //........................................int nWidth, logical average character width
0, //........................................int nEscapement, angle of escapement
0, //........................................int nOrientation, base-line orientation angle
FW_NORMAL, //...................int fnWeight, font weight
etc etc.....
What BIG thing am I doing wrong in this line:
lfHeight = -MulDiv(12, GetDeviceCaps(hdc, LOGPIXELSY), 72);
I almost got to the finish line understanding the font change. But I seem to be stymied here (not a rare event).
Thanks in advance,
Ed
-
Ed,
If you would modify your line to:
myHeight = -MulDiv(10, GetDeviceCaps(GetDC(hWnd), LOGPIXELSY), 72);
You will find that all is well in the world of Pelles C.
As Pelle's "100 + error message says".......... "try to improve yourself".
Problem solved.
Your welcome,
Ed
-
As Pelle's "100 + error message says".......... "try to improve yourself".
LOL... I nearly fell off my chair laughing the first time I saw that... and all over a misplaced closing brace.
-
Yes,
I always see it when I compile a console app w/ a windows.h, before I can add the -Ze option.
I too laughed, and realized Pelle must have a good sense of humor.
...... Something that is good thing for all of us !
I just heard an NPR interview will Will Short, the puzzle guy of the New York Times...... he was saying that having a good
laugh helps us solve problems.
Researchers have found that it puts us in a playfull mood, and that helps us think creatively
and solve problems........... and THAT is something we all need !!!!!!
(I laughed also at your username and avator!)
later, Ed