Solved

CRichEditCtrl Vertical alignment

Posted on 2006-07-18
6
874 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
[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
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
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.
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

691 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