home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Utilities / Lightspeed C SKEL fldr / Skel docommand.c < prev    next >
Encoding:
C/C++ Source or Header  |  1986-06-17  |  2.3 KB  |  94 lines  |  [TEXT/KAHL]

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