📄 printing_wo_docview.shtml.htm
字号:
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<META NAME="Author" CONTENT="Zafir Anjum">
<TITLE>Printing - Printing without the Document/View framework</TITLE>
</HEAD>
<body background="../fancyhome/back.gif" tppabs="http://www.codeguru.com/fancyhome/back.gif" bgcolor="#FFFFFF" link="#B50029" vlink="#8E2323" alink="#FF0000" bgproperties="fixed">
<table WIDTH="100%">
<tr WIDTH="100%">
<td><td>
</tr>
</table>
<CENTER>
<H3>
<FONT COLOR="#AOAO99">Printing without the Document/View framework</FONT></H3></CENTER>
<HR>
This article was contributed by <a href="mailto:Chris.Maunder@cbr.clw.csiro.au">Chris Maunder</a>.
<p>If you have a dialog based application and want to print, then you
cannot take advantage of the Doc/View framework that MFC provides to
do all the dirty work for you.
<p>In order to keep the MFC doc/View feel I recomend providing helper
functions <b>OnBeginPrinting</b>, <b>OnEndPrinting</b> and <b>OnPrint</b>
similar to the CView versions. A <b>CDC</b> and a <b>CPrintInfo</b> object
is passed into each of these functions.
<PRE><TT><FONT COLOR="#990000">
void CMyDialog::Print()
{
CDC dc;
CPrintDialog printDlg(FALSE);
if (printDlg.DoModal() == IDCANCEL) // Get printer settings from user
return;
dc.Attach(printDlg.GetPrinterDC()); // Attach a printer DC
dc.m_bPrinting = TRUE;
CString strTitle; // Get the application title
strTitle.LoadString(AFX_IDS_APP_TITLE);
DOCINFO di; // Initialise print document details
::ZeroMemory (&di, sizeof (DOCINFO));
di.cbSize = sizeof (DOCINFO);
di.lpszDocName = strTitle;
BOOL bPrintingOK = dc.StartDoc(&di); // Begin a new print job
// Get the printing extents and store in the m_rectDraw field of a
// CPrintInfo object
CPrintInfo Info;
Info.m_rectDraw.SetRect(0,0,
dc.GetDeviceCaps(HORZRES),
dc.GetDeviceCaps(VERTRES));
OnBeginPrinting(&dc, &Info); // Initialise printing
for (UINT page = Info.GetMinPage();
page <= Info.GetMaxPage() && bPrintingOK;
page++)
{
dc.StartPage(); // begin new page
Info.m_nCurPage = page;
OnPrint(&dc, &Info); // Print page
bPrintingOK = (dc.EndPage() > 0); // end page
}
OnEndPrinting(&dc, &Info); // Clean up after printing
if (bPrintingOK)
dc.EndDoc(); // end a print job
else
dc.AbortDoc(); // abort job.
dc.Detach(); // detach the printer DC
}</FONT></TT></PRE>
<P>Posted: March, 8, 98
<P>
<HR>
<TABLE BORDER=0 WIDTH="100%" >
<TR>
<TD WIDTH="33%"><FONT SIZE=-1><A HREF="../index.htm" tppabs="http://www.codeguru.com/">Goto HomePage</A></FONT></TD>
<TD WIDTH="33%">
<CENTER><FONT SIZE=-2>© 1997 Zafir Anjum</FONT> </CENTER>
</TD>
<TD WIDTH="34%">
<DIV ALIGN=right><FONT SIZE=-1>Contact me: <A HREF="mailto:zafir@home.com">zafir@home.com</A> </FONT></DIV>
</TD>
</TR>
</TABLE>
<CENTER><FONT SIZE=-2>4286</FONT></CENTER>
</BODY>
</HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -