home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / Pascal / Snippets / PNL Libraries / MySystemGlobals.p < prev    next >
Encoding:
Text File  |  1997-04-10  |  2.8 KB  |  98 lines  |  [TEXT/CWIE]

  1. unit MySystemGlobals;
  2.  
  3. interface
  4.  
  5.     uses
  6.         Types, Quickdraw, Files,
  7.         MyVersionResource;
  8.  
  9.     var  { set up by InitSystemGlobals }
  10.         system7: boolean;
  11.         system_version: longint;
  12.         has_AppleEvents: boolean;
  13.         has_FindFolder: boolean;
  14.         has_AliasManager: boolean;
  15.         has_NewStandardFile: boolean;
  16.         has_HelpManager: boolean;
  17.         has_ColourQuickDraw: boolean;
  18.         has_LaunchControl: Boolean;
  19.         has_VirtualMemory: Boolean;
  20.         app_resfile: integer;
  21.         app_fs: FSSpec;
  22.         in_foreground: boolean;
  23.         version: versionRecord;
  24.  
  25.     procedure InitSystemGlobals;
  26.     function RefNumToFSSpec(rn:integer; var fs:FSSpec):OSErr;
  27.     procedure SetInForeground (fore: boolean);
  28.     function InForeground: boolean;
  29.     
  30. implementation
  31.  
  32.     uses
  33.         OSUtils, Resources, GestaltEqu, Processes;
  34. {
  35.     function TPbtst(value:longint; bit:integer):Boolean;
  36.     begin
  37.         TPbtst := btst(value, bit);
  38.     end;
  39. }    
  40.     procedure SetInForeground (fore: boolean);
  41.     begin
  42.         in_foreground := fore;
  43.     end;
  44.  
  45.     function InForeground: boolean;
  46.         var
  47.             gv: longint;
  48.             ourpsn, frontpsn: ProcessSerialNumber;
  49.             front: boolean;
  50.     begin
  51.         if (Gestalt(gestaltOSAttr, gv) = noErr) & (btst(gv, gestaltLaunchControl)) then begin
  52.             if (GetCurrentProcess(ourpsn) = noErr) & (GetFrontProcess(frontpsn) = noErr) then begin
  53.                 if SameProcess(ourpsn, frontpsn, front) = noErr then begin
  54.                     in_foreground := front;
  55.                 end;
  56.             end;
  57.         end;
  58.         InForeground := in_foreground;
  59.     end;
  60.  
  61.     function RefNumToFSSpec(rn:integer; var fs:FSSpec):OSErr;
  62.         var
  63.             pb: FCBPBRec;
  64.     begin
  65.         pb.ioNamePtr := @fs.name;
  66.         pb.ioVRefNum := 0;
  67.         pb.ioRefNum := rn;
  68.         pb.ioFCBIndx := 0;
  69.         RefNumToFSSpec := PBGetFCBInfoSync(@pb);
  70.         fs.vRefNum := pb.ioFCBVRefNum;
  71.         fs.parID := pb.ioFCBParID;
  72.     end;
  73.     
  74.     procedure InitSystemGlobals;
  75.         var
  76.             oe: OSErr;
  77.             gv: longint;
  78.             sysenv: SysEnvRec;
  79.     begin
  80.         has_ColourQuickDraw := (SysEnvirons(1, sysenv) = noErr) & sysenv.hasColorQD; { Gestalt has a bug that causes hasColourQD to always be set }
  81.         if (Gestalt(gestaltSystemVersion, system_version) <> noErr) then begin
  82.             system_version := $0600;
  83.         end;
  84.         system7 := system_version >= $0700;
  85.         app_resfile := CurResFile;
  86.         oe := RefNumToFSSpec(app_resfile, app_fs);
  87.         has_AppleEvents := (Gestalt(gestaltAppleEventsAttr, gv) = noErr) & (btst(gv, gestaltAppleEventsPresent));
  88.         has_FindFolder := (Gestalt(gestaltFindFolderAttr, gv) = noErr) & (btst(gv, gestaltFindFolderPresent));
  89.         has_NewStandardFile := (Gestalt(gestaltStandardFileAttr, gv) = noErr) & (btst(gv, gestaltStandardFile58));
  90.         has_HelpManager := (Gestalt(gestaltHelpMgrAttr, gv) = noErr) & (btst(gv, gestaltHelpMgrPresent));
  91.         has_AliasManager := (Gestalt(gestaltAliasMgrAttr, gv) = noErr) & (btst(gv, gestaltAliasMgrPresent));
  92.         has_LaunchControl := (Gestalt(gestaltOSAttr, gv) = noErr) & (btst(gv, gestaltLaunchControl));
  93.         has_VirtualMemory := (Gestalt(gestaltVMAttr, gv) = noErr) & (btst(gv, gestaltVMPresent));
  94.         in_foreground := true;
  95.         GetVersion(app_resfile, version);
  96.     end;
  97.  
  98. end.