Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7415995
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T07:24:17+00:00 2026-05-29T07:24:17+00:00

I am reading Programming.Windows.5th.Edition,Charles Petzold when I was doing the Figure 4-5. SYSMETS1.C,I met

  • 0

I am reading

Programming.Windows.5th.Edition,Charles Petzold

when I was doing the Figure 4-5. SYSMETS1.C,I met the following codes:

cxCaps = (tm.tmPitchAndFamily & 1 ? 3 : 2) * cxChar / 2 ;

and there are explanations in the book,

SYSMETS1 also saves an average width of uppercase letters in the static variable cxCaps. For a fixed-pitch font, cxCaps would equal cxChar. For a variable-width font, cxCaps is set to 150 percent of cxChar. The low bit of the tmPitchAndFamily field in the TEXTMETRIC structure is 1 for a variable-width font and 0 for a fixed-pitch font. SYSMETS1 uses this bit to calculate cxCaps from cxChar.

Now that cxCaps is set to 150 percent of cxChar,I think it should be

cxCaps = (tm.tmPitchAndFamily & 1 ? 3.0 : 2.0) * cxChar / 2 ;

Can you explain it for me?Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T07:24:18+00:00Added an answer on May 29, 2026 at 7:24 am

    It is trying to calculate an integer result, expressed in pixels. The effective calculation is (3 * cxChar) / 2, not 3 * (cxChar / 2). Presumably the latter one is giving you pause.

    It’s going to get rounded down for a proportional font but will never be off by more than a single pixel. It doesn’t matter since the value is only a guess anyway, the actual width is different for every glyph in a proportional font.

    No points scored for readability, you could perhaps rewrite it like this:

    bool proportional = tm.tmPitchAndFamily & TMPF_FIXED_PITCH;
    if (proportional) cxCaps = (3 * cxChar) / 2;
    else cxCaps = cxChar;
    

    Note how the flag has the wrong name, perhaps the reason Petzold wrote it like that.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am reading Charles Petzold's Programming windows. 5th Edition. And there is a statement
I'm new to Windows programming and after reading the Petzold book I wonder: is
I'm reading a book about programming ASP.NET in C#. The book makes the following
I'm at the moment reading Concurrent Programming on Windows by Joe Duffy, and came
thanks for reading my post i am programming a Windows Service, and when i
I am just a beginner at windows programming and was reading a tutorial about
I'm reading Programming for Java Virtual Machine by Joshua Engel book where the author
I am reading Programming in Objective-C 4th Ed. by Stephen G. Kochan. In the
I'm reading Programming Perl , and I found this code snippet: sub new {
tl:dr how does decoupling work? could need some little example I'm reading Programming Ruby

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.