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

CRichEditCtrl Vertical alignment

Good day:

I have a CRichEditCtrl 2.0 on a dialog.  It 'is' multiline, however it will be rare if ever that the text will be vertically to large for the control, although it 'might' happen when the application is localized to other languages.  There is no horizontal scrollbar in this control and the words will wrap to the next line if they reach the horizontal limit.

The issue is that I need to Vertically Align the block of text within the control.  I can probably rig something up if there is a descent way to measure the overall height of the text block.  (then I can set the text rect to that height and set the top point of the text block to lower in the control to make it appear centered.

How would I go about doing this?

Thanks
0
r2far
Asked:
r2far
  • 4
  • 2
1 Solution
 
mahesh1402Commented:
>>there is a descent way to measure the overall height of the text block.

Have a look at Win32 API GetTextExtent/GetTextExtentPoint32 which computes width and height of the specified string of text.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/gdi/fontext_8smq.asp

You may also call CPaintDC::DrawText() function with DT_CALCRECT parameter to compute required rect of text block
http://msdn2.microsoft.com/en-us/library/a6x7y2a4.aspx

-MAHESH
0
 
mahesh1402Commented:
NOTE : Do not forget to select font in your Device Context ( DC ) that you are using in your CRichEditCtrl before invoking above text size computing functions.
0
 
r2farAuthor Commented:
Thanks for you response.

The only problem is that the text block is formated (multi-line, potentially variable height on different lines).  Which is why I am using CRichEditCtrl in the first place.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
mahesh1402Commented:
>>The only problem is that the text block is formated (

obtain text block height with above functions....obtain window rect of CRichEditCtrl..compare both rects..you will come to know how many lines of text is there..then you may be able to obgtain total text height equal to single text(or character ) height multiplied by number of lines...

-MAHESH
0
 
r2farAuthor Commented:
I was hoping there would be an easier solution (such as a function within the rich edit control to tell how much height it's text requires).  But thank you for your help.
0
 
mahesh1402Commented:
>>I was hoping there would be an easier solution

may be due to rich edit is a window..and getting text dimension is not a window oriented function...you may require text dimensions at any time..so it seems its not included within rich edit control

-MAHESH
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

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