From: as170@cleveland.Freenet.Edu (Ronn F. Black)
Newsgroups: comp.sys.amiga.programmer
Subject: Thanks for GadToolBox Answers
Date: 20 Nov 1992 21:53:31 GMT
Organization: Case Western Reserve University, Cleveland, OH (USA)
Reply-To: as170@cleveland.Freenet.Edu (Ronn F. Black)
NNTP-Posting-Host: hela.ins.cwru.edu


A great big thankyou to everyone who replied to my message for assistance with
Gadget ToolBox.  I managed to get a good skeleton program worked out for that
should provide a good ground work for further building. I am posting the "C"
source to the skeleton and the LMKFile that I am using under SAS/C V5.1x
 
I hope this helps out anyone else working on this stuff.
 
Thanks again
Ronn Black
 
---- Begin GTBMainPgm.c ----
 
/*************************************************************************
** PROGRAM:
**************************************************************************
**									**
** DESCRIPTION:								**
**	To use the skeleton, do the following search & Replaces in 
**	the GTBLMKFile.lmk and GTBMainPGM.c
**
**		SEARCH FOR	REPLACE WITH
**		"CntPanel"	<ProjectName> defined in GADToolBox.
**		"MainPGM"	The name of your Main Project.
**									**
** ROUTINES:								**
**   	CloseLibs() . .	Close all Opened Libraries.			**
**	OpenLibs(). . .	Open all needed Libraries.			**
**	HandleButtons()	Handle User clicks on Buttons.			**
**	HandleMenu(). .	Handle User Menu Selection.			**
**	Main(). . . . .	Main Routine.					**
**	
**									** 
** HISTORY:								**
**	
**	
**									**
**************************************************************************
*/                                                                         
                                                                           
/*
** DEFINES
**
*/
 
 
/*
** INCLUDES
*/                                                                         
#include <errno.h>                                                         
#include <stdio.h>
#include <ios1.h>                                                          
 
#include <clib/exec_protos.h>
#include <clib/intuition_protos.h>
#include <clib/gadtools_protos.h>
#include <clib/graphics_protos.h>
 
#include <workbench/startup.h>
#include <workbench/workbench.h>
#include <workbench/icon.h>
 
#include <pragmas/exec_pragmas.h>
#include <pragmas/intuition_pragmas.h>
#include <pragmas/gadtools_pragmas.h>
#include <pragmas/graphics_pragmas.h>
 
#include <proto/exec.h>
 
  /* 
  ** Define "INCLUDE_ALL" to include all of the includes
  */ 
#ifdef INCLUDE_ALL 
#include <proto/all.h>
 
#include <string.h>
#include <fcntl.h>                                                         
 
#include <exec/exec.h>
#include <exec/types.h>
#include <exec/nodes.h>
#include <exec/lists.h>
#include <exec/memory.h>
#include <exec/ports.h>
#include <exec/tasks.h>
#include <exec/libraries.h>
#include <exec/devices.h>
#include <exec/io.h>
#include <exec/devices.h>
#include <exec/interrupts.h>
 
#include <libraries/dos.h>
#include <libraries/dosextens.h>
 
#include <intuition/intuition.h>
#include <intuition/classes.h>
#include <intuition/classusr.h>
#include <intuition/imageclass.h>
#include <intuition/gadgetclass.h>
#include <intuition/preferences.h>
 
#include <libraries/gadtools.h>
 
#include <graphics/gfx.h>
#include <graphics/displayinfo.h>
#include <graphics/gfxbase.h>
#endif
 
#include "CntPanel.h" /****~/\~Include the .h file from GadToolBox here. ****/
                                                                            
 
                                                                           
/*
** EXTERNAL/GLOBAL VARIABLES & CONSTANTS
*/                                                                         
struct DosLibrary    *DosBase       = NULL;
struct IntuitionBase *IntuitionBase = NULL;
struct GadToolsBase  *GadToolsBase  = NULL;
struct GfxBase       *GraphicsBase  = NULL;
 
/*
** ROUTINES CALLED IN OTHER MODULES
*/
 
 
/*************************************************************************
**			SUPPORT FUNCTIONS				**
**************************************************************************
*/
/*************************************************************************
** CloseLibs() - Close all Libraries
*/
void CloseLibs()
{
  if (IntuitionBase) CloseLibrary(IntuitionBase);
  if (GadToolsBase) CloseLibrary(GadToolsBase);
  if (GraphicsBase) CloseLibrary(GraphicsBase);
 
} /* End of CloseLibs() */
 
