基本信息
源码名称:MFC打印实例
源码大小:9.21M
文件格式:.rar
开发语言:C/C++
更新时间:2021-11-23
   友情提示:(无需注册或充值,赞助后即可获取资源下载链接)

     嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300

本次赞助数额为: 2 元 
   源码介绍
调用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;
}