?
Solved

space under a font

Posted on 2010-01-11
5
Medium Priority
?
245 Views
Last Modified: 2013-11-20
Is there a way I can determine the space under a font in MFC?

John
0
Comment
Question by:IssacJones
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 7

Expert Comment

by:js-profi
ID: 26285547
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.
0
 

Author Comment

by:IssacJones
ID: 26285972
Hi

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.

John
0
 
LVL 7

Expert Comment

by:js-profi
ID: 26286057
call
   CClient dc(this);
   TEXTMETRIC tm = { 0 };
   dc.GetTextMetrics(&tm);

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;
      newFont.Create...();
      CClient dc(this);
      CFont * pOldFont = dc.SelectObject(&newFont);

before calling GetTextMetrics.
0
 
LVL 33

Accepted Solution

by:
pgnatyuk earned 1000 total points
ID: 26286295
GetTextExtendPoint32, like:

SelectObject(hDC, hFont);
GetTextExtentPoint32(bla-bla-bla);

MSDN:
http://msdn.microsoft.com/en-us/library/ms901137.aspx

Example
http://msdn.microsoft.com/en-us/library/dd162491(VS.85).aspx

Another example:
http://www.ucancode.net/Visual_C_Codes/Calculate-width-text-GetTextExtentPoint32-DT_CALCRECT-GetCharABCWidths-VC-Article.htm

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);

0
 

Author Closing Comment

by:IssacJones
ID: 31675589
Thanks
0

Featured Post

Get MySQL database support online, now!

At Percona’s web store you can order your MySQL database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit card.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Suggested Courses

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question