使用CRichEditCtrl进行部分打印输出 [英] using CRichEditCtrl for part of printout

查看:160
本文介绍了使用CRichEditCtrl进行部分打印输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在尝试使用CRichEditCtrl将一些格式化文本添加到现有MFC应用程序的打印输出中。



我们现有的代码将输出DC设置为有一个MM_ISOTROPIC映射模式,我们有一个CRect定义了我们想要绘制富文本的矩形的逻辑坐标。



放一个将小文本放入CRichEditCtrl中,我们在确定如何使文本显示在正确位置并使用正确的字体大小时遇到​​问题。



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.

// CRect rect contains the LP of the rectangle we'd like to draw into
// setup the format range attributes
fmtRange.hdc = pDC->m_hDC;
fmtRange.hdcTarget = pDC->m_hAttribDC;
fmtRange.rc = rect;
fmtRange.rcPage = rect;
fmtRange.chrg.cpMin = 0;
fmtRange.chrg.cpMax = -1;

m_pRichEdit->FormatRange(&fmtRange, TRUE);
m_pRichEdit->DisplayBand(&rect);





效果是RichText被绘制,但在DC上的错误位置,字体大小正确一半。



我怀疑我们缺少一些关于设置不同映射模式的要求和/或窗口&视口,但到现在我的头在旋转;示例在地面看起来相当薄,并且有点矛盾。



我想第一个问题是:RichTextCtrl是否需要在特定的情况下设置DC方式(特定的映射模式?)。



接下来,fmtRange.rc和.rcPage成员让我感到困惑。这些矩形对应的是什么?文档只是说rcPage:渲染设备上页面的整个区域。单位是以缇为单位测量的& rc:要渲染到的rcPage矩形内的区域。单位是以缇为单位测量的。在我们的情况下,我们想将整个RichTextCtrl内容渲染到页面的一个小矩形区域,rcPage应该是整页坐标还是我们想要绘制的矩形的坐标。



任何人都可以提供建议或指向一个使用CRichEditCtrl将一盒格式化文本添加到现有程序的显示/输出的好例子吗?



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?

推荐答案

你缺少的是这个(将mm转换为触发器 - 参见代码中的1440参考)。请注意,下面的代码是从我的代码中剪切掉的,请根据您的具体情况进行调整:



What you are missing is this (convert mm to flops - see 1440 reference in the code). Please note that the code below is cut-n-paste from my code, please adapt it for your situation:

int    nHorizRes = GetDeviceCaps(hPrinterDC, HORZRES);
int    nVertRes = GetDeviceCaps(hPrinterDC, VERTRES);
int     nLogPixelsX = GetDeviceCaps(hPrinterDC, LOGPIXELSX);
int     nLogPixelsY = GetDeviceCaps(hPrinterDC, LOGPIXELSY);

// Ensure the printer DC is in MM_TEXT mode.
SetMapMode ( hPrinterDC, MM_TEXT );

// Rendering to the same DC we are measuring.
ZeroMemory(&fr, sizeof(fr));
fr.hdc = fr.hdcTarget = hPrinterDC;

// Set up the page.
fr.rcPage.left     = fr.rcPage.top = 0;
fr.rcPage.right    = (nHorizRes/nLogPixelsX) * 1440;
fr.rcPage.bottom   = (nVertRes/nLogPixelsY) * 1440;

// Set up 0" margins all around.
fr.rc              = fr.rcPage;


这篇关于使用CRichEditCtrl进行部分打印输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