Michael Knight
asked on
How to print multiple copies?
I'm using the GetDefaultDC (I think that's what it's called)... How do I print multiple copies of the document like this w/o displaying the printer dialog box. I set the number of pages var in the structure to the correct number of copies, but it always just prints one copy. Thanks.
Can you paste some code of what you're doing? Are you doing this in the doc/view architecture? Just give us more details and we'll do our best.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Here is some sample code of the section in question... Would DocumentProperties work with this method?
// create the print object (display print dlg set, print all pages w/o page numbers, hide print to file, disable selection)
CPrintDialog *PrintTheReportDlg = new CPrintDialog(FALSE,PD_ALLP AGES | PD_COLLATE | PD_NOPAGENUMS | PD_HIDEPRINTTOFILE | PD_NOSELECTION | PD_RETURNDC);
PrintTheReportDlg->m_pd.nC opies = numberofcopies;
// display the Print Dialog where user can select their preferred settings if Print button was pressed
if (showprintdlg)
{
int return_value = PrintTheReportDlg->DoModal ();
// if dialog did not return IDOK, then check for an error occurance
if (return_value != IDOK)
{
if (return_value != IDCANCEL)
AfxMessageBox("The Printer Dialog Returned An Error.\nCannot Print Report.",MB_OK | MB_ICONEXCLAMATION);
delete PrintTheReportDlg;
return(FALSE);
}
}
// on AutoPrint, we just call for the default printer info
else
PrintTheReportDlg->GetDefa ults();
// create the print object (display print dlg set, print all pages w/o page numbers, hide print to file, disable selection)
CPrintDialog *PrintTheReportDlg = new CPrintDialog(FALSE,PD_ALLP
PrintTheReportDlg->m_pd.nC
// display the Print Dialog where user can select their preferred settings if Print button was pressed
if (showprintdlg)
{
int return_value = PrintTheReportDlg->DoModal
// if dialog did not return IDOK, then check for an error occurance
if (return_value != IDOK)
{
if (return_value != IDCANCEL)
AfxMessageBox("The Printer Dialog Returned An Error.\nCannot Print Report.",MB_OK | MB_ICONEXCLAMATION);
delete PrintTheReportDlg;
return(FALSE);
}
}
// on AutoPrint, we just call for the default printer info
else
PrintTheReportDlg->GetDefa
Here's the doc for nCopies in the PRINTDLG structure:
nCopies
Contains the initial number of copies for the Copies edit control if hDevMode is NULL; otherwise, the dmCopies member of the DEVMODE structure contains the initial value. When PrintDlg returns, nCopies contains the actual number of copies to print. This value depends on whether the application or the printer driver is responsible for printing multiple copies. If the PD_USEDEVMODECOPIESANDCOLL ATE flag is set in the Flags member, nCopies is always 1 on return, and the printer driver is responsible for printing multiple copies. If the flag is not set, the application is responsible for printing the number of copies specified by nCopies. For more information, see the description of the PD_USEDEVMODECOPIESANDCOLL ATE flag.
As you can see sometimes the printer will be responsible for the copies and sometimes the APP will be responsible. This means that your printer might not be able to handle mutliple copies. Check for the flag as explained up here and either print the copies yourself by placing your code in a for() statement or not, depending on the presence of the flag.
nCopies
Contains the initial number of copies for the Copies edit control if hDevMode is NULL; otherwise, the dmCopies member of the DEVMODE structure contains the initial value. When PrintDlg returns, nCopies contains the actual number of copies to print. This value depends on whether the application or the printer driver is responsible for printing multiple copies. If the PD_USEDEVMODECOPIESANDCOLL
As you can see sometimes the printer will be responsible for the copies and sometimes the APP will be responsible. This means that your printer might not be able to handle mutliple copies. Check for the flag as explained up here and either print the copies yourself by placing your code in a for() statement or not, depending on the presence of the flag.