home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / progwin / chap15 / print2.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-11-12  |  1.8 KB  |  67 lines

  1. /*------------------------------------------
  2.    PRINT2.C -- Printing with Abort Function
  3.                (c) Charles Petzold, 1990
  4.   ------------------------------------------*/
  5.  
  6. #include <windows.h>
  7.  
  8. HDC  GetPrinterDC (void) ;              // in PRINT.C
  9. void PageGDICalls (HDC, short, short) ;
  10.  
  11. HANDLE hInst ;
  12. char   szAppName [] = "Print2" ;
  13. char   szCaption [] = "Print Program 2 (Abort Function)" ;
  14.  
  15. BOOL FAR PASCAL AbortProc (HDC hdcPrn, short nCode)
  16.      {
  17.      MSG   msg ;
  18.  
  19.      while (PeekMessage (&msg, NULL, 0, 0, PM_REMOVE))
  20.           {
  21.           TranslateMessage (&msg) ;
  22.           DispatchMessage (&msg) ;
  23.           }
  24.      return TRUE ;
  25.      }
  26.  
  27. BOOL PrintMyPage (HWND hwnd)
  28.      {
  29.      static char szMessage [] = "Print2: Printing" ; 
  30.      BOOL        bError = FALSE ;
  31.      FARPROC     lpfnAbortProc ;
  32.      HDC         hdcPrn ;
  33.      RECT        rect ;
  34.      short       xPage, yPage ;
  35.  
  36.      if (NULL == (hdcPrn = GetPrinterDC ()))
  37.           return TRUE ;
  38.  
  39.      xPage = GetDeviceCaps (hdcPrn, HORZRES) ;
  40.      yPage = GetDeviceCaps (hdcPrn, VERTRES) ;
  41.  
  42.      EnableWindow (hwnd, FALSE) ;
  43.  
  44.      lpfnAbortProc = MakeProcInstance (AbortProc, hInst) ;
  45.      Escape (hdcPrn, SETABORTPROC, 0, (LPSTR) lpfnAbortProc, NULL) ;
  46.  
  47.      if (Escape (hdcPrn, STARTDOC, sizeof szMessage - 1, szMessage, NULL) > 0)
  48.           {
  49.           PageGDICalls (hdcPrn, xPage, yPage) ;
  50.  
  51.           if (Escape (hdcPrn, NEWFRAME, 0, NULL, NULL) > 0)
  52.                Escape (hdcPrn, ENDDOC, 0, NULL, NULL) ;
  53.           else
  54.                bError = TRUE ;
  55.           }
  56.      else
  57.           bError = TRUE ;
  58.  
  59.      if (!bError)
  60.           Escape (hdcPrn, ENDDOC, 0, NULL, NULL) ;
  61.  
  62.      FreeProcInstance (lpfnAbortProc) ;
  63.      EnableWindow (hwnd, TRUE) ;
  64.      DeleteDC (hdcPrn) ;
  65.      return bError ;
  66.      }
  67.