/*************************************************************************
** OpenLibs() - Open all Libraries
**
*/
BOOL OpenLibs()
{
  /*
  ** Local Variables
  */
  FILE *fp;
  char trash[255];
 
  if ((IntuitionBase = (void *)OpenLibrary("intuition.library",37L)) &&
      (GadToolsBase  = (void *)OpenLibrary("gadtools.library",37L))  &&
      (GraphicsBase  = (void *)OpenLibrary("graphics.library",37L))){
   
      return TRUE;
 
  } else {
 
    /*
    ** Error Opening, Warn through Con: window, then return.
    */
    if ((fp = fopen ("con:100/20/400/150/GTBMainPGM Warning","w+"))!= NULL){
      fprintf(fp,"Warning!! GTBMainPGM was not able to open \n");
      fprintf(fp,"one or more of the following Libraries: \n");
      fprintf(fp,"  libs:intution.library\n");
      fprintf(fp,"  libs:gadtools.library\n");
      fprintf(fp,"  libs:graphics.library\n");
      fprintf(fp,"Press <RETURN> to continue:");
      rewind(fp);
      fgets(trash,255,fp);
      fclose(fp);
    }
 
    CloseLibs();
    return FALSE;
  }
} /* End of OpenLibs() */
 
/*************************************************************************
** HandleButtons() - Handle User clicks on Buttons
**
*/
void HandleButtons(struct IntuiMessage *m)
{
  /*
  ** Local Variables
  */
  FILE *fp;
  char trash[255];
  struct  Gadget  *g;
  USHORT  id;
	
  /*
  ** Figure out the ID of the Button Pressed.
  */
  g = (struct Gadget *)m->IAddress;
  id = g->GadgetID;
  
  /*
  ** Tell the User what Button the Clicked On.
  */
  if ((fp = fopen("con:100/20/400/150/GTBMainPGM Info","w+")) != NULL){
    fprintf(fp,"\nINFO: You have clicked on button ID: %hu.\n",id);
    fprintf(fp,"\nPress <RETURN> to continue:");
    rewind(fp);
    fgets(trash,255,fp);
    fclose(fp);
  }
} /* End of HandleButtons() */
 
/*************************************************************************
** HandleMenu() - Handle User Menu Selections
**
*/
void HandleMenu(struct IntuiMessage *m)
{
  /*
  ** Variables for console window stuff only
  */
  FILE *fp;
  char trash[255];
 
  /*
  ** Local Variables
  */  
  char *Choice;
  USHORT code, flags;
  ULONG menuNum, itemNum, subNum;
 
  /*
  ** Process the list of Menu Selections.
  */
  code = m->Code;
  while(code != MENUNULL){
    menuNum = MENUNUM(code);
    itemNum = ITEMNUM(code);
    subNum  = SUBNUM(code);
    flags   = ((struct MenuItem *)ItemAddress(CntPanelMenus,(LONG)code))->Flags;
 
    if(flags&CHECKED){
      /*
      ** Handle flag CHECKED.
      */
    }
 
    switch( menuNum ){
      /*
      ** Project Menu (0)
      */
      case 0: switch(itemNum){
                case 0:  /*
                         ** Item 0-0
                         */
                         Choice = "Menu Item 0-0";
                         break;
                case 1:  /*
                         ** Item 0-1
                         */
                         Choice = "Menu Item 0-1";
                         break;
                case 2:  /*
                         ** Item 0-2 (Quit)
                         */
                         CloseCntPanelWindow();
                         CloseDownScreen();
                         CloseLibs();
                         exit();
                         break;
                default: /*
                         ** Bad menu Choice.
                         */
                         break;
	      } /* end switch(itemNum){ */
              break;
 
      /*
      ** Edit Menu (1)
      */
      case 1: switch(itemNum){
                case 0:  /*
                         ** Item 1-0
                         */
                         Choice = "Menu Item 1-0";
                         break;
                case 1:  /*
                         ** Item 1-1
                         */
                         Choice = "Menu Item 1-1";
                         break;
                default: /*
                         ** Bad menu Choice.
                         */
                         break;
	      } /* end switch(itemNum){ */
              break;
    }/* end switch(menuNum){ */
 
    /*
    ** Tell the User what Menu Item they selected.
    */
    if ((fp = fopen("con:100/20/400/150/GTBMainPGM Info","w+")) != NULL){
      fprintf(fp,"\nINFO: You have selected: %s.\n",Choice);
      fprintf(fp,"\nPress <RETURN> to continue:");
      rewind(fp);
      fgets(trash,255,fp);
      fclose(fp);
    }
 
    /*
    ** Get next Menu Choice
    */
    code = ((struct MenuItem *)ItemAddress(CntPanelMenus,(LONG)code))->NextSelect;
  }/* end while(code != MENUNULL){ */
         	
} /* End of HandleButtons() */
 
