MFC:如何打印 CRichEditView 的内容?
MFC: How do you print contents of a CRichEditView?
我有一个简单的任务需要打印 CRichEditView 的内容。无需缩放,无打印范围,仅打印内容。为简单起见,我尝试将其添加到消息映射中:
ON_COMMAND(ID_FILE_PRINT, &CRichEditView::OnFilePrint)
并实现虚函数:
BOOL CMyRichView::OnPreparePrinting(CPrintInfo* pInfo)
{
return DoPreparePrinting(pInfo);
}
但是当它打印时(这是实际要打印的内容):
BOOL CMyRichView::OnPreparePrinting(CPrintInfo* pInfo)
{
return DoPreparePrinting(pInfo);
}
我在 return "eturn DoPreparePrinting(pInfo);" 上只得到了 'r' 的一半。所以它似乎必须与边距或 CRichEditView
无法自行处理的东西有关?
我错过了什么?
TIA!!
编辑:
我尝试将其更改为
BOOL CMyRichView::OnPreparePrinting(CPrintInfo* pInfo)
{
// note a MM_TWIPS is 1/1440 of an inch.
// create 1/2" margin which most printers support
CSize sizepaper = GetPaperSize();
CRect rectmargins(720, 720, sizepaper.cx - 720, sizepaper.cy - 720);
// Need to set the margins when printing from CRichEditView
SetMargins(rectmargins);
// per SetMargins API reference, call wrapchanged
if (m_nWordWrap==WrapToTargetDevice) {
WrapChanged();
}
return DoPreparePrinting(pInfo);
}
但现在它只是吐出成吨的白纸。在调用基 class 之前,我还在虚函数 OnPrint(CDC* pDC, CPrintInfo* pInfo)
中尝试过它。同样的结果,所以删除 OnPrint()
(不使用它)。
编辑:
所以我从 GetPaperSize()
文档中获取了上面的示例。但这是错误的。它使用它工作(SetPaperSize()
的文档使用)。
BOOL CMyRichView::OnPrint(CDC* pDC, CPrintInfo* pInfo)
{
// note a MM_TWIPS is 1/1440 of an inch.
// Need to set the margins when printing from CRichEditView
SetMargins(CRect(720, 720, 720, 720));
// per SetMargins API reference, call wrapchanged
if (m_nWordWrap==WrapToTargetDevice) {
WrapChanged();
}
return __super::OnPrint(pDC, pInfo);
}
答案是:
ON_COMMAND(ID_FILE_PRINT, &CRichEditView::OnFilePrint)
BOOL CMyRichView::OnPreparePrinting(CPrintInfo* pInfo)
{
return DoPreparePrinting(pInfo);
}
BOOL CMyRichView::OnPrint(CDC* pDC, CPrintInfo* pInfo)
{
// note a MM_TWIPS is 1/1440 of an inch.
// Need to set the margins when printing from CRichEditView
SetMargins(CRect(720, 720, 720, 720));
// per SetMargins API reference, call wrapchanged
if (m_nWordWrap==WrapToTargetDevice) {
WrapChanged();
}
return __super::OnPrint(pDC, pInfo);
}
我有一个简单的任务需要打印 CRichEditView 的内容。无需缩放,无打印范围,仅打印内容。为简单起见,我尝试将其添加到消息映射中:
ON_COMMAND(ID_FILE_PRINT, &CRichEditView::OnFilePrint)
并实现虚函数:
BOOL CMyRichView::OnPreparePrinting(CPrintInfo* pInfo)
{
return DoPreparePrinting(pInfo);
}
但是当它打印时(这是实际要打印的内容):
BOOL CMyRichView::OnPreparePrinting(CPrintInfo* pInfo)
{
return DoPreparePrinting(pInfo);
}
我在 return "eturn DoPreparePrinting(pInfo);" 上只得到了 'r' 的一半。所以它似乎必须与边距或 CRichEditView
无法自行处理的东西有关?
我错过了什么?
TIA!!
编辑:
我尝试将其更改为
BOOL CMyRichView::OnPreparePrinting(CPrintInfo* pInfo)
{
// note a MM_TWIPS is 1/1440 of an inch.
// create 1/2" margin which most printers support
CSize sizepaper = GetPaperSize();
CRect rectmargins(720, 720, sizepaper.cx - 720, sizepaper.cy - 720);
// Need to set the margins when printing from CRichEditView
SetMargins(rectmargins);
// per SetMargins API reference, call wrapchanged
if (m_nWordWrap==WrapToTargetDevice) {
WrapChanged();
}
return DoPreparePrinting(pInfo);
}
但现在它只是吐出成吨的白纸。在调用基 class 之前,我还在虚函数 OnPrint(CDC* pDC, CPrintInfo* pInfo)
中尝试过它。同样的结果,所以删除 OnPrint()
(不使用它)。
编辑:
所以我从 GetPaperSize()
文档中获取了上面的示例。但这是错误的。它使用它工作(SetPaperSize()
的文档使用)。
BOOL CMyRichView::OnPrint(CDC* pDC, CPrintInfo* pInfo)
{
// note a MM_TWIPS is 1/1440 of an inch.
// Need to set the margins when printing from CRichEditView
SetMargins(CRect(720, 720, 720, 720));
// per SetMargins API reference, call wrapchanged
if (m_nWordWrap==WrapToTargetDevice) {
WrapChanged();
}
return __super::OnPrint(pDC, pInfo);
}
答案是:
ON_COMMAND(ID_FILE_PRINT, &CRichEditView::OnFilePrint)
BOOL CMyRichView::OnPreparePrinting(CPrintInfo* pInfo)
{
return DoPreparePrinting(pInfo);
}
BOOL CMyRichView::OnPrint(CDC* pDC, CPrintInfo* pInfo)
{
// note a MM_TWIPS is 1/1440 of an inch.
// Need to set the margins when printing from CRichEditView
SetMargins(CRect(720, 720, 720, 720));
// per SetMargins API reference, call wrapchanged
if (m_nWordWrap==WrapToTargetDevice) {
WrapChanged();
}
return __super::OnPrint(pDC, pInfo);
}