工控编程吧
标题:
上位机MFC如何实现框架之外的打印
[打印本页]
作者:
qq263946146
时间:
2019-8-3 10:16
标题:
上位机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");
//开始打印
pDC->StartDoc(&di);
//输出文本
pDC->TextOut(100, 100, _T("Hello World!"));
//结束打印
pDC->EndDoc();
//删除DC
pDC->DeleteDC();
}
}
复制代码
上面是功能实现的按钮点击函数。可以查看效果。
欢迎光临 工控编程吧 (https://www.gkbc8.com/)
Powered by Discuz! X3.4