space under a font

Is there a way I can determine the space under a font in MFC?

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

what do you mean by determine? if you have a CString you could spot a space by Find function (for example).
   CString sHello = "Hello World";
   int spcpos = sHello.Find(' ');

it is regardless what font you were using.

the space char is always ascii code 32 (0x20) for any font.
IssacJonesAuthor Commented:

No, sorry, you've misunderstood. What I need to know is the various dimensions for a given font e.g. if the font sits in some kind of cell (rectangle) how do I find the spacing from the bottom of the cell to the bottom of the font (assuming that is that there is a space).

Similarly, find the space from the top of the font to the top of the rectangle.

   CClient dc(this);
   TEXTMETRIC tm = { 0 };

then the you can retrieve the info from tm structure (think it is tmInternalLeading),

if it some control which has the font required use CWnd pointer of that control instead of this.
if  you have only the font do

      CFont newFont;
      CClient dc(this);
      CFont * pOldFont = dc.SelectObject(&newFont);

before calling GetTextMetrics.
GetTextExtendPoint32, like:

SelectObject(hDC, hFont);



Another example:

The simplest way is just to use DT_CALCRECT in DrawText:
CRect rc(0,0,0,0);
CFont* pOldFont = dc.SelectObject(&font);
dc.DrawText(str, &rc, DT_CALCRECT);


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
IssacJonesAuthor Commented:
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.