예제 #1
0
void ScheduleViewEx::OnPrintAll()
{
	CPrintDialog dlg(FALSE);
	if (IDOK == dlg.DoModal())
	{
		HDC dc = dlg.GetPrinterDC();
		
		CDC DC;
		DC.Attach(dc);

		DEVMODE *myMode = dlg.GetDevMode();//fills myMode with printer defaults 
		myMode->dmOrientation = DMORIENT_LANDSCAPE;//change default to landscape
		myMode->dmPrintQuality = DMRES_DRAFT;
		myMode->dmColor = DMCOLOR_MONOCHROME;
		DC.ResetDC(myMode);

		DC.m_bPrinting = TRUE;
		OnPrepareDC(&DC);
		DC.StartDoc(_T("myDoc"));
		
		int tmpOffset = m_offset;
		for (int i = 0;
			i< TotalPages();
			i++)
		{
			m_offset = i;
			DC.StartPage();
			OnDraw(&DC);
			DC.EndPage();
		}
		DC.EndDoc();
		m_offset = tmpOffset;
	}
}
예제 #2
0
void CPredView::OnFilePrint()
{
	CDC dc;
	CPrintDialog printDlg(false);
	if(printDlg.DoModal()==IDCANCEL)
		return;
	dc.Attach(printDlg.GetPrinterDC());
	dc.m_bPrinting=true;

	DOCINFO di;
	::ZeroMemory(&di,sizeof(DOCINFO));
	di.cbSize=sizeof(DOCINFO);
	di.lpszDocName="FCC Prediction";
	

	bool bPrintingOK=dc.StartDocA(&di);
	CPrintInfo info;
	info.m_rectDraw.SetRect(0,0,dc.GetDeviceCaps(HORZRES),dc.GetDeviceCaps(VERTRES));
	
	
	//OnPreparePrinting(&info);
	OnBeginPrinting(&dc,&info);
	OnPrint(&dc,&info);
	OnEndPrinting(&dc,&info);
	
	if(bPrintingOK)
		dc.EndDoc();
	else
		dc.AbortDoc();
	dc.Detach();
}
예제 #3
0
파일: kguipc.cpp 프로젝트: CarlHuff/kgui
/* false=error, true=ok */
bool kGUIPrintJobWin::End(void)
{
	if(m_error==true) /* some error occured previously, abort */
        m_pdc.AbortDoc ();
	else
		m_pdc.EndDoc ();
	m_pdc.Detach();
	return(!m_error);
}
예제 #4
0
파일: EdRptDoc.cpp 프로젝트: zphseu/cuiyan
BOOL CEdRptDoc::PrintAuto(CPrintDialog *pPntDlg)
{
	// 严禁在不使用省却打印机情况下不指定打印机
	ASSERT(m_bDefaultPrint || pPntDlg);
	
	// get default print
	CPrintDialog defaultDlg (FALSE, PD_RETURNDC );
	AfxGetApp()->GetPrinterDeviceDefaults( &defaultDlg.m_pd );	

	if (!pPntDlg)
		pPntDlg = &defaultDlg;
	
	HDC hdc = pPntDlg->CreatePrinterDC();
	ASSERT(hdc);
	CDC dc;
	dc.Attach( hdc );
	
    dc.m_bPrinting = TRUE;
	
    CString strTitle = m_szTitle;
	if (strTitle.IsEmpty())
		strTitle.LoadString(AFX_IDS_APP_TITLE);
		
    DOCINFO di;                                 // Initialise print doc details
    memset(&di, 0, sizeof (DOCINFO));
    di.cbSize = sizeof (DOCINFO);
    di.lpszDocName = strTitle;
	
    BOOL bPrintingOK = dc.StartDoc(&di);        // Begin a new print job
	
    CPrintInfo Info;
    Info.m_rectDraw.SetRect(0,0, dc.GetDeviceCaps(HORZRES), dc.GetDeviceCaps(VERTRES));
	
    m_Grid.OnBeginPrinting(&dc, &Info);                // Initialise printing
	m_Grid.SetFocus();
    for (UINT page = Info.GetMinPage(); page <= Info.GetMaxPage() && bPrintingOK; page++)
    {
        dc.StartPage();                         // begin new page
        Info.m_nCurPage = page;
        m_Grid.OnPrint(&dc, &Info);                    // Print page
        bPrintingOK = (dc.EndPage() > 0);       // end page
    }
    m_Grid.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
	
	DeleteDC(hdc);

	return TRUE;
}
예제 #5
0
void CvSqlQueryLowerView::DoFilePrint()
{
	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));
	Info.m_bPreview = TRUE;

	OnBeginPrinting(&dc, &Info);                // Call your "Init printing" funtion
	if (m_nPageWidth > Info.m_rectDraw.Width())
		m_nPageWidth = Info.m_rectDraw.Width();
	if (m_nPageHeight > Info.m_rectDraw.Height())
		m_nPageHeight = Info.m_rectDraw.Height();

	while (bPrintingOK)
	{
		dc.StartPage();                         // begin new page
		PrintPageHeader(&dc, Info.m_nCurPage);  // updates m_nHeaderHeight
		PrintPageFooter(&dc, Info.m_nCurPage);  // updates m_nFooterHeight

		ASSERT (m_nHeaderHeight >= 0);
		ASSERT (m_nFooterHeight >= 0);

		PrintPage(&dc, Info.m_nCurPage);
		Info.m_nCurPage++;
		dc.EndPage();
		bPrintingOK = ((int)Info.m_nCurPage > m_nbPrintPage) ? FALSE: TRUE;
	}

	OnEndPrinting(&dc, &Info);
	dc.EndDoc();
	dc.Detach();
}
예제 #6
0
//*************************************************************************************
void CBCGPKeyMapDlg::PrintKeyMap ()
{
	CWaitCursor WaitCursor;
	
	int nItem = -1;
	int nFlag = (m_KeymapList.GetSelectedCount () > 0)  ?  LVNI_SELECTED : LVNI_ALL;
	
	CPrintDialog dlgPrint (FALSE, PD_ALLPAGES | PD_RETURNDC | PD_NOSELECTION, NULL);
	if (dlgPrint.DoModal() != IDOK)
	{
		return;
	}
	
	// Obtain a handle to the device context.
	HDC hdcPrn = dlgPrint.GetPrinterDC ();
	if (hdcPrn == NULL)
	{
		ASSERT (FALSE);
		return;
	}

	CDC dc;
	dc.Attach (hdcPrn);

	CSize szPage (dc.GetDeviceCaps (HORZRES), dc.GetDeviceCaps (VERTRES));

	dc.StartDoc(_T("BCGKeyMapDlg"));  // begin a new print job
	dc.StartPage ();
	
	int nPage = 1;
	int y = OnPrintHeader (dc, nPage, szPage.cx);

	while ((nItem = m_KeymapList.GetNextItem (nItem, nFlag)) >= 0)
	{
		int nItemHeight = OnPrintItem (dc, nItem, y, szPage.cx, TRUE /* Calc height */);
		if (y + nItemHeight > szPage.cy)
		{
			dc.EndPage();

			dc.StartPage ();
			y = OnPrintHeader (dc, ++nPage, szPage.cx);
		}

		y += OnPrintItem (dc, nItem, y, szPage.cx, FALSE /* Draw */);
	}
	
	dc.EndPage();
	dc.EndDoc();
}
예제 #7
0
void CChartCtrl::Print(const TChartString& strTitle, CPrintDialog* pPrntDialog)
{
	//AFX_MANAGE_STATE(AfxGetStaticModuleState()); 
	
	CDC dc;
    if (pPrntDialog == NULL)
    {
        CPrintDialog printDlg(FALSE);
        if (printDlg.DoModal() != IDOK)         // Get printer settings from user
            return;

		dc.Attach(printDlg.GetPrinterDC());     // attach a printer DC
    }
    else
		dc.Attach(pPrntDialog->GetPrinterDC()); // attach a printer DC
    dc.m_bPrinting = TRUE;
	
    DOCINFO di;                                 // Initialise print doc details
    memset(&di, 0, sizeof (DOCINFO));
    di.cbSize = sizeof (DOCINFO);
	di.lpszDocName = strTitle.c_str();

    BOOL bPrintingOK = dc.StartDoc(&di);        // Begin a new print job

    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
}
예제 #8
0
void CView::OnFilePrint()
{
	// get default print info
	CPrintInfo printInfo;
	ASSERT(printInfo.m_pPD != NULL);    // must be set

	if (LOWORD(GetCurrentMessage()->wParam) == ID_FILE_PRINT_DIRECT)
	{
		CCommandLineInfo* pCmdInfo = AfxGetApp()->m_pCmdInfo;

		if (pCmdInfo != NULL)
		{
			if (pCmdInfo->m_nShellCommand == CCommandLineInfo::FilePrintTo)
			{
				printInfo.m_pPD->m_pd.hDC = ::CreateDC(pCmdInfo->m_strDriverName,
					pCmdInfo->m_strPrinterName, pCmdInfo->m_strPortName, NULL);
				if (printInfo.m_pPD->m_pd.hDC == NULL)
				{
					AfxMessageBox(AFX_IDP_FAILED_TO_START_PRINT);
					return;
				}
			}
		}

		printInfo.m_bDirect = TRUE;
	}

	if (OnPreparePrinting(&printInfo))
	{
		// hDC must be set (did you remember to call DoPreparePrinting?)
		ASSERT(printInfo.m_pPD->m_pd.hDC != NULL);

		// gather file to print to if print-to-file selected
		CString strOutput;
		if (printInfo.m_pPD->m_pd.Flags & PD_PRINTTOFILE && !printInfo.m_bDocObject)
		{
			// construct CFileDialog for browsing
			CString strDef(MAKEINTRESOURCE(AFX_IDS_PRINTDEFAULTEXT));
			CString strPrintDef(MAKEINTRESOURCE(AFX_IDS_PRINTDEFAULT));
			CString strFilter(MAKEINTRESOURCE(AFX_IDS_PRINTFILTER));
			CString strCaption(MAKEINTRESOURCE(AFX_IDS_PRINTCAPTION));
			CFileDialog dlg(FALSE, strDef, strPrintDef,
				OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT, strFilter, NULL, 0);
			dlg.m_ofn.lpstrTitle = strCaption;

			if (dlg.DoModal() != IDOK)
				return;

			// set output device to resulting path name
			strOutput = dlg.GetPathName();
		}

		// set up document info and start the document printing process
		CString strTitle;
		CDocument* pDoc = GetDocument();
		if (pDoc != NULL)
			strTitle = pDoc->GetTitle();
		else
			EnsureParentFrame()->GetWindowText(strTitle);
		DOCINFO docInfo;
		memset(&docInfo, 0, sizeof(DOCINFO));
		docInfo.cbSize = sizeof(DOCINFO);
		docInfo.lpszDocName = strTitle;
		CString strPortName;
		if (strOutput.IsEmpty())
		{
			docInfo.lpszOutput = NULL;
			strPortName = printInfo.m_pPD->GetPortName();
		}
		else
		{
			docInfo.lpszOutput = strOutput;
			AfxGetFileTitle(strOutput,
				strPortName.GetBuffer(_MAX_PATH), _MAX_PATH);
		}

		// setup the printing DC
		CDC dcPrint;
		if (!printInfo.m_bDocObject)
		{
			dcPrint.Attach(printInfo.m_pPD->m_pd.hDC);  // attach printer dc
			dcPrint.m_bPrinting = TRUE;
		}
		OnBeginPrinting(&dcPrint, &printInfo);

		if (!printInfo.m_bDocObject)
			dcPrint.SetAbortProc(_AfxAbortProc);

		// disable main window while printing & init printing status dialog
		// Store the Handle of the Window in a temp so that it can be enabled 
		// once the printing is finished
		CWnd * hwndTemp = AfxGetMainWnd();
		hwndTemp->EnableWindow(FALSE);
		CPrintingDialog dlgPrintStatus(this);

		CString strTemp;
		dlgPrintStatus.SetDlgItemText(AFX_IDC_PRINT_DOCNAME, strTitle);
		dlgPrintStatus.SetDlgItemText(AFX_IDC_PRINT_PRINTERNAME,
			printInfo.m_pPD->GetDeviceName());
		dlgPrintStatus.SetDlgItemText(AFX_IDC_PRINT_PORTNAME, strPortName);
		dlgPrintStatus.ShowWindow(SW_SHOW);
		dlgPrintStatus.UpdateWindow();

		// start document printing process
		if (!printInfo.m_bDocObject)
		{
			printInfo.m_nJobNumber = dcPrint.StartDoc(&docInfo);
			if (printInfo.m_nJobNumber == SP_ERROR)
			{
				// enable main window before proceeding
				hwndTemp->EnableWindow(TRUE);

				// cleanup and show error message
				OnEndPrinting(&dcPrint, &printInfo);
				dlgPrintStatus.DestroyWindow();
				dcPrint.Detach();   // will be cleaned up by CPrintInfo destructor
				AfxMessageBox(AFX_IDP_FAILED_TO_START_PRINT);
				return;
			}
		}

		// Guarantee values are in the valid range
		UINT nEndPage = printInfo.GetToPage();
		UINT nStartPage = printInfo.GetFromPage();

		if (nEndPage < printInfo.GetMinPage())
			nEndPage = printInfo.GetMinPage();
		if (nEndPage > printInfo.GetMaxPage())
			nEndPage = printInfo.GetMaxPage();

		if (nStartPage < printInfo.GetMinPage())
			nStartPage = printInfo.GetMinPage();
		if (nStartPage > printInfo.GetMaxPage())
			nStartPage = printInfo.GetMaxPage();

		int nStep = (nEndPage >= nStartPage) ? 1 : -1;
		nEndPage = (nEndPage == 0xffff) ? 0xffff : nEndPage + nStep;

		VERIFY(strTemp.LoadString(AFX_IDS_PRINTPAGENUM));

		// If it's a doc object, we don't loop page-by-page
		// because doc objects don't support that kind of levity.

		BOOL bError = FALSE;
		if (printInfo.m_bDocObject)
		{
			OnPrepareDC(&dcPrint, &printInfo);
			OnPrint(&dcPrint, &printInfo);
		}
		else
		{
			// begin page printing loop
			for (printInfo.m_nCurPage = nStartPage;
				printInfo.m_nCurPage != nEndPage; printInfo.m_nCurPage += nStep)
			{
				OnPrepareDC(&dcPrint, &printInfo);

				// check for end of print
				if (!printInfo.m_bContinuePrinting)
					break;

				// write current page
				TCHAR szBuf[80];
				ATL_CRT_ERRORCHECK_SPRINTF(_sntprintf_s(szBuf, _countof(szBuf), _countof(szBuf) - 1, strTemp, printInfo.m_nCurPage));
				
				dlgPrintStatus.SetDlgItemText(AFX_IDC_PRINT_PAGENUM, szBuf);

				// set up drawing rect to entire page (in logical coordinates)
				printInfo.m_rectDraw.SetRect(0, 0,
					dcPrint.GetDeviceCaps(HORZRES),
					dcPrint.GetDeviceCaps(VERTRES));
				dcPrint.DPtoLP(&printInfo.m_rectDraw);

				// attempt to start the current page
				if (dcPrint.StartPage() < 0)
				{
					bError = TRUE;
					break;
				}

				// must call OnPrepareDC on newer versions of Windows because
				// StartPage now resets the device attributes.
				OnPrepareDC(&dcPrint, &printInfo);

				ASSERT(printInfo.m_bContinuePrinting);

				// page successfully started, so now render the page
				OnPrint(&dcPrint, &printInfo);

				// If the user restarts the job when it's spooling, all 
				// subsequent calls to EndPage returns < 0. The first time
				// GetLastError returns ERROR_PRINT_CANCELLED
				if (dcPrint.EndPage() < 0 && (GetLastError()!= ERROR_SUCCESS))
				{
					HANDLE hPrinter;
					if (!OpenPrinter(LPTSTR(printInfo.m_pPD->GetDeviceName().GetBuffer()), &hPrinter, NULL))
					{
						bError = TRUE;
						break;
					}

					DWORD cBytesNeeded;
					if(!GetJob(hPrinter,printInfo.m_nJobNumber,1,NULL,0,&cBytesNeeded))
					{
						if (GetLastError() != ERROR_INSUFFICIENT_BUFFER)
						{
						   bError = TRUE;
						   break;
						}
					}

					JOB_INFO_1 *pJobInfo; 					
					if((pJobInfo = (JOB_INFO_1 *)malloc(cBytesNeeded))== NULL)
					{
						bError = TRUE;
						break;
					}

					DWORD cBytesUsed;

					BOOL bRet = GetJob(hPrinter,printInfo.m_nJobNumber,1,LPBYTE(pJobInfo),cBytesNeeded,&cBytesUsed);

					DWORD dwJobStatus = pJobInfo->Status;

					free(pJobInfo);
					pJobInfo = NULL;

					// if job status is restart, just continue
					if(!bRet || !(dwJobStatus & JOB_STATUS_RESTART) )
					{
						bError = TRUE;
						break;
					}
				}

				if(!_AfxAbortProc(dcPrint.m_hDC, 0))
				{		
					bError = TRUE;
					break;
				}
			}
		}

		// cleanup document printing process
		if (!printInfo.m_bDocObject)
		{
			if (!bError)
				dcPrint.EndDoc();
			else
				dcPrint.AbortDoc();
		}

		hwndTemp->EnableWindow();    // enable main window

		OnEndPrinting(&dcPrint, &printInfo);    // clean up after printing
		dlgPrintStatus.DestroyWindow();

		dcPrint.Detach();   // will be cleaned up by CPrintInfo destructor
	}
}
예제 #9
0
void Dg_FactorsHands::OnPrintPrintwindow()
{
		// TODO: Add your command handler code here
	 CRect m_rect;
 GetClientRect(&m_rect);
 CDC* pImageDC=GetDC();
 int formx,formy;
 formx=pImageDC->GetDeviceCaps(LOGPIXELSX);
 formy=pImageDC->GetDeviceCaps(LOGPIXELSY);
 ReleaseDC(pImageDC);
 DWORD dwflags=PD_PAGENUMS|PD_HIDEPRINTTOFILE|PD_SELECTION;  
 CPrintDialog m_printdlg(FALSE,dwflags,NULL);     
 if(m_printdlg.DoModal()==IDOK)
 {
  CDC pdc;
  pdc.Attach(m_printdlg.GetPrinterDC());
  int printerx,printery;
  printerx=pdc.GetDeviceCaps(LOGPIXELSX);
  printery=pdc.GetDeviceCaps(LOGPIXELSY);
  double ratex,ratey;
  ratex=(double)printerx/formx;
  ratey=(double)printery/formy;
  CClientDC dc(this);
  CBitmap bmp;
  int w=m_rect.Width();
  int h =m_rect.Height();
  bmp.CreateCompatibleBitmap(&dc,m_rect.Width(),m_rect.Height());
  CDC imagedc;
  imagedc.CreateCompatibleDC(&dc);
  imagedc.SelectObject(&bmp);
  imagedc.BitBlt(0,0,m_rect.Width(),m_rect.Height(),&dc,0,0,SRCCOPY);
  BITMAP bmap;
  bmp.GetBitmap(&bmap);
  int panelsize=0;
  if(bmap.bmBitsPixel<16)
  {
   panelsize=pow(2,bmap.bmBitsPixel*sizeof(RGBQUAD));
  }
  BITMAPINFO* bInfo=(BITMAPINFO*)LocalAlloc(LPTR,sizeof(BITMAPINFO)+panelsize);
  bInfo->bmiHeader.biClrImportant=0;
  bInfo->bmiHeader.biBitCount=bmap.bmBitsPixel;
  bInfo->bmiHeader.biCompression=0;
  bInfo->bmiHeader.biHeight=bmap.bmHeight;
  bInfo->bmiHeader.biPlanes=bmap.bmPlanes;
  bInfo->bmiHeader.biSize=sizeof(BITMAPINFO);
  bInfo->bmiHeader.biSizeImage=bmap.bmWidthBytes*bmap.bmHeight;
  bInfo->bmiHeader.biWidth=bmap.bmWidth;
  bInfo->bmiHeader.biXPelsPerMeter=0;
  bInfo->bmiHeader.biYPelsPerMeter=0;
  char *pData=new char[bmap.bmWidthBytes*bmap.bmHeight];
  ::GetDIBits(imagedc.m_hDC,bmp,0,bmap.bmHeight,pData,bInfo,DIB_RGB_COLORS);
  pdc.StartDoc("print");
  ::StretchDIBits(pdc.m_hDC,0,0,(int)((m_rect.Width()*ratex)),
   (int)((m_rect.Height())*ratey),0,0,m_rect.Width(),
   m_rect.Height(),pData,bInfo,DIB_RGB_COLORS,SRCCOPY);
  pdc.EndDoc();
  LocalFree(bInfo);
  delete[] pData;
  pData = NULL;
  bmp.DeleteObject();
 }
}
예제 #10
0
파일: Print.cpp 프로젝트: hozgur/Colorway
void CPrint::OnPrint()
{
	if (ParentWnd == NULL) return;
	// get default print info
	CPrintInfo printInfo;
	ASSERT(printInfo.m_pPD != NULL);    // must be set
/*
	if (LOWORD(GetCurrentMessage()->wParam) == ID_FILE_PRINT_DIRECT)
	{
		CCommandLineInfo* pCmdInfo = AfxGetApp()->m_pCmdInfo;

		if (pCmdInfo != NULL)
		{
			if (pCmdInfo->m_nShellCommand == CCommandLineInfo::FilePrintTo)
			{
				printInfo.m_pPD->m_pd.hDC = ::CreateDC(pCmdInfo->m_strDriverName,
					pCmdInfo->m_strPrinterName, pCmdInfo->m_strPortName, NULL);
				if (printInfo.m_pPD->m_pd.hDC == NULL)
				{
					AfxMessageBox(AFX_IDP_FAILED_TO_START_PRINT);
					return;
				}
			}
		}

		printInfo.m_bDirect = TRUE;
	}
*/
	if (OnPreparePrinting(&printInfo))
	{
		// hDC must be set (did you remember to call DoPreparePrinting?)
		ASSERT(printInfo.m_pPD->m_pd.hDC != NULL);

		// gather file to print to if print-to-file selected
		CString strOutput;
		if (printInfo.m_pPD->m_pd.Flags & PD_PRINTTOFILE && !printInfo.m_bDocObject)
		{
			// construct CFileDialog for browsing
			CString strDef(MAKEINTRESOURCE(AFX_IDS_PRINTDEFAULTEXT));
			CString strPrintDef(MAKEINTRESOURCE(AFX_IDS_PRINTDEFAULT));
			CString strFilter(MAKEINTRESOURCE(AFX_IDS_PRINTFILTER));
			CString strCaption(MAKEINTRESOURCE(AFX_IDS_PRINTCAPTION));
			CFileDialog dlg(FALSE, strDef, strPrintDef,
				OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT, strFilter);
			dlg.m_ofn.lpstrTitle = strCaption;

			if (dlg.DoModal() != IDOK)
				return;

			// set output device to resulting path name
			strOutput = dlg.GetPathName();
		}

		// set up document info and start the document printing process
		DOCINFO docInfo;
		memset(&docInfo, 0, sizeof(DOCINFO));
		docInfo.cbSize = sizeof(DOCINFO);
		docInfo.lpszDocName = PrintTitle;
		CString strPortName;
		int nFormatID;
		if (strOutput.IsEmpty())
		{
			docInfo.lpszOutput = NULL;
			strPortName = printInfo.m_pPD->GetPortName();
			nFormatID = AFX_IDS_PRINTONPORT;
		}
		else
		{
			docInfo.lpszOutput = strOutput;

			strPortName = "Miracle";
			/*AfxGetFileTitle(strOutput,
				strPortName.GetBuffer(_MAX_PATH), _MAX_PATH);*/
			nFormatID = AFX_IDS_PRINTTOFILE;
		}
		
		// setup the printing DC
		CDC dcPrint;
		if (!printInfo.m_bDocObject)
		{
			dcPrint.Attach(printInfo.m_pPD->m_pd.hDC);  // attach printer dc
			dcPrint.m_bPrinting = TRUE;
		}
		OnBeginPrinting(&dcPrint, &printInfo);

		if (!printInfo.m_bDocObject)
			dcPrint.SetAbortProc(AbortProc);

		// disable main window while printing & init printing status dialog
		AfxGetMainWnd()->EnableWindow(FALSE);
		CPrintingDialog dlgPrintStatus(ParentWnd);
		ghwndAbort = dlgPrintStatus.m_hWnd;
		CString strTemp;
		dlgPrintStatus.SetDlgItemText(AFX_IDC_PRINT_DOCNAME, PrintTitle);
		dlgPrintStatus.SetDlgItemText(AFX_IDC_PRINT_PRINTERNAME,
			printInfo.m_pPD->GetDeviceName());
		AfxFormatString1(strTemp, nFormatID, strPortName);
		dlgPrintStatus.SetDlgItemText(AFX_IDC_PRINT_PORTNAME, strTemp);
		dlgPrintStatus.ShowWindow(SW_SHOW);
		dlgPrintStatus.UpdateWindow();

		// start document printing process
		if (!printInfo.m_bDocObject && dcPrint.StartDoc(&docInfo) == SP_ERROR)
		{
			// enable main window before proceeding
			AfxGetMainWnd()->EnableWindow(TRUE);

			// cleanup and show error message
			OnEndPrinting(&dcPrint, &printInfo);
			dlgPrintStatus.DestroyWindow();
			dcPrint.Detach();   // will be cleaned up by CPrintInfo destructor
			AfxMessageBox(AFX_IDP_FAILED_TO_START_PRINT);
			return;
		}

		// Guarantee values are in the valid range
		UINT nEndPage = printInfo.GetToPage();
		UINT nStartPage = printInfo.GetFromPage();

		if (nEndPage < printInfo.GetMinPage())
			nEndPage = printInfo.GetMinPage();
		if (nEndPage > printInfo.GetMaxPage())
			nEndPage = printInfo.GetMaxPage();

		if (nStartPage < printInfo.GetMinPage())
			nStartPage = printInfo.GetMinPage();
		if (nStartPage > printInfo.GetMaxPage())
			nStartPage = printInfo.GetMaxPage();

		int nStep = (nEndPage >= nStartPage) ? 1 : -1;
		nEndPage = (nEndPage == 0xffff) ? 0xffff : nEndPage + nStep;

		VERIFY(strTemp.LoadString(AFX_IDS_PRINTPAGENUM));

		// If it's a doc object, we don't loop page-by-page
		// because doc objects don't support that kind of levity.

		BOOL bError = FALSE;
		
		// Print Loop // Burada DocObject kýsmý silindi
		{
			// begin page printing loop
			for (printInfo.m_nCurPage = nStartPage;
				printInfo.m_nCurPage != nEndPage; printInfo.m_nCurPage += nStep)
			{
				OnPrepareDC(&dcPrint, &printInfo);

				// check for end of print
				if (!printInfo.m_bContinuePrinting)
					break;

				// write current page
				TCHAR szBuf[80];
				wsprintf(szBuf, strTemp, printInfo.m_nCurPage);
				dlgPrintStatus.SetDlgItemText(AFX_IDC_PRINT_PAGENUM, szBuf);

				// set up drawing rect to entire page (in logical coordinates)
				printInfo.m_rectDraw.SetRect(0, 0,
					dcPrint.GetDeviceCaps(HORZRES),
					dcPrint.GetDeviceCaps(VERTRES));
				dcPrint.DPtoLP(&printInfo.m_rectDraw);

				// attempt to start the current page
				if (dcPrint.StartPage() < 0)
				{
					DebugMessage("Error on print 2");
					bError = TRUE;
					break;
				}

				// must call OnPrepareDC on newer versions of Windows because
				// StartPage now resets the device attributes.
				//if (afxData.bMarked4)
					OnPrepareDC(&dcPrint, &printInfo);

				ASSERT(printInfo.m_bContinuePrinting);

				// page successfully started, so now render the page
				OnPrint(&dcPrint, &printInfo);
				TRACE("on print\n");
				int stat = dcPrint.EndPage();
				if (stat < 0 || !AbortProc(dcPrint.m_hDC, 0))
				{
					bError = TRUE;
					CString str;
					str.Format("End Page = %ld,Abort = %ld",stat,gbAbort);
					DebugMessage(str);
					DebugMessage("Error on print");
					break;
				}
			}
		}

		// cleanup document printing process
		if (!printInfo.m_bDocObject)
		{
			if (!bError)
				dcPrint.EndDoc();
			else
				dcPrint.AbortDoc();
		}

		AfxGetMainWnd()->EnableWindow();    // enable main window

		OnEndPrinting(&dcPrint, &printInfo);    // clean up after printing
		dlgPrintStatus.DestroyWindow();

		dcPrint.Detach();   // will be cleaned up by CPrintInfo destructor
	}
}
void CELibrarianApp::OnPrintLibrary() 
{
	CString pszLibraryName, pszHeaderName;
	CPrintInfo printInfo;
    CELibrarianApp * pApp = this;

	//
	// get document
	//
	CELibrarianDoc* pDoc = (CELibrarianDoc*) GetDocument();
	pszLibraryName = pDoc->GetTitle();


	// 
	// print dialog
    // Page selection disabled
	//
    printInfo.m_pPD->m_pd.Flags |= PD_NOPAGENUMS;

	if (IDOK != pApp->DoPrintDialog(printInfo.m_pPD))
    {
		return;       // do not print
    }

    // print all pages
    printInfo.m_pPD->m_pd.nToPage = 0xffff;

	if (NULL == printInfo.m_pPD->m_pd.hDC)
    {
		return;
    }

	// gather file to print to if print-to-file selected
	CString strOutput;
	if (printInfo.m_pPD->m_pd.Flags & PD_PRINTTOFILE)
	{
		// construct CFileDialog for browsing
		CString strDef(MAKEINTRESOURCE(AFX_IDS_PRINTDEFAULTEXT));
		CString strPrintDef(MAKEINTRESOURCE(AFX_IDS_PRINTDEFAULT));
		CString strFilter(MAKEINTRESOURCE(AFX_IDS_PRINTFILTER));
		CString strCaption(MAKEINTRESOURCE(AFX_IDS_PRINTCAPTION));
		CFileDialog dlg(FALSE, strDef, strPrintDef,
			OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT, strFilter);
		dlg.m_ofn.lpstrTitle = strCaption;

		if (IDOK != dlg.DoModal())
        {
			return;
        }

		// set output device to resulting path name
		strOutput = dlg.GetPathName();
	}

	//
	// set up document info and start the document printing process
	//
	DOCINFO docInfo;
	memset(&docInfo, 0, sizeof(DOCINFO));
	docInfo.cbSize = sizeof(DOCINFO);
	docInfo.lpszDocName = pszLibraryName;
	CString strPortName;
	int nFormatID;
	if (strOutput.IsEmpty())
	{
		docInfo.lpszOutput = NULL;
		strPortName = printInfo.m_pPD->GetPortName();
		nFormatID = AFX_IDS_PRINTONPORT;
	}
	else
	{
		docInfo.lpszOutput = strOutput;
		nFormatID = AFX_IDS_PRINTTOFILE;
	}
	
	//
	// setup the printing DC
	//
	CDC dcPrint;
	dcPrint.Attach(printInfo.m_pPD->m_pd.hDC);  // attach printer dc
	dcPrint.m_bPrinting = TRUE;


	//
	// setup status dialog
	//
	dcPrint.SetAbortProc(PrjPrintAbortProc);

	// disable main window while printing & init printing status dialog
	AfxGetMainWnd()->EnableWindow(FALSE);
	CPrjPrintDialog dlgPrintStatus(m_pMainWnd);

	CString strTemp;

    dlgPrintStatus.SetDlgItemText(AFX_IDC_PRINT_DOCNAME, pszLibraryName);
	dlgPrintStatus.SetDlgItemText(AFX_IDC_PRINT_PRINTERNAME,
		printInfo.m_pPD->GetDeviceName());
	AfxFormatString1(strTemp, nFormatID, strPortName);
	dlgPrintStatus.SetDlgItemText(AFX_IDC_PRINT_PORTNAME, strTemp);

    dlgPrintStatus.ShowWindow(SW_SHOW);
    dlgPrintStatus.UpdateWindow();

	//
	// start printing
	//
	if (dcPrint.StartDoc(&docInfo) == SP_ERROR)
	{
		// enable main window before proceeding
		AfxGetMainWnd()->EnableWindow(TRUE);

		// cleanup and show error message
    	dlgPrintStatus.DestroyWindow();
		dcPrint.Detach();   // will be cleaned up by CPrintInfo destructor
		AfxMessageBox(AFX_IDP_FAILED_TO_START_PRINT);
		return;
	}


    BOOL bError = FALSE;
    CPrintUserData UserData;
    CString strBuffer;
 
    printInfo.m_lpUserData = (LPVOID)&UserData;
    UserData.SetLibraryName(pszLibraryName);

	//
    // print list of POU's
	//
  	//bError = PrintPOUList(&dcPrint, & printInfo);
	bError = FALSE;

	//
	// print all headers pf POU's
	//
	/*CELibrary* pCeLibrary = pDoc->GetCELibrary();
	int nn = pCeLibrary->GetPOUCount();
	CString pouName;
	for ( int ii=0 ; ii<nn && !bError; ii++)
	{	
		pouName = pCeLibrary->GetPOUName(ii);
		if (pouName != ".")
		{	
			UserData.SetHeaderName(pouName);
			bError = PrintPOUHeader( pouName, &dcPrint, &printInfo, &dlgPrintStatus);
		}
	}*/

	if (!bError)
		dcPrint.EndDoc();
	else
		dcPrint.AbortDoc();

	AfxGetMainWnd()->EnableWindow();    // enable main window
	dlgPrintStatus.DestroyWindow();
	dcPrint.Detach();   // will be cleaned up by CPrintInfo destructor
    return;
	
}
예제 #12
0
void CMainFrame::OnOptPrint()
{
	CPrintDialog dlg(FALSE);
	if (IDOK!=dlg.DoModal())
	{
		return;
	}

	HDC hdcPrinter = dlg.GetPrinterDC();
	if (hdcPrinter == NULL){
		MessageBox("无法找到打印机",NULL,MB_OK|MB_ICONSTOP);
	}else{
		CDC dcPrinter;
		dcPrinter.Attach(hdcPrinter);

		// call StartDoc() to begin printing
		DOCINFO docinfo;
		memset(&docinfo, 0, sizeof(docinfo));
		docinfo.cbSize = sizeof(docinfo);
		docinfo.lpszDocName = "事件记录报表";

		// if it fails, complain and exit gracefully
		if (dcPrinter.StartDoc(&docinfo) < 0){
			MessageBox("无法初始化打印机",NULL,MB_OK|MB_ICONSTOP);
		}else{
			dcPrinter.SetMapMode(MM_TWIPS);
			CFont *pOldFont;
			CFont fnt;
			if(fnt.CreatePointFont(70,"宋体",&dcPrinter)){
				pOldFont=(CFont*)dcPrinter.SelectObject(&fnt);                  
			}else{
				pOldFont=(CFont*)dcPrinter.SelectStockObject(DEVICE_DEFAULT_FONT);
			}
			CPoint pt(dcPrinter.GetDeviceCaps(HORZRES),dcPrinter.GetDeviceCaps(VERTRES));
			dcPrinter.DPtoLP (&pt);
			pt.y=-pt.y;
			CSize sz=dcPrinter.GetTextExtent("序号   ");
			CSize sz1=dcPrinter.GetTextExtent("报警时间                          ");
			CSize sz2=dcPrinter.GetTextExtent("变量名                            ");
			CSize sz3=dcPrinter.GetTextExtent("变量描述                                     ");
			CSize sz4=dcPrinter.GetTextExtent("报警时测量值  ");
			CSize sz5=dcPrinter.GetTextExtent("单位   ");
			CSize sz6=dcPrinter.GetTextExtent("报警类型   ");
			CSize sz7=dcPrinter.GetTextExtent("状态   ");
			int lineHeight=sz.cy*1.5;
			int lineCount=(pt.y-sz.cy*10)/lineHeight;
			if(lineCount<0) return;
			long id=0;
			CString str;
			int i,iPage=0;
			int cLeftGap=800;
			while(evtsList[id].valid){
				// start a page
				if (dcPrinter.StartPage() < 0){
					MessageBox("无法初始化页",NULL,MB_OK|MB_ICONSTOP);
					dcPrinter.AbortDoc();
				}else{
					// actually do some printing
					//print title
					iPage++;
					str.Format("事件记录报表 第%2d页",iPage);
					dcPrinter.TextOut(cLeftGap,-lineHeight*3,str);
					//str.Format("序号  事件");
					str.Format("序号");
					dcPrinter.TextOut(cLeftGap,-lineHeight*5,str);
					str.Format("报警时间");
					dcPrinter.TextOut(cLeftGap+sz.cx,-lineHeight*5,str);
					str.Format("变量名");
					dcPrinter.TextOut(cLeftGap+sz.cx+sz1.cx,-lineHeight*5,str);
					str.Format("变量描述");
					dcPrinter.TextOut(cLeftGap+sz.cx+sz1.cx+sz2.cx,-lineHeight*5,str);
					str.Format("报警时测量值");
					dcPrinter.TextOut(cLeftGap+sz.cx+sz1.cx+sz2.cx+sz3.cx,-lineHeight*5,str);
					str.Format("单位");
					dcPrinter.TextOut(cLeftGap+sz.cx+sz1.cx+sz2.cx+sz3.cx+sz4.cx,-lineHeight*5,str);
					str.Format("报警类型");
					dcPrinter.TextOut(cLeftGap+sz.cx+sz1.cx+sz2.cx+sz3.cx+sz4.cx+sz5.cx,-lineHeight*5,str);
					str.Format("状态");
					dcPrinter.TextOut(cLeftGap+sz.cx+sz1.cx+sz2.cx+sz3.cx+sz4.cx+sz5.cx+sz6.cx,-lineHeight*5,str);
					for(i=0;i<lineCount;i++){
						if(evtsList[id].valid){
							CArgs args;
							parse_arg_ey(evtsList[id].data, &args, ";");
							str.Format("%3d",id);
							dcPrinter.TextOut(cLeftGap,-lineHeight*(6+i),str);
							str.Format("%s",args.argv[0]);
							dcPrinter.TextOut(cLeftGap+sz.cx,-lineHeight*(6+i),str);
							str.Format("%s",args.argv[2]);
							dcPrinter.TextOut(cLeftGap+sz.cx+sz1.cx,-lineHeight*(6+i),str);
							str.Format("%s",args.argv[1]);
							dcPrinter.TextOut(cLeftGap+sz.cx+sz1.cx+sz2.cx,-lineHeight*(6+i),str);
							str.Format("%s",args.argv[6]);
							dcPrinter.TextOut(cLeftGap+sz.cx+sz1.cx+sz2.cx+sz3.cx,-lineHeight*(6+i),str);
							str.Format("%s",args.argv[7]);
							dcPrinter.TextOut(cLeftGap+sz.cx+sz1.cx+sz2.cx+sz3.cx+sz4.cx,-lineHeight*(6+i),str);
							str.Format("%s",args.argv[4]);
							dcPrinter.TextOut(cLeftGap+sz.cx+sz1.cx+sz2.cx+sz3.cx+sz4.cx+sz5.cx,-lineHeight*(6+i),str);
							str.Format("%s",args.argv[5]);
							dcPrinter.TextOut(cLeftGap+sz.cx+sz1.cx+sz2.cx+sz3.cx+sz4.cx+sz5.cx+sz6.cx,-lineHeight*(6+i),str);
							id++;
						}else{
							break;
						}
					}
				}
				dcPrinter.EndPage();
			}
			dcPrinter.SelectObject(pOldFont);
			dcPrinter.EndDoc();
		}
	}
}
예제 #13
0
//***********************************************************************************************************
BOOL CBCGPBaseVisualCtrl::DoPrint(CDC* pDCIn, CPrintInfo* pInfo)
{
	CObject* pBaseVisual = GetVisualBaseObject();
	if (pBaseVisual == NULL)
	{
		return FALSE;
	}

	CBCGPBaseVisualObject* pVisualObject = DYNAMIC_DOWNCAST(CBCGPBaseVisualObject, pBaseVisual);
	CBCGPVisualContainer* pVisualContainer = DYNAMIC_DOWNCAST(CBCGPVisualContainer, pBaseVisual);

	if (pVisualObject == NULL && pVisualContainer == NULL)
	{
		return FALSE;
	}

	CBCGPGraphicsManager* pGM = GetGraphicsManager();
	if (pGM == NULL)
	{
		return FALSE;
	}

	ASSERT_VALID(pGM);

	CDC* pDC = pDCIn;
	CPrintDialog* pPrintDlg = NULL;

	if (pDC == NULL)
	{
		pPrintDlg = new CPrintDialog(FALSE);
		
		if (pPrintDlg->DoModal() == IDCANCEL)
		{
			delete pPrintDlg;
			return FALSE;
		}

		pDC = CDC::FromHandle(pPrintDlg->GetPrinterDC());
		pDC->m_bPrinting = TRUE;
		
		CString strTitle;
		strTitle.LoadString(AFX_IDS_APP_TITLE);
		
		DOCINFO di;
		ZeroMemory(&di, sizeof (DOCINFO));
		di.cbSize = sizeof (DOCINFO);
		di.lpszDocName = strTitle;
		
		if (!pDC->StartDoc(&di))
		{	
			pDC->AbortDoc();
			delete pPrintDlg;
			return FALSE;
		}

		pInfo = new CPrintInfo();
		pInfo->m_rectDraw.SetRect(0,0, pDC->GetDeviceCaps(HORZRES), pDC->GetDeviceCaps(VERTRES));
	}

	CSize size(pInfo->m_rectDraw.Size());
	CBCGPRect rect(CBCGPPoint(), size);
	CBCGPRect rectControl(pVisualObject != NULL ? pVisualObject->GetRect() : pVisualContainer->GetRect());

	CBCGPSize sizeScaleRatio((double)size.cx / rectControl.Width(), (double)size.cy / rectControl.Height());

	double dAspect = min(sizeScaleRatio.cx, sizeScaleRatio.cy);
	sizeScaleRatio.cx = sizeScaleRatio.cy = dAspect;

	size.cx = bcg_clamp((int)(rectControl.Width() * dAspect), 0, size.cx);
	size.cy = bcg_clamp((int)(rectControl.Height() * dAspect), 0, size.cy);
	
	rect.SetSize(size);

	CDC	dcPrint;
	CBitmap	bmpPrint;
	CBitmap* pBmpPrintOld = NULL;
	CDC* pDCOut = NULL;

	CBrush brWhite(RGB(255, 255, 255));

	if (DYNAMIC_DOWNCAST(CBCGPGraphicsManagerGDI, pGM) != NULL)
	{
		dcPrint.CreateCompatibleDC(NULL);
		bmpPrint.Attach(CBCGPDrawManager::CreateBitmap_32(size, NULL));
		
		pBmpPrintOld = dcPrint.SelectObject (&bmpPrint);
		ASSERT(pBmpPrintOld != NULL);

		pDCOut = &dcPrint;
	}
	else
	{
		pGM->SetPrintInfo(pInfo);
		pDCOut = pDC;
	}

	pDCOut->FillRect((CRect)rect, &brWhite);
	pGM->BindDC(pDCOut);

	if (pGM->IsBindDCFailed())
	{
		pDCOut->FillRect((CRect)rect, &brWhite);
		pDCOut->TextOut(0, 0, _T("Out of memory"));
	}
	else
	{
		pGM->BeginDraw();

		CBCGPSize sizeScaleRatioOld;
		
		if (pVisualObject != NULL)
		{
			sizeScaleRatioOld = pVisualObject->GetScaleRatio();
			pVisualObject->SetScaleRatio(sizeScaleRatio);
			pVisualObject->SetRect(rect);
		}
		else
		{
			sizeScaleRatioOld = pVisualContainer->GetScaleRatio();
			pVisualContainer->SetScaleRatio(sizeScaleRatio);
			pVisualContainer->SetRect(rect);
		}

		pGM->Clear();

		if (pVisualObject != NULL)
		{
			pVisualObject->OnDraw (pGM, rect);
		}
		else
		{
			pVisualContainer->OnDraw (pGM, rect);
		}

		pGM->EndDraw();

		pGM->BindDC(NULL);

		if (pVisualObject != NULL)
		{
			pVisualObject->SetScaleRatio(sizeScaleRatioOld);
		}
		else
		{
			pVisualContainer->SetScaleRatio(sizeScaleRatioOld);
		}

		if (dcPrint.GetSafeHdc() != NULL)
		{
			CBCGPDrawManager::FillAlpha (rect, (HBITMAP)bmpPrint.GetSafeHandle (), 255);
		}
	}

	if (pVisualObject != NULL)
	{
		pVisualObject->SetRect(rectControl);
		pVisualObject->SetDirty ();
	}
	else
	{
		pVisualContainer->SetRect(rectControl);
		pVisualContainer->SetDirty ();
	}

	if (dcPrint.GetSafeHdc() != NULL)
	{
		BITMAP bmp = {0};
		bmpPrint.GetBitmap (&bmp);

		CRect rectOut(pInfo->m_rectDraw.TopLeft (), CSize(bmp.bmWidth, bmp.bmHeight));

		int mode = pDC->SetStretchBltMode(HALFTONE);

		pDC->BitBlt (rectOut.left, rectOut.top, rectOut.Width(), rectOut.Height(), &dcPrint, 0, 0, SRCCOPY);
		pDC->SetStretchBltMode(mode);

		dcPrint.SelectObject(pBmpPrintOld);
	}
	else
	{
		pGM->SetPrintInfo(NULL);
	}

	if (pPrintDlg != NULL)
	{
		pDC->EndDoc();
		delete pPrintDlg;
		delete pInfo;
	}

	return TRUE;
}
예제 #14
0
BOOL CMlsPrint::Print(CMlsPrintInfo* pInfo, CWnd* pParent)
{
	BOOL fSuccess = FALSE;
	
	ASSERT(pInfo != NULL);
	
	m_pInfo = pInfo;
	m_pParent = pParent;
	
	if (OnPreparePrinting())
	{
		fSuccess = TRUE;
		
		ASSERT(m_pInfo->m_pPD->m_pd.hDC != NULL);

		CDC dcPrint;
		dcPrint.Attach(m_pInfo->m_pPD->m_pd.hDC);
		dcPrint.m_bPrinting = TRUE;
		m_pDC = &dcPrint;

		OnBeginPrinting();
		OnCreatePrintingDialog();
		
		dcPrint.SetAbortProc(MlsPrintAbortProc);

		CString docTitle;
		GetTitle(docTitle);
		
		if (docTitle.GetLength() > 31)
		{
			docTitle.ReleaseBuffer(31);
		}

		DOCINFO docInfo;
		memset(&docInfo, 0, sizeof(DOCINFO));
		docInfo.cbSize = sizeof(DOCINFO);
		docInfo.lpszDocName = docTitle;
//		docInfo.lpszOutput = NULL;

		if (dcPrint.StartDoc(&docInfo) != SP_ERROR)
		{
			UINT nEndPage = m_pInfo->GetToPage();
			UINT nStartPage = m_pInfo->GetFromPage();
	
			// Guarantee values are in the valid range
			if (nEndPage < m_pInfo->GetMinPage())
				nEndPage = m_pInfo->GetMinPage();
			if (nEndPage > m_pInfo->GetMaxPage())
				nEndPage = m_pInfo->GetMaxPage();
	
			if (nStartPage < m_pInfo->GetMinPage())
				nStartPage = m_pInfo->GetMinPage();
			if (nStartPage > m_pInfo->GetMaxPage())
				nStartPage = m_pInfo->GetMaxPage();
	
			int nStep = (nEndPage >= nStartPage) ? 1 : -1;
			nEndPage = (nEndPage == 0xffff) ? 0xffff : nEndPage + nStep;
	
			BOOL bError = FALSE;
			for (m_pInfo->m_nCurPage = nStartPage; !bError && m_pInfo->m_nCurPage != nEndPage; m_pInfo->m_nCurPage += nStep)
			{
				OnPrepareDC();
	
				if (!m_pInfo->m_bContinuePrinting)
				{
					break;
				}
	
				// Set up drawing rect to entire page (in logical coordinates)
				m_pInfo->m_rectDraw.SetRect(0, 0, dcPrint.GetDeviceCaps(HORZRES), dcPrint.GetDeviceCaps(VERTRES));
				dcPrint.DPtoLP(&m_pInfo->m_rectDraw);
				
				OnUpdatePrintingDialog();
				
				VERIFY(dcPrint.StartPage());
				
				OnPrint();
				
				if (dcPrint.EndPage() < 0)
				{
					bError = TRUE;
				}
			}
	
			if (!bError)
			{
				dcPrint.EndDoc();
			}
		}
		
		else
		{
			AfxMessageBox(AFX_IDP_FAILED_TO_START_PRINT);
		}
		
		OnEndPrinting();
		OnReleasePrintingDialog();
		
		m_pDC = NULL;
	}
	
	m_pInfo = NULL;
	
	return fSuccess;
}