home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / sys / amiga / programm / 13055 < prev    next >
Encoding:
Text File  |  1992-09-03  |  5.2 KB  |  152 lines

  1. Path: sparky!uunet!wupost!waikato.ac.nz!aukuni.ac.nz!cs18.cs.aukuni.ac.nz!cste3
  2. Newsgroups: comp.sys.amiga.programmer
  3. Subject: Menus and Gadgets!!!
  4. Message-ID: <1992Sep3.225333.21017@cs.aukuni.ac.nz>
  5. From: cste3@cs.aukuni.ac.nz (Christopher Paul    Stevens        )
  6. Date: Thu, 3 Sep 1992 22:53:33 GMT
  7. Organization: Computer Science Dept. University of Auckland
  8. Lines: 142
  9.  
  10. I've been programming C now for 6 days and am having difficulty in getting
  11. gadgets and menus to work...
  12.  
  13. The code which follows works fine without all the gadget code in at the
  14. beginning of Open_Windows() but as soon as I put the gadget code in
  15. my program hangs at the LayoutMenus() call in the DefineMenus().
  16.  
  17. Can anybody tell me what I have done wrong ?
  18.  
  19. The code dosn't actually hang a ssuch it just sits there for about 20 secs
  20. and then the menus appear, somtimes when I select a item that item will
  21. work but other times when I select an item the whole system hangs!!
  22.  
  23. All that I can think of is that I am some how changing the VisualInfo structure
  24. which is stuffing up LayoutMenus ????
  25.  
  26. Also if any one could give me some example code of how to set up Gadgets using
  27. 2.0 calls I would greatly appreciate it.
  28.  
  29. AdvaTHANKSnce.
  30.  
  31. -----------Source Code Follows-----------
  32.  
  33. struct TextAttr fnt_Gadget = {
  34.    "topaz.font",
  35.    TOPAZ_EIGHTY,
  36.    FS_NORMAL,
  37.    FPF_ROMFONT
  38. };
  39.  
  40. APTR vi = NULL;         /* Visual Info *Structure */
  41.  
  42. struct NewGadget firstGadget = {
  43.     100,100,50,50,    /* Size */
  44.     "Test",           /* Name */
  45.     &fnt_Gadget,      /* font */
  46.     0,                /* ID   */
  47.     PLACETEXT_IN,     /* Flags */
  48.     NULL,             /* Visual Info */
  49.     0                 /* User data */
  50. };
  51.  
  52. /*=======================================================================*/
  53. void main(void)
  54. {
  55.    OpenLibraries();
  56.    Open_Screen();
  57.    vi = GetVisualInfo(MyScreen,TAG_DONE);
  58.    Open_Windows();
  59.    Define_Menus();
  60.    [....]
  61. }  /* Main */
  62. /*=======================================================================*/
  63. void Define_Menus(void)
  64. /* Set up all menus for use throughout */
  65. {
  66.  
  67.    /*  ULONG errorcode = NULL; */
  68.    BOOL suc;
  69.  
  70.    if((menu = CreateMenus(nm,
  71.       GTMN_FrontPen, 0,
  72.    /* GTMN_SecondaryError, &errorcode,*/      /* Does not seem to be */
  73.       TAG_DONE))==NULL) {                     /* implemented ????    */
  74.      Abort("Error opening menus");             /* in SASC 5.10        */
  75.       }
  76.  
  77.    suc = LayoutMenus(menu,vi,TAG_DONE); /* <-- this is the line */
  78.  
  79.    if (suc == FALSE) {
  80.      Abort("Menu Layout failed");
  81.    }
  82.  
  83.    ClearMenuStrip(Wind0);     /* Set the menus to the windows */
  84.    SetMenuStrip(Wind0,menu);
  85.    ClearMenuStrip(Wind1);
  86.    SetMenuStrip(Wind1,menu);
  87. }  /* Define_Menus */
  88. /*=======================================================================*/
  89. void Open_Windows(void)
  90. /* Open all windows at specified locations */
  91. {
  92.    SHORT udh = 50; /* Upper display window height */
  93.    SHORT mbh = (MyScreen->BarHeight)+1; /* menuBarHeight */
  94.    SHORT cdt = udh + mbh; /* Centre display top */
  95.    SHORT cdh = MyScreen->Height-cdt; /* Centre display height */
  96.  
  97.    /* Open Central display window with a gadget list */              /**/
  98.                                      /**/
  99.    struct Gadget *gad, *glist = NULL;                                /**/
  100.                                      /**/
  101.    firstGadget.ng_VisualInfo = vi;                                   /**/
  102.                                      /**/
  103.    gad = CreateContext(&glist);                                      /**/
  104.                                      /**/
  105.    if (gad == NULL) {                                                /**/
  106.       Abort("Create context failed!!!!");                            /**/
  107.    }                                                                 /**/
  108.                                      /**/
  109.    gad = CreateGadget(BUTTON_KIND,glist,&firstGadget,TAG_DONE);      /**/
  110.                                      /**/
  111.    if (gad == NULL) {                                                /**/
  112.       Abort("Create Gadget failed");                                 /**/
  113.    }                                                                 /**/
  114.  
  115.    if((Wind0=OpenWindowTags(NULL,            /* When I remove all lines */
  116.       WA_Left,          0,                      /* marked /**/
  117.       WA_Top,           cdt,                    /* I get fine menus that   */
  118.       WA_Width,         640,                    /* work with no delay      */
  119.       WA_Height,        cdh,                    /* with the marked code it */
  120.       WA_DetailPen,     0,                      /* stuffs it every time !! */
  121.       WA_BlockPen,      1,
  122.       WA_IDCMP,         MENUPICK,
  123.       WA_CustomScreen,  MyScreen,
  124.       WA_Activate,      TRUE,
  125.       WA_Backdrop,      TRUE,
  126.       WA_Gadgets,       glist,                                          /**/
  127.       TAG_END))==NULL) {
  128.      Abort("Error opening display window!!!");
  129.       }
  130.  
  131.  /* Open Upper display window */
  132.     if((Wind1=OpenWindowTags(NULL,
  133.        WA_Left,          0,
  134.        WA_Top,           mbh,
  135.        WA_Width,         640,
  136.        WA_Height,        udh,
  137.        WA_DetailPen,     0,
  138.        WA_BlockPen,      1,
  139.        WA_IDCMP,         NULL,
  140.        WA_CustomScreen,  MyScreen,
  141.        WA_Activate,      FALSE,
  142.        WA_Backdrop,      TRUE,
  143.        WA_Borderless,    TRUE,
  144.        TAG_END))==NULL) {
  145.       Abort("Error opening upper display window!!!");
  146.        }
  147.  
  148. }  /* Open_Windows */
  149. /*=======================================================================*/
  150.  
  151. --------End of Code--------
  152.