home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 …ember: Reference Library / Apple Developer Reference Library (December 1999) (Disk 1).iso / pc / technical documentation / macintosh technotes and q&as / qa / qd / inhibitprjobdialog.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-07-09  |  2.3 KB  |  136 lines

  1. #define OLDROUTINELOCATIONS            0
  2. #define OLDROUTINENAMES                0
  3. #define SystemSevenOrLater            1
  4.  
  5. #ifndef __FONTS__
  6. #    include <Fonts.h>
  7. #endif
  8.  
  9. #ifndef __DIALOGS__
  10. #    include <Dialogs.h>
  11. #endif
  12.  
  13. #ifndef __PRINTING__
  14. #    include <Printing.h>
  15. #endif
  16.  
  17. static TPPrDlgRef    gTPPrDlgRef;
  18. static DialogRef    gDialogRef;
  19.  
  20. static pascal OSErr InitMac (void)
  21. {
  22.     MaxApplZone ( );
  23.     InitGraf (&(qd.thePort));
  24.     InitFonts ( );
  25.     InitWindows ( );
  26.     InitMenus ( );
  27.     TEInit ( );
  28.     InitDialogs (nil);
  29.     InitCursor ( );
  30.  
  31.     return noErr;
  32. }
  33.  
  34. static pascal OSErr ReportError (OSErr)
  35. {
  36.     SysBeep (-1);
  37.     return noErr;
  38. }
  39.  
  40. static pascal TPPrDlgRef PDlgInitProc (THPrint)
  41. {
  42.     return gTPPrDlgRef;
  43. }
  44.  
  45. static pascal Boolean ModalFilterProc
  46.     (DialogPtr dialog, EventRecord *event, short *itemHit)
  47. {
  48.     Boolean handledIt = false;
  49.  
  50.     if (gDialogRef == dialog)
  51.     {
  52.         if (event->what == nullEvent)
  53.         {
  54.             *itemHit = kStdOkItemIndex;
  55.             handledIt = true;
  56.         }
  57.     }
  58.  
  59.     return handledIt;
  60. }
  61.  
  62. void main (void)
  63. {
  64.     OSErr err = InitMac ( );
  65.  
  66.     if (err)
  67.         SysBeep (-1);
  68.     else
  69.     {
  70.         THPrint printRecordH = (THPrint) NewHandle (sizeof (TPrint));
  71.  
  72.         if (!printRecordH)
  73.             err = MemError ( );
  74.         else
  75.         {
  76.             OSErr err2 = noErr;
  77.  
  78.             PrOpen ( );
  79.  
  80.             if (!(err = PrError ( )))
  81.             {
  82.                 PrintDefault (printRecordH);
  83.  
  84.                 if (!(err = PrError ( )))
  85.                 {
  86.                     TPPrDlgRef prDlg = PrJobInit (printRecordH);
  87.  
  88.                     if (!(err = PrError ( )))
  89.                     {
  90.                         ModalFilterUPP modalFilterUPP = NewModalFilterProc (ModalFilterProc);
  91.  
  92.                         if (!modalFilterUPP)
  93.                             err = nilHandleErr;
  94.                         else
  95.                         {
  96.                             PDlgInitUPP pDlgInitUPP = NewPDlgInitProc (PDlgInitProc);
  97.  
  98.                             if (!pDlgInitUPP)
  99.                                 err = nilHandleErr;
  100.                             else
  101.                             {
  102.                                 Boolean userApprovedPrintJob;
  103.                                 MoveWindow ((WindowRef) prDlg, -32000, -32000, false);
  104.  
  105.                                 prDlg->pFltrProc = modalFilterUPP;
  106.  
  107.                                 gTPPrDlgRef    = prDlg;
  108.                                 gDialogRef    = (DialogRef) prDlg;
  109.  
  110.                                 userApprovedPrintJob = PrDlgMain (printRecordH,pDlgInitUPP);
  111.                                 if (!(err = PrError ( )) && userApprovedPrintJob)
  112.                                 {
  113.                                     // do the rest of your printing here
  114.                                 }
  115.                                 DisposeRoutineDescriptor (pDlgInitUPP);
  116.                             }
  117.                             DisposeRoutineDescriptor (modalFilterUPP);
  118.                         }
  119.                     }
  120.                 }
  121.  
  122.                 PrClose ( );
  123.                 err2 = PrError ( );
  124.                 if (!err) err = err2;
  125.             }
  126.  
  127.             DisposeHandle ((Handle) printRecordH);
  128.             err2 = MemError ( );
  129.             if (!err) err = err2;
  130.         }
  131.  
  132.         if (err)
  133.             (void) ReportError (err);
  134.     }
  135. }
  136.