Solved

CRichEditCtrl Vertical alignment

Posted on 2006-07-18
6
837 Views
Last Modified: 2013-11-20
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
Comment
Question by:r2far
  • 4
  • 2
6 Comments
 
LVL 22

Expert Comment

by:mahesh1402
ID: 17135761
>>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
 
LVL 22

Expert Comment

by:mahesh1402
ID: 17136226
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
 
LVL 4

Author Comment

by:r2far
ID: 17138874
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 22

Accepted Solution

by:
mahesh1402 earned 250 total points
ID: 17138990
>>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
 
LVL 4

Author Comment

by:r2far
ID: 17155221
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
 
LVL 22

Expert Comment

by:mahesh1402
ID: 17155305
>>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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Add content to output file 4 62
Separate files macro - Errors on larger data set 18 65
dog bark java program 15 87
canBalance challenge 34 70
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

910 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now