home *** CD-ROM | disk | FTP | other *** search
/ Aminet 10 / aminetcdnumber101996.iso / Aminet / dev / gui / menubuilder.lha / TestMenus.c < prev   
Encoding:
C/C++ Source or Header  |  1995-12-28  |  2.4 KB  |  148 lines

  1. //
  2. // Open a window, and use the menus defined in the file "Ram:TestMenus.h"
  3. //
  4.  
  5.  
  6. #include <intuition/intuition.h>
  7. #include <clib/intuition_protos.h>
  8.  
  9. #include <exec/exec.h>
  10. #include <clib/exec_protos.h>
  11.  
  12. #include <clib/gadtools_protos.h>
  13.  
  14. #include <stdio.h>
  15.  
  16.  
  17. #include "ram:TestMenus.h"
  18.  
  19.  
  20.  
  21. void open_window(void);
  22. char handle_input(void);
  23. void close_window(void);
  24.  
  25.  
  26. struct Library *IntuitionBase,*GadToolsBase;
  27. struct Screen *TestScreen;
  28. struct Window *TestWindow;
  29. struct Menu *MenuStrip;
  30. unsigned long *VisInfo;
  31.  
  32.  
  33.  
  34. int main()
  35. {
  36.     IntuitionBase = OpenLibrary("intuition.library",36);
  37.     if (IntuitionBase == NULL)
  38.     {
  39.         printf("Sorry, I need v36 in order to run.\n");
  40.         return(0);
  41.     }
  42.     
  43.     GadToolsBase = OpenLibrary("gadtools.library",36);
  44.     if (GadToolsBase == NULL)
  45.     {
  46.         printf("Unable to open gadtools.library v36.\n");
  47.         CloseLibrary(IntuitionBase);
  48.         return(0);
  49.     }
  50.  
  51.  
  52.     /* Lock the workbench screen so we can get VisualInfo */
  53.     TestScreen = LockPubScreen(NULL);
  54.  
  55.     /* Get VisualInfo from our screen */
  56.     VisInfo = GetVisualInfo(TestScreen,TAG_END);
  57.  
  58.     open_window();
  59.  
  60.  
  61.  
  62.     /* Use the 'struct NewMenu mbld[]' menu structure from Ram:MenuTest.h */
  63.     /* to define the menus for the window. */
  64.     MenuStrip=CreateMenus(mbld,TAG_END);
  65.     LayoutMenus(MenuStrip,VisInfo,TAG_END);
  66.     SetMenuStrip(TestWindow,MenuStrip);
  67.  
  68.     /* Unlock the screen */
  69.     UnlockPubScreen(NULL,TestScreen);
  70.  
  71.  
  72.     /* Wait for user to close the window */
  73.     handle_input();
  74.  
  75.  
  76.     /* Clean up and exit */
  77.     ClearMenuStrip(TestWindow);
  78.     close_window();
  79.     FreeMenus(MenuStrip);
  80.     FreeVisualInfo(VisInfo);
  81.  
  82.     CloseLibrary(IntuitionBase);
  83.     CloseLibrary(GadToolsBase);
  84.  
  85.     return(0);
  86. }
  87.  
  88.  
  89.  
  90. void open_window()
  91. {
  92.     TestWindow=OpenWindowTags(0,
  93.                         WA_Left,100,
  94.                         WA_Top,50,
  95.                         WA_Width,440,
  96.                         WA_Height,100,
  97.                         WA_CloseGadget,TRUE,
  98.                         WA_SizeGadget,TRUE,
  99.                         WA_DragBar,TRUE,
  100.                         WA_DepthGadget,TRUE,
  101.                         WA_Activate,TRUE,
  102.                         WA_Title,"MenuBuilder example",
  103.                         WA_IDCMP,IDCMP_CLOSEWINDOW,
  104.                         TAG_DONE);
  105. }
  106.  
  107.  
  108. void close_window()
  109. {
  110.     CloseWindow(TestWindow);
  111. }
  112.  
  113.  
  114.  
  115.  
  116.  
  117.  
  118.  
  119. char handle_input()
  120. {
  121.     struct IntuiMessage *message;
  122.     unsigned long signals,class,code;
  123.     int finished = FALSE;
  124.  
  125.  
  126.     do
  127.     {
  128.         signals=Wait(1L<<TestWindow->UserPort->mp_SigBit);    /* wait for msg */
  129.  
  130.         message=GetMsg(TestWindow->UserPort);
  131.         class=message->Class;
  132.         code=message->Code;
  133.         ReplyMsg((struct Message*)message);
  134.  
  135.         switch (class)
  136.         {
  137.             case IDCMP_CLOSEWINDOW:
  138.                 finished = TRUE;
  139.                 break;
  140.             default:
  141.                 break;
  142.         }
  143.     }
  144.     while (finished == FALSE);
  145. }
  146.  
  147.  
  148.