home *** CD-ROM | disk | FTP | other *** search
/ Otherware / Otherware_1_SB_Development.iso / mac / developm / source / appkill.cpt / ak_ppc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-12-21  |  2.7 KB  |  109 lines

  1. /*********
  2. ** ak_ppc.c
  3. **
  4. ** contains code for ppc functions of the program
  5. ** and code for launching other apps.
  6. ***********/
  7.  
  8. #ifndef THINK_C
  9.  /* include the <standard mac headers> */
  10. #include <AppleEvents.h>
  11. #include <Desk.h>
  12. #include <Dialogs.h>
  13. #include <Events.h>
  14. #include <Fonts.h>
  15. #include <GestaltEqu.h>
  16. #include <Menus.h>
  17. #include <OSEvents.h>
  18. #include <QuickDraw.h>
  19. #include <THINK.h>
  20. #include <ToolUtils.h>
  21. #include <Types.h>
  22. #include <Windows.h>
  23. #else
  24.  #include "ak_headers"
  25. #endif
  26. #include <StandardFile.h>
  27. #include <string.h>
  28. #include "ak_ppc.h"
  29.  
  30. void DoAlert(Str255, Str255, Str255, Str255); /* appkiller.c */
  31.  
  32. void MyPPCInit(void)
  33. {
  34.     OSErr err;
  35.     err = PPCInit();
  36. } /* MyPPCInit() */
  37.  
  38.  
  39. void PostWithPPCBrowser(void)        /* p. 5-25, IM-6 */
  40. {
  41.     EventRecord    myHLEvent;
  42.     OSErr    myErr;
  43.     PortInfoRec    myPortInfo;
  44.     TargetID    myTarget;
  45.     
  46.     myErr = PPCBrowser("\pSelect an Application to Stop", "\pApplication", FALSE,
  47.         &myTarget.location, &myPortInfo, NULL, "\p");
  48.     if (myErr == noErr) {
  49.         /* copy portname into myTarget.name */
  50.         void *tmp;
  51.         /*DebugStr("Before memcpy()"); */
  52.         tmp = memcpy( &myTarget.name, &myPortInfo.name,
  53.                  sizeof(myPortInfo.name));
  54.         /*DebugStr("After memcpy()"); */
  55.         myHLEvent.what = kHighLevelEvent;
  56.         myHLEvent.message = (long)kCoreEventClass;
  57.         *(long*)(&myHLEvent.where) = (long)kAEQuitApplication;
  58.         
  59.         /*DebugStr("\pbefore PostHighLevelEvent()."); */
  60.         myErr = PostHighLevelEvent(&myHLEvent, (long)&myTarget, 0, NULL,0,
  61.                         receiverIDisTargetID);
  62.         /*DebugStr("\pafter PostHighLevelEvent()."); */
  63.         } /* if */
  64. } /* PostWithPPCBrowser() */
  65.  
  66.  
  67. void DoLaunch(void)
  68. {
  69.     // PLAN OF ATTACK:
  70.     //
  71.     // 1) pop up standard file open box; select any file of type APPL
  72.     // 2) SubLaunch the application, while keeping ourselves alive.
  73.     // 3) Cleanup(?) and exit.
  74.  
  75.     StandardFileReply theSFR;
  76.     SFTypeList    theTypes;
  77.     OSErr    err;
  78.  
  79.     theTypes[0] = 'APPL';    /* to launch any application */
  80.     theTypes[1] = 'FNDR';    /* to launch the finder again */
  81.     
  82.     StandardGetFile(NULL, 2, theTypes, &theSFR);        // 1)
  83.     
  84.     if ( theSFR.sfGood == TRUE) { 
  85.         LaunchParamBlockRec    launchParams;
  86.         ProcessSerialNumber    psn;
  87.         long psize, msize,asize; /* preferred, min, available sizes */
  88.         
  89.         launchParams.launchBlockID = extendedBlock;
  90.         launchParams.launchEPBLength = extendedBlockLen;
  91.         launchParams.launchFileFlags = 0;
  92.         launchParams.launchControlFlags = launchContinue +
  93.                                           launchNoFileFlags;
  94.         launchParams.launchAppSpec = &(theSFR.sfFile);
  95.         launchParams.launchAppParameters = NULL;
  96.         
  97.         err = LaunchApplication(&launchParams);            // 2)
  98.         
  99.         if (err != noErr) DoAlert("\pSorry, an error occured and",
  100.             "\pSystem 7 choked.", "\p", "\p");
  101.     } /* if user selected file... */
  102.     
  103.     return;                                                // 3)
  104. } /* DoLaunch() */
  105.  
  106.  
  107.  
  108.  
  109.