r2far
asked on
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
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
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.
ASKER
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.
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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.
>>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
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
Have a look at Win32 API GetTextExtent/GetTextExten
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