Winapi StartDoc cannot detect user chose cancel in saveas dialog

Posted by Carisa Kissane on Wednesday, May 22, 2024

When the user responds to the Print dialog invoked by StartDoc() function, by pressing Cancel button, StartDoc() returns false and the program cancels the print job.

However, when the user chooses pdf printer driver, it can open another dialog for naming the pdf file. If the user chooses Cancel at this stage, StartDoc() does not return false to the calling function. The program actually performs all the printing process except a file is not created. How to detect the user selected Cancel in Saveas dialogbox of the printer driver in order to avoid lengthy printing process.

Is there a way to detect the user selected Cancel in the later Saveas dialog.

Below is a sample code:

 PRINTDLGEX Printdlgex ; HDC PrintDC = GetPrinterDC (hwnd,&Printdlgex) ; if (! PrintDC) return false ; static DOCINFO di = { sizeof (DOCINFO), "My Program", NULL } ; if (StartDoc (PrintDC,&di) > 0) { if (StartPage (PrintDC) > 0) { // Lengthy Printing process } /* if (StartPage (PrintDC) > 0) */ } /* if (StartDoc (PrintDC,&di) > 0) */ 
6 Related questions 2 Suppressing the Save As dialog on Microsoft XPS Document Writer when converting GDI To XPS 4 bypass Adobe PDF Printer "SaveFileAs" prompt 6 Capture print dialog's cancel in silverlight printing Related questions 2 Suppressing the Save As dialog on Microsoft XPS Document Writer when converting GDI To XPS 4 bypass Adobe PDF Printer "SaveFileAs" prompt 6 Capture print dialog's cancel in silverlight printing 1 If Printer Dialog Cancelled, Then Don't Print? 4 Convert Word to PDF - Disable "save" Dialog 2 Access Word 'Save As' dialog box with PowerShell script 2 Is there any way of suppressing ‘Do you want to save changes to xxx.pdf before closing’ dialog using ABCpdf 1 Macro "Save to PDF" saves even on cancels 2 VBA “Save to PDF” saves even on cancels 0 Word. Save as PDF without dialog window Load 7 more related questions Show fewer related questions

Sorted by: Reset to default

ncG1vNJzZmirpJawrLvVnqmfpJ%2Bse6S7zGiorp2jqbawutJoa29uaWV%2FdnyOsKCnmaCeerTAwKurnaeTYrCius2oq2aclamypMCMrqqeql2YtbC%2FxGaamqaTmrlutc1mqpqulZbAbrDImqOonw%3D%3D