http://www.codeguru.com/printing/printing_wo_docview.shtml Printing without the Document/View framework CDC dc; CPrintDialog printDlg(FALSE); if (printDlg.DoModal() == IDCANCEL) // Get printer settings from user return; dc.Attach(printDlg.GetPrinterDC()); // Attach a printer DC
Printing without the Document/View framework CDC dc;
CPrintDialog printDlg(FALSE); if (printDlg.DoModal() == IDCANCEL) // Get printer settings from user
return; dc.Attach(printDlg.GetPrinterDC()); // Attach a printer DC
http://www.codeguru.com/printing/printing_class_library.shtml
{
pInfo->SetMinPage(1);
pInfo->SetMaxPage(1);
}void CDialogPrintDlg::OnEndPrinting(CDC *pDC, CPrintInfo *pInfo)
{}void CDialogPrintDlg::OnStartPrint()
{
// TODO: Add your control notification handler code here
CDC dc;
CPrintDialog printDlg(FALSE); if (printDlg.DoModal() == IDCANCEL)// Get printer settings fromuser
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); // Call your "Init printing" funtion
for (UINT page = Info.GetMinPage();
page <= Info.GetMaxPage() && bPrintingOK;
page++)
{
dc.StartPage(); // begin new page
Info.m_nCurPage = page;
OnPrint(&dc, &Info); // Call your "Print page" function
bPrintingOK = (dc.EndPage() > 0); // end page
}
OnEndPrinting(&dc, &Info); // Call your "Clean up" funtion if (bPrintingOK)
dc.EndDoc(); // end a print job
else
dc.AbortDoc(); // abort job. dc.Detach();
}void CDialogPrintDlg::OnPrint(CDC *pDC, CPrintInfo *pInfo)
{
OnPaint();
}