Click here to Skip to main content
15,881,882 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: How to get the Font width ??? Pin
Steve S15-Aug-05 0:22
Steve S15-Aug-05 0:22 
AnswerRe: How to get the Font width ??? Pin
Steve S15-Aug-05 0:21
Steve S15-Aug-05 0:21 
AnswerRe: How to get the Font width ??? Pin
mark novak15-Aug-05 0:30
mark novak15-Aug-05 0:30 
GeneralRe: How to get the Font width ??? Pin
HumanOsc15-Aug-05 0:31
HumanOsc15-Aug-05 0:31 
GeneralRe: How to get the Font width ??? Pin
HumanOsc15-Aug-05 0:41
HumanOsc15-Aug-05 0:41 
GeneralRe: How to get the Font width ??? Pin
mark novak15-Aug-05 1:07
mark novak15-Aug-05 1:07 
GeneralRe: How to get the Font width ??? Pin
HumanOsc16-Aug-05 1:38
HumanOsc16-Aug-05 1:38 
GeneralRe: How to get the Font width ??? Pin
mark novak16-Aug-05 2:45
mark novak16-Aug-05 2:45 
Good question.

From the MSDN on LOGFONT:
If lfWidth is zero, the aspect ratio of the device is matched against the digitization aspect ratio of the available fonts to find the closest match, determined by the absolute value of the difference.

The height of a font is in logical units. Which is why a font at size 8 can look huge on a computer with large fonts set.

The Windows GDI was designed to make as little assumptions as possible about what it's drawing on. On a printer 20 pixels is very tiny because it's DPI is so high. There are even monitors that aren't at the normal 96 dpi, so these would not look right if it was embedded with a nonlogical number. Some devices don't even use pixels but other measurements, like twips, so until the DC is set with this information you can't get the width on some fonts.

Why can't you get the font's average width logical units? I'm not sure, perhaps it has to do mostly with the font, whether an accurate font to that size has been selected or not, or whether a font author must set this information in the header. Maybe windows is just reluctant to provide such an inaccurate approximation, I don't know.

In my opinion it doesn't seem like a big deal (apart from being interesting) since it's a logical value anyways. If you were to use it, you'd have to make all the calculations that GetTextMetrics makes for it to work across all DCs. I can't see where you'd use it without a DC.

I hope this makes things somewhat clearer.


GeneralRe: How to get the Font width ??? Pin
HumanOsc22-Aug-05 10:24
HumanOsc22-Aug-05 10:24 
GeneralRe: How to get the Font width ??? Pin
Anonymous18-Oct-05 15:41
Anonymous18-Oct-05 15:41 
GeneralWeird ProgBar Prob... Pin
u6ik14-Aug-05 23:43
u6ik14-Aug-05 23:43 
GeneralRe: Weird ProgBar Prob... Pin
mark novak15-Aug-05 0:19
mark novak15-Aug-05 0:19 
GeneralRe: Weird ProgBar Prob... Pin
u6ik15-Aug-05 1:17
u6ik15-Aug-05 1:17 
Generalopc server and client Pin
xieyig14-Aug-05 23:43
xieyig14-Aug-05 23:43 
Questionhow can I convert a mfc ocx to asp server ocx Pin
xieyig14-Aug-05 23:37
xieyig14-Aug-05 23:37 
GeneralStupid newbies need help. Pin
cue_ball14-Aug-05 22:03
cue_ball14-Aug-05 22:03 
GeneralRe: Stupid newbies need help. Pin
HumanOsc14-Aug-05 23:15
HumanOsc14-Aug-05 23:15 
GeneralRe: Stupid newbies need help. Pin
u6ik15-Aug-05 0:03
u6ik15-Aug-05 0:03 
GeneralRe: Stupid newbies need help. Pin
HumanOsc15-Aug-05 0:10
HumanOsc15-Aug-05 0:10 
GeneralC++ and Python Questions... Pin
Raistlfiren14-Aug-05 18:46
Raistlfiren14-Aug-05 18:46 
GeneralRe: C++ and Python Questions... Pin
code-frog14-Aug-05 19:00
professionalcode-frog14-Aug-05 19:00 
GeneralRe: C++ and Python Questions... Pin
Raistlfiren14-Aug-05 19:16
Raistlfiren14-Aug-05 19:16 
GeneralRe: C++ and Python Questions... Pin
code-frog14-Aug-05 19:35
professionalcode-frog14-Aug-05 19:35 
GeneralRe: C++ and Python Questions... Pin
Raistlfiren14-Aug-05 19:55
Raistlfiren14-Aug-05 19:55 
GeneralRe: C++ and Python Questions... Pin
code-frog14-Aug-05 21:26
professionalcode-frog14-Aug-05 21:26 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.