工控编程吧
标题:
上位机MFC如何实现分页打印
[打印本页]
作者:
qq263946146
时间:
2019-8-3 10:21
标题:
上位机MFC如何实现分页打印
void CDemoDlg::OnTest()
{
//打印对话框
DWORD dwFlags = PD_ALLPAGES | PD_USEDEVMODECOPIES | PD_NOPAGENUMS
| PD_NOSELECTION | PD_HIDEPRINTTOFILE;
CPrintDialog dlg(FALSE);
if (dlg.DoModal() == IDOK)
{
//获得打印机DC
HDC hDC = dlg.GetPrinterDC();
if (hDC == NULL)
{
return;
}
//通过HDC获得CDC指针
CDC* pDC = CDC::FromHandle(hDC);
pDC->m_bPrinting = TRUE;
//文档信息
DOCINFO di;
::ZeroMemory (&di, sizeof (DOCINFO));
di.cbSize = sizeof (DOCINFO);
di.lpszDocName = _T("Demo");
//开始打印
BOOL bPrinting = pDC->StartDoc(&di);
for (UINT nPage = 0; nPage < 10 && bPrinting; nPage++)
{
pDC->StartPage();
//输出文本
CString strText = _T("");
strText.Format(_T("第%d页"), nPage + 1);
pDC->TextOut(100, 0, strText);
pDC->TextOut(100, 200, _T("Hello World!"));
bPrinting = (pDC->EndPage() > 0);
}
if (bPrinting)
{
pDC->EndDoc();
}
else
{
pDC->AbortDoc();
}
//结束打印
pDC->EndDoc();
//删除DC
pDC->DeleteDC();
}
}
复制代码
可以看到开始打印,结束打印,暂停打印对应函数为
StartDoc,
EndDoc,
AbortDoc
。
打开分布打印对应函数为
StartPage,
EndPage
欢迎光临 工控编程吧 (https://www.gkbc8.com/)
Powered by Discuz! X3.4