• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 257
  • Last Modified:

font size

Hi!
I draw a text with a specific height with TextOut routine but, after a mouse action, I want this text size (font size) to fit inside a specific rectangle; so, I should know the font height that should be set according to this rectangle width.  Do anyone know how to do it (this routine will be inserted or called from a mouse click event handle).
Thanks in advance.
0
marakr
Asked:
marakr
  • 2
1 Solution
 
jhattinghCommented:
Use:

CSize GetOutputTextExtent( const CString& str ) const;

Return Value: The dimensions of the string (in logical units) returned in a CSize object.

.... and check it's width and height against the coordinates created from your mouse movements.
0
 
marakrAuthor Commented:
Thanks for your answer. I was just wondering how would I really change it (I meant pDC->SelectObject(...)).  I really don't know how to work with those device contexts.
Could you give me bit more details?
0
 
jhattinghCommented:
1] set a (bool m_bMouseDown) to true when LMB is down and to false when LMB is released.

2] When the mouse is down, set a member CSize variable to equal the current CPoint variable passed in the override.

3] When the "LMB Up" is fired, check the difference between the CSize variable and the now-supplied CPoint variable

4] Apply the following pseudo code:

for (int n = 1; n < MAXSIZE; n++)
{
  Create a CFont object
 
  Get the LOGFONT structure and
  increment it's size

  Use the CDC::SelectObject to use
  the font

  Use GetOutputTextExtent() to compare
  the new size of the text with the
  CSize that you got from the user's
  mouse drag movements

  If either the new height or new
  width reaches the relative dimensions
  of the user-specified CSize, then go
  ahead and use CDC::DrawText to do
  it's thang, and 'continue' to leave
  the for-loop...!
}

I hope this helps.

LWJason
0

Featured Post

[Webinar] Kill tickets & tabs using PowerShell

Are you tired of cycling through the same browser tabs everyday to close the same repetitive tickets? In this webinar JumpCloud will show how you can leverage RESTful APIs to build your own PowerShell modules to kill tickets & tabs using the PowerShell command Invoke-RestMethod.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now