CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Dec 2012

    CRichEditCtrl::FormatRange result differ in VC++ 6.0 and 2010


    Ich have ported my application from VC++ 6.0 to VC++ 2010.
    Now code that was working in VC++ 6.0 is not working anymore in VC++ 2010.
    In my case I am writing text to a CRTFEditCtrl and then want to calculate the height of the complete text.
    For calculating the height the FORMATRANGE.rc.bottom value, that has been returned from the CRichEditCtrl::FormatRange() fct., is used.
    In VC++ 6.0 the rc.bottom value is '=2160' whereas in VC++ 2010 the value is '=499920'.
    Also the return value of FormatRange() differs, in VC++ 6.0 it is '=104' and in VC++ 2010 it is '=103'

    Does anybody what the Problem could be?

    In the code below the value I get for 'gs_LastRTFHeight' is '=144' in VC++ 6.0 and '=33328' in VC++ 2010

    Here is my code:

    DrawRTF(TextToDraw,100 * 1.0);
    static void BSDrawRTF(const char * t, const char* limit)
    	gs_LastRTFWidth			= 0;
    	gs_LastRTFHeight		= 0;
    	if (strlen(t) == 0)
    	long	Limit = max(0,atol(limit));
    	CDC dcTarget;
    	dcTarget.CreateDC("DISPLAY", NULL, NULL, NULL);
    	CRect	OutRect;
    	OutRect.left	= 0;
    	OutRect.top		= 0;
    	OutRect.right	= Limit ?
    						::MulDiv(Limit, 1440, dcTarget.GetDeviceCaps(LOGPIXELSX)) :
    	OutRect.bottom	= 500000;
    	CTORTFFormater::GetEdit()->SetTargetDevice(dcTarget, OutRect.right);
    	FRange.hdc			= dcTarget.m_hDC;
    	FRange.hdcTarget	= dcTarget.m_hDC;
    	FRange.rc			= OutRect;
    	FRange.rcPage		= OutRect;
    	FRange.chrg.cpMin	= 0;
    	FRange.chrg.cpMax	= CTORTFFormater::GetEdit()->GetTextLength();
    	long lIndex = CTORTFFormater::GetEdit()->FormatRange(&FRange, FALSE);
    	gs_LastRTFWidth		= ::MulDiv(dcTarget.GetDeviceCaps(LOGPIXELSX), FRange.rc.right,  1440);
    	gs_LastRTFHeight	= ::MulDiv(dcTarget.GetDeviceCaps(LOGPIXELSX), FRange.rc.bottom, 1440);
    	CTORTFFormater::GetEdit()->FormatRange(NULL, FALSE);	// release the cached DC information stored in SetTargetDevice
    	CTORTFFormater::GetEdit()->SetControlWidth(0);		// restore the original 
    	CString s;
    	s.Format("RTFTEXT:%d,%d,%d,%ld", gs_CurrentPainter->AddRTFText(t), gs_LastRTFWidth, gs_LastRTFHeight, Limit);
    	gs_PaintData += s + "\r\n";

  2. #2
    Join Date
    May 2004
    45,000FT Above Nevada

    Re: CRichEditCtrl::FormatRange result differ in VC++ 6.0 and 2010

    Using LOGPIXELSX to calc gs_LastRTFHeight might be a downfall ??


    gs_LastRTFHeight	= ::MulDiv(dcTarget.GetDeviceCaps(LOGPIXELSX), FRange.rc.bottom, 1440);
    Last edited by Vanaj; December 13th, 2012 at 12:52 PM.
    ATP BE400 CE500 (C550B-SPW) CE560XL MU300 CFI CFII

    "The speed of non working code is irrelevant"... Of course that is just my opinion, I could be wrong.

    "Nothing in the world can take the place of persistence. Talent will not; nothing is more common than unsuccessful men with talent. Genius will not; unrewarded genius is almost a proverb. Education will not; the world is full of educated derelicts. Persistence and determination are omnipotent. The slogan 'press on' has solved and always will solve the problems of the human race."...Calvin Coolidge 30th President of the USA.

  3. #3
    Join Date
    Dec 2012

    Re: CRichEditCtrl::FormatRange result differ in VC++ 6.0 and 2010

    Hello Vanja,

    Thank you very much for your answer. Your are right its better to calculate the heigth using LOGPIXELSY rather then LOGPIXELSX, but the calculation is not the problem here.

    The problem is that the FORMATRANGE.rc.bottom value is way to big after calling the FormatRange() fct.
    In VC++ 6.0 the FORMATRANGE.rc.bottom value is =2160 and in VC++ 2010 it is =499920.


  4. #4
    Join Date
    Apr 1999

    Re: CRichEditCtrl::FormatRange result differ in VC++ 6.0 and 2010

    Quote Originally Posted by rgwerder1 View Post
    The problem is that the FORMATRANGE.rc.bottom value is way to big after calling the FormatRange() fct.
    In VC++ 6.0 the FORMATRANGE.rc.bottom value is =2160 and in VC++ 2010 it is =499920.
    Well, why not debug both the VC 6.0 and VC 2010 and see where the results start to diverge? Be your own problem solver.

    You should have the full MFC source code, so unless it is a change in the MFC source code, the issue may be your own code and not the differences in the compiler. It would also help if you made just one function call per line, instead of assuming what a function will return and use that return value.
    You keep doing that over and over again in that piece of code. First, never assume that you get back a valid CWnd or the CWnd that you're expecting to get back. Second, assign the return value to a CWnd* variable and just use that variable. This saves from you making the function call repeatedly.

    What is "GetEdit()"? I don't think it's an MFC function, unless I'm mistaken.
    Do you know what these are, or are you assuming what these values are? Again, store these in variables, inspect to make sure they are exactly the same and valid, and then just use those variable.

    Once you've established that the GetEdit() returns a valid CWnd pointer, and those values are exactly the same between versions of VC++, then debug into the FormatRange() function to see what's going on.


    Paul McKenzie
    Last edited by Paul McKenzie; December 14th, 2012 at 10:24 AM.

  5. #5
    Join Date
    Feb 2003
    Iasi - Romania

    Re: CRichEditCtrl::FormatRange result differ in VC++ 6.0 and 2010

    Chech which version of RichEdit control is used in your aplication. Different versions of MFC may load different RichEdit versions, that may behave different in some particular cases.
    As an example, CRichEditView loads and uses RichEdit control version 1.0 in VS6.0. In VS2010, version 2.1 is loaded and used.

    To find out how to play with different versions of RichEdit in an MFC application, have a look in this Codeguru article:
    How to Use RichEditControl 4.1 in CRichEditView.
    Last edited by ovidiucucu; December 15th, 2012 at 05:03 AM.
    "When in Rome, do as Romans do."
    My latest articles: http://codexpert.ro/blog/author/ovidiu-cucu/

  6. #6
    Join Date
    Dec 2012

    Re: CRichEditCtrl::FormatRange result differ in VC++ 6.0 and 2010

    Hello everbody,
    Thank your for your answers.
    I have found a solution for my problem.

    Instead of using the 'GetTextLength()' function I am using the 'GetTextLengthEx()' function:

    old code:
    FRange.chrg.cpMax	= pEdit->GetTextLength();
    new code:
    FRange.chrg.cpMax	= pEdit->GetTextLengthEx(GTL_PRECISE | GTL_NUMCHARS);
    The GetTextLength() was e.g returning 'length=104' whereas GetTextLengthEx() was returning 'length=102'.


Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.