12.6.4 Performing a Cancelable Print Operation

Before beginning a print operation, your application should do the following to ensure that the user can cancel the operation:

1.Define a print-canceling function, as described in the preceding section.

2.Use the MakeProcInstance function to retrieve the procedure-instance address for the print-canceling function.

When your application begins a print operation, it should do the following:

1.Use the SetAbortProc function to specify the print-canceling function the application will use during the print operation. When calling SetAbortProc, specify the procedure-instance address of the application's print-canceling function.

2.Use the CreateDialog, ShowWindow, and UpdateWindow functions to create and display the Abort dialog box.

3.Use the EnableWindow function to disable your parent window.

4.Start the normal print operation, but check the return value from the EndPage function (or the NEXTBAND escape) after each call. If the return value is less than zero, the user has canceled the operation or an error has occurred.

5.Use the DestroyWindow function to destroy the Abort dialog box, if necessary. (Windows destroys the box automatically if the user cancels the print operation.)

6.Use the EnableWindow function to reenable the parent window.