We're trying to use a CRichEditCtrl to add some formatted text to the printout of an existing MFC application.
Our existing code sets the output DC to have a MM_ISOTROPIC mapping mode, and we have a CRect that defines logical coordinates of the rectangle into which we'd like to draw the rich text.
After putting a little text into the CRichEditCtrl, we're having problems figuring out how to make this text appear at the correct position and with the correct font size.
fmtRange.hdc = pDC->m_hDC;
fmtRange.hdcTarget = pDC->m_hAttribDC;
fmtRange.rc = rect;
fmtRange.rcPage = rect;
fmtRange.chrg.cpMin = 0;
fmtRange.chrg.cpMax = -1;
The effect is that the RichText is drawn, but in the wrong place on the DC, and the fonts are about half the correct size.
I suspect we're missing some requirement about setting a different mapping mode and/or window & viewports, but by now my head is spinning; examples seem rather thin on the ground, and are a bit contradictory.
I guess the first question is: does the RichTextCtrl require the DC to be set up in a specific way (a specific mapping mode?).
Next, the fmtRange.rc and .rcPage members confuse me. What do these rectangles correspond to? The documentation just says "rcPage: The entire area of a page on the rendering device. Units are measured in twips" & "rc: The area within the rcPage rectangle to render to. Units are measured in twips." In our situation, where we would like to render the entire RichTextCtrl contents into a small rectangular region of the page, should rcPage really be the full page coordinates or just the coordinates of the rectangle we want to draw into.
Can anyone offer suggestions or point me to a good example of using a CRichEditCtrl to add a box of formatted text to the display/output of an existing program?