home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Mac Game Programming Gurus / TricksOfTheMacGameProgrammingGurus.iso / More Source / Pascal / Skel 3.0i / Skel docommand.p < prev    next >
Encoding:
Text File  |  1994-04-12  |  2.2 KB  |  84 lines  |  [TEXT/PJMM]

  1. unit DoCommand;
  2.  
  3. interface
  4.     uses
  5.         Globals, Report;
  6.  
  7.     function DoCommand (mresult: Longint): Boolean;
  8.  
  9. implementation
  10.  
  11. {Handle a command given through a menu selection}
  12. {############################   DoCommand   ##############################}
  13.  
  14. {   We carry out the command indicated by mResult.}
  15. {   If it was Quit, we return true, else false.  Since the menu was}
  16. {   highlighted by MenuSelect, we must finish by unhighlighting it}
  17. {   to indicate we're done.}
  18.  
  19.     function DoCommand (mresult: Longint): Boolean;
  20.         var
  21.             refnum: LongInt;
  22.             themenu, theitem: LongInt;
  23.             name: Str255;
  24.             saveport: GrafPtr;        (* for saving current port in when opening a desk accessory *)
  25.             astr: StringHandle;        (* Handle for a utility string *)
  26.             returns: Boolean;
  27.  
  28.     begin
  29.         returns := false;        (* assume Quit not selected *)
  30.         themenu := HiWord(mresult);    (* get the menu selected *)
  31.         theitem := LoWord(mresult);    (* ... and the Item of that menu *)
  32.         case (themenu) of
  33.             0: 
  34.                 ;        (* user made no selection; do nothing *)
  35.  
  36.             applemenu: 
  37.  
  38.                 if (theitem = 1) then
  39.                     begin    (* get string, and tell about Skel *)
  40.  
  41. (* }
  42. {  It's important not to pass Report a de-referenced}
  43. {  Handle; if Report were in another segment, loading}
  44. {  it could cause a memory compaction; the de-referenced}
  45. {  Handle could become invalid.  Watch out for this}
  46. {  and similar nasties everywhere in your program.}
  47. {  See the Memory Manager and the Segment Loader.}
  48. {*)
  49.                         astr := GetString(aboutskelid);
  50.  
  51.                         Report(astr);
  52.                     end
  53.                 else
  54.                     begin        (* run a desk accessory; make sure port is preserved *)
  55.                         GetPort(saveport);
  56.                         GetItem(mymenus[applemenu], theitem, name);    (* get name *)
  57.                         refnum := OpenDeskAcc(name);(* run the desk accessory *)
  58.                         SetPort(saveport);
  59.                     end;
  60.  
  61.             filemenu: 
  62.                 case (theitem) of
  63.                     irattle:     (* Rattle *)
  64.                         begin
  65.                             astr := GetString(rattleid);
  66.                             Report(astr);
  67.                         end;
  68.                     ifrighten: (* Frighten *)
  69.                         begin
  70.                             astr := GetString(frightenid);
  71.                             Report(astr);
  72.                         end;
  73.                     iquit: 
  74.                         returns := true;(* Quit *)
  75.  
  76.                 end;            (* fileMenu case *)
  77.  
  78.         end;                (* menu case *)
  79.  
  80.         HiliteMenu(0);    (* turn off hilighting on the menu just used *)
  81.         DoCommand := returns;
  82.     end;                    (* DoCommand *)
  83.  
  84. end.