Solved

CRichEditCtrl Vertical alignment

Posted on 2006-07-18
6
859 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

Technology Partners: 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!

Question has a verified solution.

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

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
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.
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

749 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