home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 8 / FreshFishVol8-CD1.bin / useful / dev / c / rkrm / workbench / appmenuitem.c < prev    next >
C/C++ Source or Header  |  1992-09-03  |  5KB  |  118 lines

  1. ;/* appmenuitem.c - Compiled under SAS C 5.10 with:
  2. lc -L -j73 appmenuitem.c
  3. quit
  4. */
  5.  
  6. /* Requires Kickstart version 37 or later.  Works from the Shell (CLI) only */
  7.  
  8. /*
  9. Copyright (c) 1992 Commodore-Amiga, Inc.
  10.  
  11. This example is provided in electronic form by Commodore-Amiga, Inc. for
  12. use with the "Amiga ROM Kernel Reference Manual: Libraries", 3rd Edition,
  13. published by Addison-Wesley (ISBN 0-201-56774-1).
  14.  
  15. The "Amiga ROM Kernel Reference Manual: Libraries" contains additional
  16. information on the correct usage of the techniques and operating system
  17. functions presented in these examples.  The source and executable code
  18. of these examples may only be distributed in free electronic form, via
  19. bulletin board or as part of a fully non-commercial and freely
  20. redistributable diskette.  Both the source and executable code (including
  21. comments) must be included, without modification, in any copy.  This
  22. example may not be published in printed form or distributed with any
  23. commercial product.  However, the programming techniques and support
  24. routines set forth in these examples may be used in the development
  25. of original executable software products for Commodore Amiga computers.
  26.  
  27. All other rights reserved.
  28.  
  29. This example is provided "as-is" and is subject to change; no
  30. warranties are made.  All use is at your own risk. No liability or
  31. responsibility is assumed.
  32. */
  33.  
  34. #include <exec/types.h>          /* Need this for the Amiga variable types  */
  35. #include <workbench/workbench.h> /* This has DiskObject and AppIcon structs */
  36. #include <workbench/startup.h>   /* This has WBStartup and WBArg structs    */
  37. #include <exec/libraries.h>
  38. #include <dos/dostags.h>
  39. #include <stdio.h>
  40. #include <clib/dos_protos.h>
  41. #include <clib/exec_protos.h>    /* Exec message, port and library functions*/
  42. #include <clib/wb_protos.h>      /* AppMenuItem function protos             */
  43.  
  44. #ifdef LATTICE
  45. int CXBRK(void) { return(0); }   /* Disable Lattice CTRL/C handling */
  46. int chkabort(void) { return(0); }/* really */
  47. #endif
  48.  
  49. extern struct Library *SysBase;
  50. struct Library *WorkbenchBase;
  51.  
  52. void main(int argc, char **argv)
  53. {
  54. struct MsgPort      *myport=NULL;
  55. struct AppMenuItem *appitem=NULL;
  56. struct AppMessage   *appmsg=NULL;
  57. LONG result, x, count=0L;
  58. BOOL success=0L;
  59. BPTR file;
  60.  
  61. if (WorkbenchBase = OpenLibrary("workbench.library",37))
  62.   {
  63.   /* The CreateMsgPort() function is in Exec version 37 and later only */
  64.   if(myport = CreateMsgPort())
  65.     {
  66.     /* Add our own AppMenuItem to the Workbench Tools Menu */
  67.     appitem=AddAppMenuItemA(0L,                   /* Our ID# for item */
  68.                     (ULONG)"SYS:Utilities/More",  /* Our UserData     */
  69.                            "Browse Files",        /* MenuItem Text    */
  70.                             myport,NULL);         /* MsgPort, no tags */
  71.     if(appitem)
  72.       {
  73.       printf("Select Workbench Tools demo menuitem 'Browse Files'\n");
  74.  
  75.       /* For this example, we allow the AppMenuItem to be selected */
  76.       /* only once, then we remove it and exit                     */
  77.       WaitPort(myport);
  78.       while((appmsg=(struct AppMessage *)GetMsg(myport)) && (count<1))
  79.         {
  80.         /* Handle messages from the AppMenuItem - we have only one  */
  81.         /* item so we don't have to check its appmsg->am_ID number. */
  82.         /* We'll System() the command string that we passed as      */
  83.         /* userdata when we added the menu item.                    */
  84.         /* We find our userdata pointer in appmsg->am_UserData      */
  85.  
  86.         printf("User picked AppMenuItem with %ld icons selected\n",
  87.                                                 appmsg->am_NumArgs);
  88.         for(x=0;x<appmsg->am_NumArgs;x++)
  89.            printf("  #%ld name='%s'\n",x+1,appmsg->am_ArgList[x].wa_Name);
  90.  
  91.         count++;
  92.         if( file=Open("CON:0/40/640/150/AppMenu Example/auto/close/wait",
  93.                          MODE_OLDFILE)  )     /* for any stdio output */
  94.           {
  95.           result=SystemTags((UBYTE *)appmsg->am_UserData,SYS_Input,file,
  96.                                                          SYS_Output,NULL,
  97.                                                          SYS_Asynch,TRUE,
  98.                                                          TAG_DONE);
  99.           /* If Asynch System() itself fails, we must close file */
  100.           if(result == -1) Close(file);
  101.           }
  102.         ReplyMsg((struct Message *)appmsg);
  103.         }
  104.       success=RemoveAppMenuItem(appitem);
  105.       }
  106.  
  107.     /* Clear away any messages that arrived at the last moment */
  108.     /* and let Workbench know we're done with the messages     */
  109.     while(appmsg=(struct AppMessage *)GetMsg(myport))
  110.       {
  111.       ReplyMsg((struct Message *)appmsg);
  112.       }
  113.     DeleteMsgPort(myport);
  114.     }
  115.   CloseLibrary(WorkbenchBase);
  116.   }
  117. }
  118.