home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD v1.2 / amidev_cd_12.iso / reference / amiga_mail_vol2 / iv-59 / appmenu.c < prev    next >
C/C++ Source or Header  |  1996-01-30  |  6KB  |  163 lines

  1. ;/* AppMenu.c - Execute me to compile me with SAS/C 6.56
  2. sc NMINC STRMERGE NOSTKCHK NODEBUG DATA=NEAR IGNORE=73 AppMenu.c
  3. slink FROM LIB:c.o,AppMenu.o TO AppMenu LIBRARY LIB:sc.lib,LIB:Amiga.lib
  4. quit
  5. */
  6. /*
  7. Copyright (c) 1991 Commodore-Amiga, Inc.
  8.  
  9. This example is provided in electronic form by Commodore-Amiga,
  10. Inc. for use with the Amiga Mail Volume II technical publication.
  11. Amiga Mail Volume II contains additional information on the correct
  12. usage of the techniques and operating system functions presented in
  13. these examples.  The source and executable code of these examples may
  14. only be distributed in free electronic form, via bulletin board or
  15. as part of a fully non-commercial and freely redistributable
  16. diskette.  Both the source and executable code (including comments)
  17. must be included, without modification, in any copy.  This example
  18. may not be published in printed form or distributed with any
  19. commercial product. However, the programming techniques and support
  20. routines set forth in these examples may be used in the development
  21. of original executable software products for Commodore Amiga
  22. computers.
  23.  
  24. All other rights reserved.
  25.  
  26. This example is provided "as-is" and is subject to change; no
  27. warranties are made.  All use is at your own risk. No liability or
  28. responsibility is assumed.
  29. */
  30.  
  31. #include <intuition/intuition.h>
  32. #include <exec/memory.h>
  33. #include <workbench/startup.h>
  34. #include <workbench/workbench.h>
  35.  
  36. #ifdef LATTICE
  37.  
  38. /* disable SAS/C CTRL-C handing */
  39. int
  40. CXBRK(void)
  41. {
  42.     return (0);
  43. }
  44. int
  45. chkabort(void)
  46. {
  47.     return (0);
  48. }
  49.  
  50. #include <clib/exec_protos.h>
  51. #include <clib/intuition_protos.h>
  52. #include <clib/icon_protos.h>
  53. #include <clib/wb_protos.h>
  54. #include <clib/dos_protos.h>
  55. #include <clib/alib_stdio_protos.h>
  56. #endif
  57.  
  58. struct IntuitionBase *IntuitionBase;
  59. struct WorkbenchBase *WorkbenchBase;
  60.  
  61. void            main(void);
  62.  
  63. void
  64. main(void)
  65. {
  66.     struct MsgPort *msgport;
  67.     struct Window  *window;
  68.     struct AppMenuItem *appmenuitem;
  69.     struct IntuiMessage *imsg;
  70.     struct AppMessage *appmsg;
  71.     struct WBArg   *argptr;
  72.  
  73.     ULONG           id = 1, userdata = 0, i;
  74.     BOOL            ABORT = FALSE;
  75.  
  76.     /* Open Intuition.library & Workbench.library. Fail silently if < 36 */
  77.     if (IntuitionBase = OpenLibrary("intuition.library", 36))
  78.     {
  79.         if (WorkbenchBase = OpenLibrary("workbench.library", 36))
  80.         {
  81.             /* Create the message port to which Workbench can send messages */
  82.             if (msgport = CreateMsgPort())
  83.             {
  84.                 if (window =
  85.                     OpenWindowTags(NULL, WA_Left, 0, WA_Top, 1, WA_Width, 160,
  86.                                    WA_Height, 50, WA_IDCMP, CLOSEWINDOW,
  87.                                    WA_Flags, WINDOWCLOSE | WINDOWDRAG,
  88.                                    WA_Title, "AppMenu", TAG_END))
  89.                 {
  90.  
  91.                     /* Use our window to attach an menu item to the Tools menu. */
  92.                     if (appmenuitem = AddAppMenuItem(id, userdata,
  93.                                                      "AppMenuItem", msgport, NULL))
  94.                     {
  95.  
  96.                         do
  97.                         {
  98.                             /* Wait for either a CLOSEWINDOW or an AppMessage */
  99.                             Wait(1 << window->UserPort->mp_SigBit |
  100.                                  1 << msgport->mp_SigBit);
  101.                             while (imsg = (struct IntuiMessage *)
  102.                                 GetMsg(window->UserPort))
  103.                             {
  104.                                 if (imsg->Class = CLOSEWINDOW)
  105.                                     ABORT = TRUE;
  106.                                 ReplyMsg((struct Message *) imsg);
  107.                             }
  108.                             while (appmsg = (struct AppMessage *) GetMsg(msgport))
  109.                             {
  110.  
  111.                                 /*
  112.                                  * The AppMessage type will be MTYPE_APPMENU,
  113.                                  * the ID & userdata are what we supplied when
  114.                                  * the window was designed as an AppWindow.
  115.                                  * Since there are no Workbench arguments for
  116.                                  * menu operations, NumArgs will always be 0.
  117.                                  */
  118.                                 printf(
  119.                        "am: appmsg=%lx, Type=%ld, ID=%ld, UserData=%ld, NumArgs=%ld\n",
  120.                                        appmsg, appmsg->am_Type, appmsg->am_ID,
  121.                                        appmsg->am_UserData, appmsg->am_NumArgs);
  122.                                 argptr = appmsg->am_ArgList;
  123.                                 for (i = 0; i < appmsg->am_NumArgs; i++)
  124.                                 {
  125.  
  126.                                     /*
  127.                                      * The lock will be on the directory in
  128.                                      * which the file resides. If there is no
  129.                                      * filename, either a volume or window was
  130.                                      * dropped on us.
  131.                                      */
  132.                                     printf("\targ(%ld): Name='%s', Lock=%lx\n", i,
  133.                                            argptr->wa_Name, argptr->wa_Lock);
  134.                                     /* Point to next argument */
  135.                                     argptr++;
  136.                                 }
  137.  
  138.                                 ReplyMsg((struct Message *) appmsg);
  139.                             }
  140.                         } while (ABORT == FALSE);
  141.                         /* remove the AppMenu and close down */
  142.                         RemoveAppMenuItem(appmenuitem);
  143.                     }
  144.                     else
  145.                         printf("Couldn't add AppMenuItem\n");
  146.                     CloseWindow(window);
  147.                 }
  148.                 else
  149.                     printf("Couldn't open window\n");
  150.                 DeleteMsgPort(msgport);
  151.             }
  152.             else
  153.                 printf("Coulnd't create messageport\n");
  154.             CloseLibrary(WorkbenchBase);
  155.         }
  156.         else
  157.             printf("Couldn't open workbench.library\n");
  158.         CloseLibrary(IntuitionBase);
  159.     }
  160.     else
  161.         printf("Couldn't open intuition.library\n");
  162. }
  163.