In your application code, provide an abort function to process messages for the Abort dialog box.
An abort function retrieves messages from the application queue and dispatches them if they are intended for the Abort dialog box. The function continues to loop until it encounters the WM_DESTROY message or until the print operation is complete.
Applications that make lengthy print requests must pass an abort function to GDI to handle special situations during printing operations. The most common situation occurs when a printing operation fills the available disk space before the spooler can copy the data to the printer. Since the spooler can continue to print even though disk space is full, GDI calls the abort function to see if the application wants to cancel the print operation or simply wait until disk space is free.
To specify the abort function, first get the procedure-instance address for the function:
lpAbortProc = MakeProcInstance (AbortProc, hInst);
Then call the Escape function with the SETABORTPROC value and the Abort function's address:
Escape(hDC, SETABORTPROC, 0, lpAbortProc, 0L);
GDI will then call the abort function during spooling. An abort function must have the following form:
int FAR PASCAL AbortProc(hPr, Code)
1 HDC hPr;
2 int Code;
where:
1 | The hPr argument is a handle to the printer device context. | |||
2 | The Code argument specifies the nature of the call. It can take one of two values: | |||
Value | Meaning | |||
SP_OUTOFDISK | Spooler has run out of disk space while spooling the data file. The printing operation will continue if the application waits for disk space to become free. | |||
0 | Spooler operation is continuing without error. |
Once GDI has called the abort function, the function can return TRUE to continue the spooler operation immediately, or return FALSE to cancel the printing operation. Most abort functions call the PeekMessage function to temporarily yield control, then return TRUE to continue the print operation. Yielding control typically gives the spooler enough time to free some disk space.
If the abort function returns FALSE, the printing operation is canceled and an error value is returned by the application's next call to the Escape function.
IMPORTANT:
If your application encounters a printing error or a canceled print operation, it must not attempt to terminate the operation by using the Escape function with either the ENDDOC or ABORTDOC escape. GDI automatically terminates the operation before returning the error value.
The following example shows the statements required for the abort function:
int FAR PASCAL AbortProc(hPr, Code)
HDC hPr; /* for multiple printer
display contexts */
int Code; /* for printing status */
{
MSG msg;
/* Process messages intended
for the abort dialog box */
while (PeekMessage((LPMSG) &msg,
NULL, NULL, NULL, PM_REMOVE))
if(!IsDialogMessage(hAbortDlgWnd,
(LPMSG) &msg)) {
TranslateMessage((LPMSG) &msg);
DispatchMessage((LPMSG) &msg);
}
/* bAbort is TRUE (return is FALSE)
if the user has aborted */
return(!bAbort);
}