home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / sys / amiga / programmer / 660 < prev    next >
Encoding:
Text File  |  1996-08-05  |  5.0 KB  |  146 lines

  1. Path: cs.uwa.edu.au!jasonb
  2. From: jasonb@cs.uwa.edu.au (Jason S Birch)
  3. Newsgroups: comp.sys.amiga.programmer
  4. Subject: Re: Help me with a basic MUI program PLEASE?
  5. Date: 10 Jan 96 06:01:26 GMT
  6. Organization: The University of Western Australia
  7. Message-ID: <jasonb.821253686@cs.uwa.edu.au>
  8. References: <2440.6581T1279T1051@in.net>
  9. NNTP-Posting-Host: decadence.cs.uwa.oz.au
  10. X-Newsreader: NN version 6.5.0 #3 (NOV)
  11.  
  12. mave@in.net (John J. Maver) writes:
  13. >    Could someone please help me with MUI?  I have started trying to use
  14. >MUIBuilder,and I can't seem to make a good main.c to control the code it
  15. >generates.  I am new to MUI.  All I want to know is how to open the window and
  16. >then when the person hits the close gadget, have the window close.  With my
  17. >existing main.c. the window opens and is open for good!!
  18.  
  19. Here's a main program that works with your files. It's a slight
  20. modification of MUIBuilder/C/Examples/MUIB-Demo.c to make it more
  21. up-to-date:
  22.  
  23. /* Libraries */
  24. #include <libraries/mui.h>
  25.  
  26. /* Note: If you're using SAS/C, you might prefer to change these
  27.    to <proto/...> and use registerized parameters. */
  28.  
  29. /* protos */
  30. #include <clib/muimaster_protos.h>
  31. #include <clib/alib_protos.h>
  32. #include <clib/dos_protos.h>
  33. #include <clib/exec_protos.h>
  34.  
  35. /*  Pragmas  */
  36. #include <pragmas/muimaster_pragmas.h>
  37. #include <pragmas/exec_pragmas.h>
  38.  
  39. /*  Ansi  */
  40. #include <stdlib.h>
  41. #include <stdio.h>
  42.  
  43. /* MUIBuilder */
  44. #include "test.h"
  45.  
  46. struct Library * MUIMasterBase;
  47.  
  48. /* Init function */
  49. static void init( void )
  50. {
  51.         if (!(MUIMasterBase = OpenLibrary(MUIMASTER_NAME,MUIMASTER_VMIN)))
  52.         {
  53.                 printf("Can't Open MUIMaster Library");
  54.                 exit(20);
  55.         }
  56. }
  57.  
  58. /* main function */
  59. main()
  60. {
  61.         struct ObjApp * App = NULL;     /* Application object */
  62.         ULONG   signal;
  63.  
  64.         /* Program initialisation (you need to write it yourself) */
  65.         init();
  66.  
  67.         /* Create Application : generated by MUIBuilder */
  68.         if (App = CreateApp()){
  69.  
  70.             /* Your CreateApp() will already open the window for you. If it 
  71.              * didn't, you'd have:
  72.              *   set(App->WI_label_0, MUIA_Window_Open, TRUE);
  73.              * somewhere here.
  74.              */
  75.  
  76.             /* Set up a notification on the Window's CloseRequest attribute.
  77.              * This attribute is set to TRUE whenever someone clicks on the 
  78.              * close gadget. What we're doing here is telling the window to 
  79.              * call the app's ReturnID method with the value of ReturnID_Quit,
  80.              * which we'll then check for in our main loop, where we call the 
  81.              * NewInput method.
  82.              */
  83.             DoMethod(App->WI_label_0,       /* The window */
  84.                     MUIM_Notify, MUIA_Window_CloseRequest, TRUE,
  85.                     App->App,
  86.                     2,
  87.                     MUIM_Application_ReturnID, MUIV_Application_ReturnID_Quit
  88.             );
  89.             /* Note that this should be the only ReturnID you use. Earlier 
  90.              * examples of MUI programs used ReturnID's for a great deal of 
  91.              * work, creating event loops like typical GadTools programs. 
  92.              * Avoid this. Instead, create custom classes (it's very, very 
  93.              * easy - try to understand PSI.c to learn, along with the 
  94.              * Class1.c, Class2.c and Class3.c demos in 
  95.              * MUI:Developer/C/Examples) and set up notifications between 
  96.              * them. 
  97.              * The main event loop should look similar to the following:
  98.              */
  99.             while (DoMethod(App->App, MUIM_Application_NewInput, &signal) != MUIV_Application_ReturnID_Quit) {
  100.                 if (signal){                /* Wait for a signal */
  101.                     signal = Wait(signal | SIGBREAKF_CTRL_C);
  102.                     if (signal & SIGBREAKF_CTRL_C)
  103.                         break;
  104.                 }
  105.             }
  106.             /* While it's not necessary, you could do a:
  107.              *   set(App->WI_label_0, MUIA_Window_Open, FALSE);
  108.              * here to close the window first.
  109.              */
  110.  
  111.             DisposeApp(App);
  112.         } else
  113.             printf("Failed to create application!\n");
  114.  
  115.         CloseLibrary(MUIMasterBase);
  116.         exit(0);
  117. }
  118.  
  119. >    Is there a good reference for MUI?  Some basic examples, not some 18 part
  120. >multiprogram.
  121.  
  122. I started by using MUIBuilder to generate some GUIs - the code above
  123. can be used for pretty much any MUIBuilder interface, now that
  124. MUIBuilder allows you to set up the notifications - and seeing what
  125. the result was. Then I moved onto the source code for the demos that
  126. come with MUI, and finally joined the mui mailing list:
  127.  
  128. To: listserv@taloa.unice.fr
  129. Subject:
  130.  
  131. SIGNON mui
  132.  
  133. (Or something like that, anyway. :)
  134.  
  135. >    Thank you for your help.
  136.  
  137. No worries.
  138.  
  139. ><tsb> John J. Maver
  140.  
  141. -- 
  142. Jason S Birch                        ,-_|\ email: jasonb@cs.uwa.edu.au
  143. Department of Computer Science      /     \ Tel (work): +61 9 380 1840
  144. The University of Western Australia *_.-._/ Fax (work): +61 9 380 1089
  145. Nedlands  W. Australia  6907             v  Tel (home): +61 9 386 8630
  146.