Solved

CRichEditCtrl Vertical alignment

Posted on 2006-07-18
6
831 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Decoding 32 bit binary streams 6 31
string initialization in java 11 103
Fibonacci challenge 11 84
Problem to event 3 50
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.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

758 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

25 Experts available now in Live!

Get 1:1 Help Now