/*************************************************************************
**				START OF MAIN()				**
**************************************************************************
*/
int main(argc, argv)
int argc;
char *argv[];
{
 
  /*
  ** Local Variables and Constants
  */
 
 
  /***********************************************************************
  **				START OF PROGRAM			**
  ************************************************************************
  */
  /*
  ** Make printf work when started from CLI but don't open a console window
  ** when started from workbench. (printf is normally disabled when TINY 
  ** is used to prevent the)
  */
#define TINY
#ifdef TINY
 
  extern int  _fmode, _iomode;
  extern int (* ONBREAK)();
  extern int CXBRK();
  register int x;
  extern struct UFB  ufbs[];
 
#endif
 
 
  /*
  ** Attempt to Open Libraries
  */
  if (!OpenLibs()){
    return;
  }
 
  if (!SetupScreen()){
 
    if (!OpenCntPanelWindow()){
 
      /*******************************************************************
      ** Main Intuition Loop
      */
      for (;;){
 
        /*
        ** Variables used here
        */
        struct IntuiMessage *msg;
        ULONG class;
        UWORD code;
 
        /*
        ** Wait on Message
        */
	WaitPort(CntPanelWnd->UserPort);
	while (msg = GT_GetIMsg(CntPanelWnd->UserPort)){
 
          /*
          ** Get Class and Code, then Reply
          */
          class = msg->Class; 
          code = msg->Code;
          GT_ReplyIMsg(msg);
 
          /*
          ** Close Window Gadget Picked
          */
          switch (class){
 
            case CLOSEWINDOW: CloseCntPanelWindow();
                              CloseDownScreen();
                              CloseLibs();
                              exit();
 
            case BUTTONIDCMP: HandleButtons(msg);
                              break;
	    
            case MENUPICK:    HandleMenu(msg);
            default:          break; 
            
	  } /* end switch (class){ */
	} /* end while (msg = GT GetIMsg(CntPanelWnd->UserPort)){ */
 
      } /* for (;;) */
 
    } /* if (!OpenCntPanelWindow()){ */
    CloseDownScreen();
 
  } /* if (!SetupScreen()){ */
  CloseLibs();
 
} /* main */
 
 
---- end GTBMainPgm.c  ----
 
 
---- Begin LMKFile.lmk ----
 
 
##############################################################################
## All related programs                                                     ##
##############################################################################
##
ALL: GTBMainPgm
  say "All Done."
 
##############################################################################
## GTBMainPgm.c                                                             ##
##############################################################################
##
GTBMainPgm: GTBMainPgm.o CntPanel.o LMKFile.lmk
 
  #
  # Link Section
  #
 
  #
  # Build Link file
  #
  @echo >GTBMainPgm.lnk  "ROOT"
  @echo >>GTBMainPgm.lnk "  LIB:c.o"
#  @echo >>GTBMainPgm.lnk "  LIB:boopsi.o"
  @echo >>GTBMainPgm.lnk "  GTBMainPgm.o"
  @echo >>GTBMainPgm.lnk "  CntPanel.o"
#  @echo >>GTBMainPgm.lnk "OVERLAY"
#  @eval >>GTBMainPgm.lnk 35 lformat="~%C*N" # Put in Pound sign
  @echo >>GTBMainPgm.lnk "TO GTBMainPgm"
  @echo >>GTBMainPgm.lnk "MAP GTBMainPgm.map FHLO"
  @echo >>GTBMainPgm.lnk "LIB LIB:lc.lib LIB:amiga.lib LIB:amiga2.0.lib"
  @echo >>GTBMainPgm.lnk "ADDSYM"
  @echo >>GTBMainPgm.lnk "BATCH"
 
  #
  # Uncomment the following to eliminate the main window when running from 
  # Workbench. However, this disables PRINTF completely....
  #
  @echo >>GTBMainPgm.lnk "DEFINE __main=__tinymain"
 
  blink  with GTBMainPgm.lnk
 
 
GTBMainPgm.o: GTBMainPgm.c
  #
  #Compile Section
  #
  LC GTBMainPgm.c
 
CntPanel.o: CntPanel.c
  #
  #Compile Section
  #
  LC CntPanel.c
 
##############################################################################
## Error Handling                                                           ##
##############################################################################
##
.ONERROR:
  say "Compile Terminated with Error."
 
 
 
---- end LMKFile.lmk   ----
-- 
-------------- Ronn F. Black --> as170@Cleveland.Freenet.Edu ---------------
Enter through the narrow gate. For wide is the gate and broad is the road that
leads to destruction, and many enter through it. But small is the gate and
narrow is the road that leads to life and only a few find it.      Matt7:13-14
Newsgroups: comp.sys.amiga.datacomm