home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / Pascal / Snippets / CopyBits Demo / MySystemUtils.p < prev    next >
Encoding:
Text File  |  1995-10-23  |  1.5 KB  |  88 lines  |  [TEXT/MWPS]

  1. { MySystemUtils.p
  2. {
  3. { Pascal version by Bill Catambay
  4. { Original C version by Kenneth Worley
  5. { Public Domain
  6. }
  7. Unit MySystemUtils;
  8.  
  9. Interface
  10.  
  11. Uses
  12.     Types, Windows, Fonts, Dialogs;
  13.     
  14. Procedure InitToolbox;
  15. Function GetSysVersion: integer;
  16. Function HasColorQuickDraw: Boolean;
  17. Function WindowDevice( winPtr: WindowPtr): GDHandle;
  18.  
  19. Implementation
  20.  
  21. Procedure InitToolbox;
  22.  
  23.     begin
  24.     { Initialize the Mac Toolbox Managers }
  25.     InitGraf(@qd.thePort);
  26.     InitFonts;
  27.     InitWindows;
  28.     InitMenus;
  29.     FlushEvents(everyEvent,0);
  30.     TEInit;
  31.     InitDialogs(NIL);
  32.     InitCursor;
  33.     end;
  34.  
  35. Function GetSysVersion: integer;
  36.  
  37. Var
  38.     env:        SysEnvRec;
  39.     err:        OSErr;
  40.     
  41.     begin
  42.     GetSysVersion := 0;
  43.     err := SysEnvirons( 2, env );
  44.     if err <> NoErr then
  45.         exit(GetSysVersion);
  46.     if env.systemVersion >= $0700 then
  47.         GetSysVersion := 7
  48.     else if env.systemVersion >= $0600 then
  49.         GetSysVersion := 6;
  50.     end;
  51.  
  52. Function HasColorQuickDraw: Boolean;
  53.  
  54. Var
  55.     env:        SysEnvRec;
  56.     err:        OSErr;
  57.     
  58.     begin
  59.     err := SysEnvirons( 2, env );
  60.     if err = NoErr then
  61.         HasColorQuickDraw := env.hasColorQD
  62.     else
  63.         HasColorQuickDraw := false;
  64.     end;
  65.  
  66. Function WindowDevice( winPtr: WindowPtr): GDHandle;
  67.  
  68. Var
  69.     theDevice:        GDHandle;
  70.     targetPt:        Point;
  71.     
  72.     begin
  73.     targetPt := winPtr^.portRect.topLeft;
  74.     theDevice := GetDeviceList;
  75.     while (not PtInRect(targetPt, theDevice^^.gdRect)) do
  76.         begin
  77.         theDevice := GetNextDevice( theDevice );
  78.         if theDevice = NIL then
  79.             begin
  80.             theDevice := GetMainDevice;
  81.             leave;
  82.             end;
  83.         end;
  84.     WindowDevice := theDevice;
  85.     end;
  86.  
  87. End.
  88.