home *** CD-ROM | disk | FTP | other *** search
/ Aminet 18 / aminetcdnumber181997.iso / Aminet / dev / gui / pmdev.lha / PopupMenuDeveloper / Demos / PlainMenu.c next >
Encoding:
C/C++ Source or Header  |  1997-02-26  |  2.2 KB  |  80 lines

  1. //
  2. // $VER: PlainMenu.c 1.0 (27.2.97)
  3. //
  4. // Popup Menu example program
  5. //
  6. // ©1996-1997 Henrik Isaksson
  7. // All Rights Reserved.
  8. //
  9. // Run and click the mouse in the window!
  10. //
  11.  
  12. #include <intuition/intuition.h>
  13.  
  14. #include <clib/intuition_protos.h>
  15. #include <clib/exec_protos.h>
  16. #include <clib/alib_protos.h>
  17.  
  18. #include <string.h>
  19. #include <stdio.h>
  20. #include <stdlib.h>
  21.  
  22. #include <libraries/pm.h>
  23. #include <proto/pm.h>
  24.  
  25. struct IntuitionBase    *IntuitionBase;
  26. struct GfxBase        *GfxBase;
  27. struct PopupMenuBase    *PopupMenuBase;
  28.  
  29. struct Window *w;    // This window is only needed to find out when and where the menu should appear.
  30.             // The font in this window's rastport will be used for the menu.
  31.  
  32. void main()
  33. {
  34.     BOOL r=TRUE;
  35.     struct IntuiMessage *im,imsg;
  36.     struct PopupMenu *p;
  37.  
  38.     PopupMenuBase=(struct PopupMenuBase *)OpenLibrary(POPUPMENU_NAME,POPUPMENU_VERSION);            // Open the library
  39.     if(PopupMenuBase) {
  40.         IntuitionBase=(struct IntuitionBase *)PopupMenuBase->pmb_IntuitionBase;    // We let popupmenu.library open the libraries we need
  41.         GfxBase=(struct GfxBase *)PopupMenuBase->pmb_GfxBase;            // They remain valid until the library is closed!
  42.  
  43.         p=Menu("Plain Simple Menu!"),    // Create a very simple menu...
  44.             Item("Quit"),    PM_UserData,    5,    End,
  45.             End;
  46.  
  47.         if(p) {
  48.             w=OpenWindowTags(NULL,    WA_IDCMP,    IDCMP_CLOSEWINDOW|IDCMP_MOUSEBUTTONS,    // Open a little window
  49.                     WA_RMBTrap,    TRUE,
  50.                     WA_DragBar,    TRUE,
  51.                     WA_Width,    150,
  52.                     WA_Height,    100,
  53.                     WA_Title,    "PlainMenu",
  54.                     WA_CloseGadget,    TRUE,
  55.                     TAG_DONE);
  56.             if(w) {
  57.                 while(r) {
  58.                     WaitPort(w->UserPort);                        // Wait for a message
  59.                     while((im=(struct IntuiMessage *)GetMsg(w->UserPort))) {    // Get the message
  60.                         CopyMem(im,&imsg,sizeof(struct IntuiMessage));        // Copy the contents of it
  61.                         ReplyMsg((struct Message *)im);                // Reply the message
  62.  
  63.                         switch(imsg.Class) {
  64.                             case IDCMP_CLOSEWINDOW: r=FALSE; break;
  65.                             case IDCMP_MOUSEBUTTONS:            // The user has hit a mousebutton - time to open the menu!
  66.                                 r=(BOOL)((ULONG)(OpenPopupMenu(w,
  67.                                         PM_Menu,        p,
  68.                                         TAG_DONE))-5);
  69.                             break;
  70.                         }
  71.                     }
  72.                 }
  73.                 CloseWindow(w);
  74.             } else printf("Window error!\n");
  75.             FreePopupMenu(p);
  76.         } else printf("Menu error!\n");
  77.         CloseLibrary((struct Library *)PopupMenuBase);
  78.     }
  79. }
  80.