home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1999 / MacHack 1999.toast / The Hacks / ReaderMouse / MyUtils.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-06-20  |  2.5 KB  |  120 lines  |  [TEXT/CWIE]

  1. /*
  2.     File:        MySGStuff.c
  3.     
  4.     Contains:    Sequence grabber code.
  5.  
  6.     Written by:    John Wang
  7.  
  8.     Copyright:    © 1994 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     Change History (most recent first):
  11.  
  12.         <1>        04/04/94    JW        Created.
  13.  
  14.     To Do:
  15.     
  16.         I added ReportMessage
  17.  
  18.     
  19. */
  20.  
  21. #ifdef THINK_C
  22. #define        applec
  23. #endif
  24. #include    "MyHeaders.h"
  25. #include    <Folders.h>
  26. #include    <TextUtils.h>
  27.  
  28. #include    "MyCaptureAppShell.h"
  29. //#include    "MySGStuff.h"
  30. #include    "MyUtils.h"
  31.  
  32.  
  33. #define STR_PREFSNAME 128
  34.  
  35.  
  36. /* ------------------------------------------------------------------------- */
  37.  
  38. //    Show Alert.  Then, return true is err != noErr.
  39. void ReportWarning(Str255 procStr, long err)
  40. {
  41.     Str255    myStr;
  42.     
  43.     NumToString(err, myStr);
  44.     ParamText("\pWarning!", procStr, err ? myStr : nil, nil);
  45.     Alert(kALERT_ERROR, nil);
  46. }
  47.  
  48. void ReportMessage(Str255 procStr)
  49. {    
  50.     ParamText(procStr, nil, nil, nil);
  51.     Alert(kALERT_ERROR, nil);
  52. }
  53.  
  54.  
  55.  
  56. void ReportFatal(Str255 procStr, long err)
  57. {
  58.     Str255    myStr;
  59.     
  60.     NumToString(err, myStr);
  61.     ParamText("\pFatal Error!", procStr, err ? myStr : nil, nil);
  62.     Alert(kALERT_ERROR, nil);
  63.     ExitToShell();
  64. }
  65.  
  66. void GetGlobalWindow(WindowPtr theWindow, Rect *windowRect)
  67. {
  68.     //    Get the windowRect in global coordinates.
  69.     *windowRect = theWindow->portRect;
  70.     LocalToGlobal(&topLeft(*windowRect));
  71.     LocalToGlobal(&botRight(*windowRect));
  72. }
  73.  
  74. /* ------------------------------------------------------------------------- */
  75.  
  76. //    readPreferencesFile will return refnum = -1 if not found.
  77. short readPreferencesFile()
  78. {
  79.     short            myVRefNum;
  80.     long            myDirID;
  81.     StringHandle    prefsName;
  82.     short            myRefNum;
  83.     
  84.     if (FindFolder(kOnSystemDisk, kPreferencesFolderType, true, &myVRefNum, &myDirID))
  85.         return(-1);
  86.     
  87.     prefsName = GetString(STR_PREFSNAME);
  88.     myRefNum = HOpenResFile(myVRefNum, myDirID, (unsigned char *) *prefsName, fsRdPerm);
  89.     ReleaseResource((Handle) prefsName);
  90.     
  91.     return(myRefNum);
  92. }
  93.  
  94. //    writePreferencesFile returns -1 if preferences file can't be opened.
  95. short writePreferencesFile()
  96. {
  97.     short            myVRefNum;
  98.     long            myDirID;
  99.     StringHandle    prefsName;
  100.     short            myRefNum;
  101.     
  102.     if (FindFolder(kOnSystemDisk, kPreferencesFolderType, true, &myVRefNum, &myDirID))
  103.         return(-1);
  104.     
  105.     prefsName = GetString(STR_PREFSNAME);
  106.     HDelete(myVRefNum, myDirID, (unsigned char *) *prefsName);
  107.     HCreateResFile(myVRefNum, myDirID, (unsigned char *) *prefsName);
  108.     myRefNum = HOpenResFile(myVRefNum, myDirID, (unsigned char *) *prefsName, fsRdWrPerm);
  109.     ReleaseResource((Handle) prefsName);
  110.     
  111.     return(myRefNum);
  112. }
  113.  
  114. void closePreferencesFile(short myRefNum)
  115. {
  116.     UpdateResFile(myRefNum);
  117.     CloseResFile(myRefNum);
  118. }
  119.  
  120.