Winapi Startdoc Cannot Detect User Chose Cancel in Saveas Dialog

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
Chloe Bennett

Chloe Bennett

Culture, Media & Entertainment Columnist

Chloe Bennett explores the intersection of pop culture, streaming entertainment, digital trends, and contemporary lifestyle. Her weekly commentary reaches thousands of culture enthusiasts.

Share this article