home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 November: Tool Chest / Dev.CD Nov 98 TC.toast / Sample Code / QuickTime / JPEG Sample / Source / main.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-03-05  |  3.5 KB  |  158 lines  |  [TEXT/CWIE]

  1. /*************************************************************************************
  2. #
  3. #        main.c
  4. #
  5. #        This is the main entry point.
  6. #
  7. #        Author(s):     Michael Marinkovich & Guillermo Ortiz
  8. #                    marink@apple.com
  9. #
  10. #        Modification History: 
  11. #
  12. #            4/3/96        MWM     Initial coding                     
  13. #
  14. #        Copyright © 1992-96 Apple Computer, Inc., All Rights Reserved
  15. #
  16. #
  17. #        You may incorporate this sample code into your applications without
  18. #        restriction, though the sample code has been provided "AS IS" and the
  19. #        responsibility for its operation is 100% yours.  However, what you are
  20. #        not permitted to do is to redistribute the source as "DSC Sample Code"
  21. #        after having made changes. If you're going to re-distribute the source,
  22. #        we require that you make it clear in the source that the code was
  23. #        descended from Apple Sample Code, but that you've made changes.
  24. #
  25. *************************************************************************************/
  26.  
  27. #include <ConditionalMacros.h>
  28. #if OLDROUTINELOCATIONS
  29.     #include <SegLoad.h>
  30. #else
  31.     #include <Processes.h>
  32. #endif
  33. #include <Resources.h>
  34. #include <ToolUtils.h>
  35.  
  36. #include "App.h"
  37. #include "Global.h"
  38. #include "Proto.h"
  39.  
  40.  
  41.  
  42. //----------------------------------------------------------------------
  43. //
  44. //    main - main entry point of our program
  45. //
  46. //
  47. //----------------------------------------------------------------------
  48.  
  49. void main(void)
  50. {
  51.     OSErr            err;
  52.     short            m = 5;
  53.         
  54.     MaxApplZone();
  55.     
  56.     for (;m == 0;m--)                 // alloc the master pointers
  57.     {
  58.         MoreMasters();
  59.     }
  60.     
  61.     err = Initialize();
  62.     
  63.     EventLoop();
  64.         
  65.     ExitToShell();
  66.  
  67. }
  68.  
  69.  
  70. //----------------------------------------------------------------------
  71. //
  72. //    HandleError - basic error notification procedure
  73. //
  74. //
  75. //----------------------------------------------------------------------
  76.  
  77. void HandleError(short errNo,Boolean fatal)
  78. {
  79.     DialogPtr            errDialog;
  80.     short                itemHit;
  81.     short                c;
  82.     Handle                button;
  83.     short                itemType;
  84.     Rect                itemRect;
  85.     StringHandle        errString;
  86.     Str255                numString;
  87.     GrafPtr                oldPort;
  88.     
  89.     GetPort(&oldPort);
  90.     SysBeep(30);
  91.     SetCursor(&qd.arrow);
  92.     
  93.     errDialog = GetNewDialog(rErrorDlg, nil, (WindowPtr) -1);
  94.     if (errDialog != nil) 
  95.     {
  96.         ShowWindow(errDialog);
  97.         SetPort(errDialog);
  98.         SetGWorld((CGrafPtr)errDialog, nil);
  99.         PenPat(&qd.gray);                                // frame user areas
  100.         
  101.         for (c = 7;c < 9;c++) 
  102.         {
  103.             GetDItem(errDialog,c,&itemType,&button,&itemRect);
  104.             FrameRect(&itemRect);
  105.         }
  106.         PenPat(normal);
  107.  
  108.         GetDItem( errDialog, fatal ? 2 : 1, &itemType, &button, &itemRect );
  109.         HiliteControl( (ControlHandle)button, 255);         //    unhilite appropriate button
  110.         
  111.         SetDialogDefaultItem(errDialog,fatal  ? 1 : 2);
  112.         
  113.         NumToString( errNo, numString );
  114.         if ( errNo < 0 )
  115.             errNo = -errNo + 200;
  116.             
  117.         errString = GetString( 128 + errNo );
  118.         
  119.         if ( errString == nil )
  120.                 errString = GetString( 128 );
  121.         
  122.         DetachResource((Handle)errString);
  123.         HLock((Handle)errString);
  124.         ParamText( numString, *errString, nil, nil );
  125.         HUnlock((Handle)errString);
  126.         DisposeHandle((Handle)errString);
  127.         
  128.         ModalDialog( nil, &itemHit );
  129.         
  130.         SetPort( oldPort );
  131.  
  132.         DisposeDialog( errDialog );
  133.     }
  134.     else
  135.         ExitToShell();        // since didn't have mem to open dialog assume the worst
  136.             
  137.     if (fatal) 
  138.         ExitToShell();        //    it's a bad one, get out of here
  139.     
  140. }
  141.  
  142.  
  143. //----------------------------------------------------------------------
  144. //
  145. //    HandleAlert - display alert and then exit to shell
  146. //
  147. //
  148. //----------------------------------------------------------------------
  149.  
  150. void HandleAlert(short alertID)
  151. {
  152.     short            item;
  153.     
  154.     
  155.     item = Alert(alertID, nil);
  156.     ExitToShell();
  157.  
  158. }