
/*Amiga Computing*/
/*Code Clinic*/
/*Jan1991- windows and screens*/
/*A500 upwards*/

/*c source code*/

#include <exec/types.h>
#include <intuition/intuition.h>

struct IntuitionBase *IntuitionBase;    /*library pointer*/
struct Screen *customscreen;            /*pointer to screen structure*/
struct Window *thiswindow;              /*pointers to window structures*/
struct Window *thatwindow;
struct Window *otherwindow;
char *thatwindowtitle="that window";    /*window title text*/
char *otherwindowtitle="other window";
char *screentitle="custom screen";      /*screen title text*/
long i;

struct NewScreen TheNewScreen =         /*the new screen structure*/
{
 0,                                     /*Left Edge           */
 0,                                     /*Top Edge            */
 320,                                   /*Width               */
 200,                                   /*Height              */  
 3,                                     /*Depth               */
 1,                                     /*Detail Pen          */ 
 3,                                     /*Block Pen           */
 NULL,                                  /*Default ViewModes   */
 CUSTOMSCREEN,                          /*Screen Type         */
 NULL,                                  /*Default Font        */
 "custom screen",                       /*Title               */
 NULL,                                  /*No Gadget List      */
 NULL                                   /*No Custom BitMap    */   
};

struct NewWindow TheNewWindow =       /*a new window structure*/
{
 20,                                     /*Left Edge          */ 
 20,                                     /*Top Edge           */
 150,                                    /*Width              */
 50,                                     /*Height             */
 0,                                      /*Detail Pen         */ 
 1,                                      /*Block Pen          */
 CLOSEWINDOW,                            /*IDCMP flags        */
                                         /*Window flags for   */
                                         /*system window gadgets*/              
 WINDOWSIZING|WINDOWDRAG|WINDOWDEPTH|WINDOWCLOSE|SIZEBRIGHT,
 0,                                      /*No Gadgets         */
 0,                                      /*Default menu checkmark*/
 "this window",                          /*Title              */ 
 0,                                      /*Screen Pointer, put*/
                                         /*in after screen has*/
                                         /*been opened        */ 
 0,                                      /*Default BitMap     */
 64,                                     /*Minimum Width      */
 20,                                     /*Minimum Height     */
 300,                                    /*Maximum Width      */    
 200,                                    /*Maximum Height     */
 CUSTOMSCREEN,                           /*Custom screen, not */
                                         /*Workbench          */
};

main()
{
IntuitionBase = (struct IntuitionBase *)
 OpenLibrary("intuition.library",LIBRARY_VERSION);/*open the library*/
if (IntuitionBase == NULL) cleanup("no library");
customscreen= (struct Screen *) OpenScreen(&TheNewScreen);
if (customscreen == 0) cleanup("no screen");      /*open the screen*/

TheNewWindow.Screen = customscreen;              /*attach window to screen*/
           
                                                 /*open this window*/
if ((thiswindow = (struct Window *)OpenWindow(&TheNewWindow))  == NULL) 
cleanup("cannot open this window");

TheNewWindow.BlockPen = 3;                       /*open that window*/
if ((thatwindow = (struct Window *)OpenWindow(&TheNewWindow))  == NULL) 
cleanup("cannot open that window");
SetWindowTitles(thatwindow,thatwindowtitle,screentitle);
ModifyIDCMP(thatwindow,0);                       /*alter that window*/
for (i=0;i<50;i++)
MoveWindow(thatwindow,0,1);                      /*move that window*/

TheNewWindow.DetailPen = 1;                      /*open other window*/
if ((otherwindow = (struct Window *)OpenWindow(&TheNewWindow))  == NULL) 
cleanup("cannot open otherwindow");
SetWindowTitles(otherwindow,otherwindowtitle,screentitle);
ModifyIDCMP(otherwindow,0);                      /*alter other window*/
for (i=0;i<50;i++)                               /*move other window*/
MoveWindow(otherwindow,1,2);

Wait(1<<thiswindow->UserPort->mp_SigBit);        /*wait for mouseclick on*/
                                                 /*thiswindow close gadget*/
cleanup("ok"); 
}

cleanup(errormsg)                                   /* leave as you would wish */
{                                                   /*  to find                */
printf(errormsg);
if (otherwindow != 0 ) CloseWindow(otherwindow);  /*close windows*/
if (thatwindow != 0 ) CloseWindow(thatwindow);
if (thiswindow != 0 ) CloseWindow(thiswindow);
if (customscreen != 0 ) CloseScreen(customscreen);/*close screen*/
if (IntuitionBase !=0) CloseLibrary(IntuitionBase);/*close library*/
exit(0);
return(0);
}
