home *** CD-ROM | disk | FTP | other *** search
/ Enigma Amiga Life 109 / EnigmaAmiga109CD.iso / software / sviluppo / popupmenudeveloper / c / demos / simplemenu.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-11-19  |  2.5 KB  |  105 lines

  1. //
  2. // $VER: SimpleMenu.c 3.0 (23.08.99)
  3. //
  4. // Popup Menu example program
  5. //
  6. // ©1996-1997 Henrik Isaksson
  7. // All Rights Reserved.
  8. //
  9. // This simple example shows how to open a small menu.
  10. // New since 'before' is that it is even simpler now. =)
  11. //
  12.  
  13. #include <intuition/intuition.h>
  14. #include <proto/intuition.h>
  15. #include <proto/exec.h>
  16. #include <clib/alib_protos.h>
  17. #include <stdio.h>
  18.  
  19. #include <libraries/pm.h>
  20. #include <proto/pm.h>
  21.  
  22. struct PopupMenuBase    *PopupMenuBase;
  23.  
  24. struct Window *OpenMyWindow(void);
  25.  
  26. void main()
  27. {
  28.     BOOL            r=TRUE;    /* Keep running until this gets FALSE */
  29.     struct Window        *w;    /* One window. */
  30.     struct IntuiMessage    *im,imsg;
  31.     struct PopupMenu    *p;    /* One menu. */
  32.  
  33.     if(OPEN_PM_LIB) {    /* A little macro from libraries/pm.h. */
  34.         IntuitionBase=(struct IntuitionBase *)PopupMenuBase->pmb_IntuitionBase;
  35.  
  36.         /* Create a PopupMenu using the macros defined in pm.h: */
  37.  
  38.         p=PMMenu("Small Menu"),
  39.             PMItem("Item1"),        PMEnd,
  40.             PMItem("Item2"),        PMEnd,
  41.             PMBar,                PMEnd,
  42.             PMItem("Quit"),    PM_UserData, 5,    PMEnd,
  43.           PMEnd;
  44.  
  45.         if(p) {
  46.             w=OpenMyWindow();    /* Open a little window. (declared below) */
  47.             if(w) {
  48.  
  49.                 /* A standard event loop follows: */
  50.                 while(r) {
  51.                     WaitPort(w->UserPort);
  52.                     while((im=(struct IntuiMessage *)GetMsg(w->UserPort))) {
  53.                         CopyMem(im,&imsg,sizeof(struct IntuiMessage));
  54.                         ReplyMsg((struct Message *)im);
  55.  
  56.                         switch(imsg.Class) {
  57.                             case IDCMP_CLOSEWINDOW: r=FALSE; break;
  58.                             case IDCMP_MOUSEBUTTONS:
  59.                                 r=PM_OpenPopupMenu(w,
  60.                                     PM_Menu,    p,
  61.                                     TAG_DONE);
  62.  
  63.                                 /* If r is 5, we want to quit: */
  64.                                 
  65.                                 if(r==5) r=0;
  66.                                 else r=1;
  67.                                 
  68.                                 /* Maybe a bit confusing... Well, PM_OpenPopupMenu */
  69.                                 /* returns 0 if no item was select, so we can't just */
  70.                                 /* assign the return value to r. */
  71.                                 /* There is another (better?) way of handling the input; */
  72.                                 /* the PM_MenuHandler tag. */
  73.  
  74.                                 break;
  75.                         }
  76.                     }
  77.                 }
  78.                 CloseWindow(w);
  79.             } else printf("Window error!\n");
  80.             PM_FreePopupMenu(p);
  81.         } else printf("Menu error!\n");
  82.  
  83.         CLOSE_PM_LIB;
  84.     }
  85. }
  86.  
  87. struct Window *OpenMyWindow(void)
  88. {
  89.  
  90.     /* Open the window. I'm keeping this code here just to make the other */
  91.     /* code more readable. */
  92.  
  93.     return OpenWindowTags(NULL,
  94.             WA_IDCMP,    IDCMP_CLOSEWINDOW|IDCMP_MOUSEBUTTONS,    // Open a little window
  95.             WA_RMBTrap,    TRUE,
  96.             WA_DragBar,    TRUE,
  97.             WA_Width,    150,
  98.             WA_Height,    100,
  99.             WA_Left,    150,
  100.             WA_Top,        0,
  101.             WA_Title,    "SimpleMenu",
  102.             WA_CloseGadget,    TRUE,
  103.         TAG_DONE);
  104. }
  105.