Preparing to Print

The following code sample determines whether the selected printer is capable of printing bitmaps by calling the GetDeviceCaps function, supplying the RASTERCAPS value. By examining this function's return value, the application can determine whether it should print a document or inform the user that the device does not support raster output.

// Examine the raster capabilities of the device identified by pd.hDC 
// to verify that it supports the BitBlt function. 
 
if (!(GetDeviceCaps(pd.hDC, RASTERCAPS) 
    & RC_BITBLT)) 
{ 
    DeleteDC(pd.hDC); 
    MessageBox(hwnd, 
        "Printer cannot display bitmaps.", 
        "Device Error", 
        MB_OK); 
    break; 
} 
 

After the sample application determines that the selected printer is capable of printing bitmaps, it follows these steps:

  1. Sets a Boolean flag that the application's abort procedure can examine to determine whether to allow printing to continue.
  2. Registers the application's AbortProc function, which is used to cancel a print job.
  3. Displays a modeless Cancel dialog box.
  4. Disables the application's window while the dialog box is displayed.

The steps are illustrated in the following code sample.

// Set the flag used by the AbortPrintJob dialog procedure. 
 
bPrint = TRUE; 
 
// Register the application's AbortProc function with GDI. 
 
SetAbortProc(pd.hDC, AbortProc); 
 
// Display the modeless Cancel dialog box. 
 
hdlgCancel = CreateDialog(hinst, (LPTSTR) "AbortDlg", 
    hwnd, (DLGPROC) AbortPrintJob); 
 
// Disable the application's window. 
 
EnableWindow(hwnd, FALSE); 
 

Once the application registers AbortProc, GDI calls the function repeatedly during the printing process to determine whether to cancel a job. In the current version of the Win32 API, GDI calls this function approximately every two seconds until the entire job has been spooled.

If the user chooses to cancel the job, GDI notifies the spooler that it should delete the corresponding journal file from the print queue and reset the printer to its default state.