home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 October: Mac OS SDK / Dev.CD Oct 00 SDK1.toast / Development Kits / Mac OS / Display Manager SDK / Sample Code / Display Changed CWPro3 / Source / main.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-01-20  |  3.3 KB  |  146 lines  |  [TEXT/CWIE]

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