下你所需,载你所想!
汇集开发技术源码资料

MFC打印实例

:9.207MB :1 :2022-10-10 16:50:56

部分简介

MFC打印实例如果开发者对于本文件有需要的可以参考。
调用Windows自带打印功能,可选用PDF虚拟打印机
void CScribbleView::OnPrint(CDC* pDC, CPrintInfo* pInfo)
{
if (pInfo->m_nCurPage == 1) // page no. 1 is the title page
{
PrintTitlePage(pDC, pInfo);
return; // nothing else to print on page 1 but the page title
}
CString strHeader = GetDocument()->GetTitle();
PrintPageHeader(pDC, pInfo, strHeader);
// PrintPageHeader() subtracts out from the pInfo->m_rectDraw the
// amount of the page used for the header.
pDC->SetWindowOrg(pInfo->m_rectDraw.left,-pInfo->m_rectDraw.top);
// Now print the rest of the page
OnDraw(pDC);
}
void CScribbleView::PrintTitlePage(CDC* pDC, CPrintInfo* pInfo)
{
// Prepare a font size for displaying the file name
LOGFONT logFont;
memset(&logFont, 0, sizeof(LOGFONT));
logFont.lfHeight = 75; // 3/4th inch high in MM_LOENGLISH
// (1/100th inch)
CFont font;
CFont* pOldFont = NULL;
if (font.CreateFontIndirect(&logFont))
pOldFont = pDC->SelectObject(&font);
// Get the file name, to be displayed on title page
CString strPageTitle = GetDocument()->GetTitle();
// Display the file name 1 inch below top of the page,
// centered horizontally
pDC->SetTextAlign(TA_CENTER);
pDC->TextOut(pInfo->m_rectDraw.right/2, -100, strPageTitle);
if (pOldFont != NULL)
pDC->SelectObject(pOldFont);
}
void CScribbleView::PrintPageHeader(CDC* pDC, CPrintInfo* pInfo,
CString& strHeader)
{
// Print a page header consisting of the name of
// the document and a horizontal line
pDC->SetTextAlign(TA_LEFT);
pDC->TextOut(0,-25, strHeader); // 1/4 inch down
// Draw a line across the page, below the header
TEXTMETRIC textMetric;
pDC->GetTextMetrics(&textMetric);
int y = -35 - textMetric.tmHeight; // line 1/10th inch below text
pDC->MoveTo(0, y); // from left margin
pDC->LineTo(pInfo->m_rectDraw.right, y); // to right margin
// Subtract out from the drawing rectange the space used by the header.
y -= 25; // space 1/4 inch below (top of) line
pInfo->m_rectDraw.top = y;
}

MFC打印实例

热门推荐

相关文章