home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / sys / amiga / programm / 16149 < prev    next >
Encoding:
Text File  |  1992-11-20  |  13.4 KB  |  506 lines

  1. Path: sparky!uunet!zaphod.mps.ohio-state.edu!magnus.acs.ohio-state.edu!usenet.ins.cwru.edu!cleveland.Freenet.Edu!as170
  2. From: as170@cleveland.Freenet.Edu (Ronn F. Black)
  3. Newsgroups: comp.sys.amiga.programmer
  4. Subject: Thanks for GadToolBox Answers
  5. Date: 20 Nov 1992 21:53:31 GMT
  6. Organization: Case Western Reserve University, Cleveland, OH (USA)
  7. Lines: 494
  8. Message-ID: <1ejmorINNp6c@usenet.INS.CWRU.Edu>
  9. Reply-To: as170@cleveland.Freenet.Edu (Ronn F. Black)
  10. NNTP-Posting-Host: hela.ins.cwru.edu
  11.  
  12.  
  13. A great big thankyou to everyone who replied to my message for assistance with
  14. Gadget ToolBox.  I managed to get a good skeleton program worked out for that
  15. should provide a good ground work for further building. I am posting the "C"
  16. source to the skeleton and the LMKFile that I am using under SAS/C V5.1x
  17.  
  18. I hope this helps out anyone else working on this stuff.
  19.  
  20. Thanks again
  21. Ronn Black
  22.  
  23. ---- Begin GTBMainPgm.c ----
  24.  
  25. /*************************************************************************
  26. ** PROGRAM:
  27. **************************************************************************
  28. **                                    **
  29. ** DESCRIPTION:                                **
  30. **    To use the skeleton, do the following search & Replaces in 
  31. **    the GTBLMKFile.lmk and GTBMainPGM.c
  32. **
  33. **        SEARCH FOR    REPLACE WITH
  34. **        "CntPanel"    <ProjectName> defined in GADToolBox.
  35. **        "MainPGM"    The name of your Main Project.
  36. **                                    **
  37. ** ROUTINES:                                **
  38. **       CloseLibs() . .    Close all Opened Libraries.            **
  39. **    OpenLibs(). . .    Open all needed Libraries.            **
  40. **    HandleButtons()    Handle User clicks on Buttons.            **
  41. **    HandleMenu(). .    Handle User Menu Selection.            **
  42. **    Main(). . . . .    Main Routine.                    **
  43. **    
  44. **                                    ** 
  45. ** HISTORY:                                **
  46. **    
  47. **    
  48. **                                    **
  49. **************************************************************************
  50. */                                                                         
  51.                                                                            
  52. /*
  53. ** DEFINES
  54. **
  55. */
  56.  
  57.  
  58. /*
  59. ** INCLUDES
  60. */                                                                         
  61. #include <errno.h>                                                         
  62. #include <stdio.h>
  63. #include <ios1.h>                                                          
  64.  
  65. #include <clib/exec_protos.h>
  66. #include <clib/intuition_protos.h>
  67. #include <clib/gadtools_protos.h>
  68. #include <clib/graphics_protos.h>
  69.  
  70. #include <workbench/startup.h>
  71. #include <workbench/workbench.h>
  72. #include <workbench/icon.h>
  73.  
  74. #include <pragmas/exec_pragmas.h>
  75. #include <pragmas/intuition_pragmas.h>
  76. #include <pragmas/gadtools_pragmas.h>
  77. #include <pragmas/graphics_pragmas.h>
  78.  
  79. #include <proto/exec.h>
  80.  
  81.   /* 
  82.   ** Define "INCLUDE_ALL" to include all of the includes
  83.   */ 
  84. #ifdef INCLUDE_ALL 
  85. #include <proto/all.h>
  86.  
  87. #include <string.h>
  88. #include <fcntl.h>                                                         
  89.  
  90. #include <exec/exec.h>
  91. #include <exec/types.h>
  92. #include <exec/nodes.h>
  93. #include <exec/lists.h>
  94. #include <exec/memory.h>
  95. #include <exec/ports.h>
  96. #include <exec/tasks.h>
  97. #include <exec/libraries.h>
  98. #include <exec/devices.h>
  99. #include <exec/io.h>
  100. #include <exec/devices.h>
  101. #include <exec/interrupts.h>
  102.  
  103. #include <libraries/dos.h>
  104. #include <libraries/dosextens.h>
  105.  
  106. #include <intuition/intuition.h>
  107. #include <intuition/classes.h>
  108. #include <intuition/classusr.h>
  109. #include <intuition/imageclass.h>
  110. #include <intuition/gadgetclass.h>
  111. #include <intuition/preferences.h>
  112.  
  113. #include <libraries/gadtools.h>
  114.  
  115. #include <graphics/gfx.h>
  116. #include <graphics/displayinfo.h>
  117. #include <graphics/gfxbase.h>
  118. #endif
  119.  
  120. #include "CntPanel.h" /****~/\~Include the .h file from GadToolBox here. ****/
  121.                                                                             
  122.  
  123.                                                                            
  124. /*
  125. ** EXTERNAL/GLOBAL VARIABLES & CONSTANTS
  126. */                                                                         
  127. struct DosLibrary    *DosBase       = NULL;
  128. struct IntuitionBase *IntuitionBase = NULL;
  129. struct GadToolsBase  *GadToolsBase  = NULL;
  130. struct GfxBase       *GraphicsBase  = NULL;
  131.  
  132. /*
  133. ** ROUTINES CALLED IN OTHER MODULES
  134. */
  135.  
  136.  
  137. /*************************************************************************
  138. **            SUPPORT FUNCTIONS                **
  139. **************************************************************************
  140. */
  141. /*************************************************************************
  142. ** CloseLibs() - Close all Libraries
  143. */
  144. void CloseLibs()
  145. {
  146.   if (IntuitionBase) CloseLibrary(IntuitionBase);
  147.   if (GadToolsBase) CloseLibrary(GadToolsBase);
  148.   if (GraphicsBase) CloseLibrary(GraphicsBase);
  149.  
  150. } /* End of CloseLibs() */
  151.  
  152. /*************************************************************************
  153. ** OpenLibs() - Open all Libraries
  154. **
  155. */
  156. BOOL OpenLibs()
  157. {
  158.   /*
  159.   ** Local Variables
  160.   */
  161.   FILE *fp;
  162.   char trash[255];
  163.  
  164.   if ((IntuitionBase = (void *)OpenLibrary("intuition.library",37L)) &&
  165.       (GadToolsBase  = (void *)OpenLibrary("gadtools.library",37L))  &&
  166.       (GraphicsBase  = (void *)OpenLibrary("graphics.library",37L))){
  167.    
  168.       return TRUE;
  169.  
  170.   } else {
  171.  
  172.     /*
  173.     ** Error Opening, Warn through Con: window, then return.
  174.     */
  175.     if ((fp = fopen ("con:100/20/400/150/GTBMainPGM Warning","w+"))!= NULL){
  176.       fprintf(fp,"Warning!! GTBMainPGM was not able to open \n");
  177.       fprintf(fp,"one or more of the following Libraries: \n");
  178.       fprintf(fp,"  libs:intution.library\n");
  179.       fprintf(fp,"  libs:gadtools.library\n");
  180.       fprintf(fp,"  libs:graphics.library\n");
  181.       fprintf(fp,"Press <RETURN> to continue:");
  182.       rewind(fp);
  183.       fgets(trash,255,fp);
  184.       fclose(fp);
  185.     }
  186.  
  187.     CloseLibs();
  188.     return FALSE;
  189.   }
  190. } /* End of OpenLibs() */
  191.  
  192. /*************************************************************************
  193. ** HandleButtons() - Handle User clicks on Buttons
  194. **
  195. */
  196. void HandleButtons(struct IntuiMessage *m)
  197. {
  198.   /*
  199.   ** Local Variables
  200.   */
  201.   FILE *fp;
  202.   char trash[255];
  203.   struct  Gadget  *g;
  204.   USHORT  id;
  205.     
  206.   /*
  207.   ** Figure out the ID of the Button Pressed.
  208.   */
  209.   g = (struct Gadget *)m->IAddress;
  210.   id = g->GadgetID;
  211.   
  212.   /*
  213.   ** Tell the User what Button the Clicked On.
  214.   */
  215.   if ((fp = fopen("con:100/20/400/150/GTBMainPGM Info","w+")) != NULL){
  216.     fprintf(fp,"\nINFO: You have clicked on button ID: %hu.\n",id);
  217.     fprintf(fp,"\nPress <RETURN> to continue:");
  218.     rewind(fp);
  219.     fgets(trash,255,fp);
  220.     fclose(fp);
  221.   }
  222. } /* End of HandleButtons() */
  223.  
  224. /*************************************************************************
  225. ** HandleMenu() - Handle User Menu Selections
  226. **
  227. */
  228. void HandleMenu(struct IntuiMessage *m)
  229. {
  230.   /*
  231.   ** Variables for console window stuff only
  232.   */
  233.   FILE *fp;
  234.   char trash[255];
  235.  
  236.   /*
  237.   ** Local Variables
  238.   */  
  239.   char *Choice;
  240.   USHORT code, flags;
  241.   ULONG menuNum, itemNum, subNum;
  242.  
  243.   /*
  244.   ** Process the list of Menu Selections.
  245.   */
  246.   code = m->Code;
  247.   while(code != MENUNULL){
  248.     menuNum = MENUNUM(code);
  249.     itemNum = ITEMNUM(code);
  250.     subNum  = SUBNUM(code);
  251.     flags   = ((struct MenuItem *)ItemAddress(CntPanelMenus,(LONG)code))->Flags;
  252.  
  253.     if(flags&CHECKED){
  254.       /*
  255.       ** Handle flag CHECKED.
  256.       */
  257.     }
  258.  
  259.     switch( menuNum ){
  260.       /*
  261.       ** Project Menu (0)
  262.       */
  263.       case 0: switch(itemNum){
  264.                 case 0:  /*
  265.                          ** Item 0-0
  266.                          */
  267.                          Choice = "Menu Item 0-0";
  268.                          break;
  269.                 case 1:  /*
  270.                          ** Item 0-1
  271.                          */
  272.                          Choice = "Menu Item 0-1";
  273.                          break;
  274.                 case 2:  /*
  275.                          ** Item 0-2 (Quit)
  276.                          */
  277.                          CloseCntPanelWindow();
  278.                          CloseDownScreen();
  279.                          CloseLibs();
  280.                          exit();
  281.                          break;
  282.                 default: /*
  283.                          ** Bad menu Choice.
  284.                          */
  285.                          break;
  286.           } /* end switch(itemNum){ */
  287.               break;
  288.  
  289.       /*
  290.       ** Edit Menu (1)
  291.       */
  292.       case 1: switch(itemNum){
  293.                 case 0:  /*
  294.                          ** Item 1-0
  295.                          */
  296.                          Choice = "Menu Item 1-0";
  297.                          break;
  298.                 case 1:  /*
  299.                          ** Item 1-1
  300.                          */
  301.                          Choice = "Menu Item 1-1";
  302.                          break;
  303.                 default: /*
  304.                          ** Bad menu Choice.
  305.                          */
  306.                          break;
  307.           } /* end switch(itemNum){ */
  308.               break;
  309.     }/* end switch(menuNum){ */
  310.  
  311.     /*
  312.     ** Tell the User what Menu Item they selected.
  313.     */
  314.     if ((fp = fopen("con:100/20/400/150/GTBMainPGM Info","w+")) != NULL){
  315.       fprintf(fp,"\nINFO: You have selected: %s.\n",Choice);
  316.       fprintf(fp,"\nPress <RETURN> to continue:");
  317.       rewind(fp);
  318.       fgets(trash,255,fp);
  319.       fclose(fp);
  320.     }
  321.  
  322.     /*
  323.     ** Get next Menu Choice
  324.     */
  325.     code = ((struct MenuItem *)ItemAddress(CntPanelMenus,(LONG)code))->NextSelect;
  326.   }/* end while(code != MENUNULL){ */
  327.              
  328. } /* End of HandleButtons() */
  329.  
  330. /*************************************************************************
  331. **                START OF MAIN()                **
  332. **************************************************************************
  333. */
  334. int main(argc, argv)
  335. int argc;
  336. char *argv[];
  337. {
  338.  
  339.   /*
  340.   ** Local Variables and Constants
  341.   */
  342.  
  343.  
  344.   /***********************************************************************
  345.   **                START OF PROGRAM            **
  346.   ************************************************************************
  347.   */
  348.   /*
  349.   ** Make printf work when started from CLI but don't open a console window
  350.   ** when started from workbench. (printf is normally disabled when TINY 
  351.   ** is used to prevent the)
  352.   */
  353. #define TINY
  354. #ifdef TINY
  355.  
  356.   extern int  _fmode, _iomode;
  357.   extern int (* ONBREAK)();
  358.   extern int CXBRK();
  359.   register int x;
  360.   extern struct UFB  ufbs[];
  361.  
  362. #endif
  363.  
  364.  
  365.   /*
  366.   ** Attempt to Open Libraries
  367.   */
  368.   if (!OpenLibs()){
  369.     return;
  370.   }
  371.  
  372.   if (!SetupScreen()){
  373.  
  374.     if (!OpenCntPanelWindow()){
  375.  
  376.       /*******************************************************************
  377.       ** Main Intuition Loop
  378.       */
  379.       for (;;){
  380.  
  381.         /*
  382.         ** Variables used here
  383.         */
  384.         struct IntuiMessage *msg;
  385.         ULONG class;
  386.         UWORD code;
  387.  
  388.         /*
  389.         ** Wait on Message
  390.         */
  391.     WaitPort(CntPanelWnd->UserPort);
  392.     while (msg = GT_GetIMsg(CntPanelWnd->UserPort)){
  393.  
  394.           /*
  395.           ** Get Class and Code, then Reply
  396.           */
  397.           class = msg->Class; 
  398.           code = msg->Code;
  399.           GT_ReplyIMsg(msg);
  400.  
  401.           /*
  402.           ** Close Window Gadget Picked
  403.           */
  404.           switch (class){
  405.  
  406.             case CLOSEWINDOW: CloseCntPanelWindow();
  407.                               CloseDownScreen();
  408.                               CloseLibs();
  409.                               exit();
  410.  
  411.             case BUTTONIDCMP: HandleButtons(msg);
  412.                               break;
  413.         
  414.             case MENUPICK:    HandleMenu(msg);
  415.             default:          break; 
  416.             
  417.       } /* end switch (class){ */
  418.     } /* end while (msg = GT GetIMsg(CntPanelWnd->UserPort)){ */
  419.  
  420.       } /* for (;;) */
  421.  
  422.     } /* if (!OpenCntPanelWindow()){ */
  423.     CloseDownScreen();
  424.  
  425.   } /* if (!SetupScreen()){ */
  426.   CloseLibs();
  427.  
  428. } /* main */
  429.  
  430.  
  431. ---- end GTBMainPgm.c  ----
  432.  
  433.  
  434. ---- Begin LMKFile.lmk ----
  435.  
  436.  
  437. ##############################################################################
  438. ## All related programs                                                     ##
  439. ##############################################################################
  440. ##
  441. ALL: GTBMainPgm
  442.   say "All Done."
  443.  
  444. ##############################################################################
  445. ## GTBMainPgm.c                                                             ##
  446. ##############################################################################
  447. ##
  448. GTBMainPgm: GTBMainPgm.o CntPanel.o LMKFile.lmk
  449.  
  450.   #
  451.   # Link Section
  452.   #
  453.  
  454.   #
  455.   # Build Link file
  456.   #
  457.   @echo >GTBMainPgm.lnk  "ROOT"
  458.   @echo >>GTBMainPgm.lnk "  LIB:c.o"
  459. #  @echo >>GTBMainPgm.lnk "  LIB:boopsi.o"
  460.   @echo >>GTBMainPgm.lnk "  GTBMainPgm.o"
  461.   @echo >>GTBMainPgm.lnk "  CntPanel.o"
  462. #  @echo >>GTBMainPgm.lnk "OVERLAY"
  463. #  @eval >>GTBMainPgm.lnk 35 lformat="~%C*N" # Put in Pound sign
  464.   @echo >>GTBMainPgm.lnk "TO GTBMainPgm"
  465.   @echo >>GTBMainPgm.lnk "MAP GTBMainPgm.map FHLO"
  466.   @echo >>GTBMainPgm.lnk "LIB LIB:lc.lib LIB:amiga.lib LIB:amiga2.0.lib"
  467.   @echo >>GTBMainPgm.lnk "ADDSYM"
  468.   @echo >>GTBMainPgm.lnk "BATCH"
  469.  
  470.   #
  471.   # Uncomment the following to eliminate the main window when running from 
  472.   # Workbench. However, this disables PRINTF completely....
  473.   #
  474.   @echo >>GTBMainPgm.lnk "DEFINE __main=__tinymain"
  475.  
  476.   blink  with GTBMainPgm.lnk
  477.  
  478.  
  479. GTBMainPgm.o: GTBMainPgm.c
  480.   #
  481.   #Compile Section
  482.   #
  483.   LC GTBMainPgm.c
  484.  
  485. CntPanel.o: CntPanel.c
  486.   #
  487.   #Compile Section
  488.   #
  489.   LC CntPanel.c
  490.  
  491. ##############################################################################
  492. ## Error Handling                                                           ##
  493. ##############################################################################
  494. ##
  495. .ONERROR:
  496.   say "Compile Terminated with Error."
  497.  
  498.  
  499.  
  500. ---- end LMKFile.lmk   ----
  501. -- 
  502. -------------- Ronn F. Black --> as170@Cleveland.Freenet.Edu ---------------
  503. Enter through the narrow gate. For wide is the gate and broad is the road that
  504. leads to destruction, and many enter through it. But small is the gate and
  505. narrow is the road that leads to life and only a few find it.      Matt7:13-14
  506.