home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD 2.1 / Amiga Developer CD v2.1.iso / Reference / DevCon / Milan_1991 / Devcon91.1 / Libraries / Intuition / attachedsc.c next >
Encoding:
C/C++ Source or Header  |  1992-09-01  |  3.8 KB  |  201 lines

  1. /*
  2.  * attachedsc.c
  3.  *
  4.  * Demonstrates opening attached screens.
  5.  *
  6.  * This program functions fine under Kickstart V36/V37, but the two
  7.  * screens remain independent.
  8.  *
  9.  * (C) Copyright 1991, Commodore-Amiga, Inc.
  10.  *
  11.  * Executables based on this information may be used in software
  12.  * for Commodore Amiga computers.  All other rights reserved.
  13.  * This information is provided "as is"; no warranties are made.  All
  14.  * use is at your own risk. No liability or responsibility is assumed.
  15.  *
  16.  */
  17.  
  18. /*----------------------------------------------------------------------*/
  19.  
  20. #include <exec/types.h>
  21. #include <graphics/displayinfo.h>
  22. #include <intuition/intuition.h>
  23.  
  24. #include <clib/exec_protos.h>
  25. #include <clib/graphics_protos.h>
  26. #include <clib/intuition_protos.h>
  27. #include <pragmas/exec_pragmas.h>
  28. #include <pragmas/graphics_pragmas.h>
  29. #include <pragmas/intuition_pragmas.h>
  30.  
  31. /* These definitions will appear in V39 include files.  Until then,
  32.  * they're available locally
  33.  */
  34.  
  35. #ifndef SA_Attach
  36. #define SA_Attach    (SA_Dummy + 0x001D)
  37. #endif
  38.  
  39. extern struct Library *SysBase;
  40.  
  41. /*----------------------------------------------------------------------*/
  42.  
  43. void error_exit(STRPTR errorstring);
  44.  
  45. /*----------------------------------------------------------------------*/
  46.  
  47. struct GfxBase *GfxBase = NULL;
  48. struct IntuitionBase *IntuitionBase = NULL;
  49. struct Screen *parent = NULL;
  50. struct Screen *child = NULL;
  51. struct Window *parentwin = NULL;
  52. struct Window *childwin = NULL;
  53.  
  54. UWORD Pens[] =
  55. {
  56.     ~0,
  57. };
  58.  
  59. /*----------------------------------------------------------------------*/
  60.  
  61. main()
  62.  
  63. {
  64.     int i,w;
  65.  
  66.     if (!( GfxBase = (struct GfxBase *)
  67.     OpenLibrary("graphics.library", 36L) ))
  68.     {
  69.     error_exit("Couldn't open Gfx V36\n");
  70.     }
  71.  
  72.     if (!( IntuitionBase = (struct IntuitionBase *)
  73.     OpenLibrary("intuition.library", 36L) ))
  74.     {
  75.     error_exit("Couldn't open Intuition V36\n");
  76.     }
  77.  
  78.     if (!(parent = OpenScreenTags(NULL,
  79.     SA_DisplayID, HIRES_KEY,
  80.     SA_Overscan, OSCAN_TEXT,
  81.     SA_Depth, 2,
  82.     SA_AutoScroll, 1,
  83.     SA_Pens, Pens,
  84.     SA_Title, "Parent",
  85.     TAG_DONE )))
  86.     {
  87.     error_exit("Couldn't open screen");
  88.     }
  89.     if (!( parentwin = OpenWindowTags(NULL,
  90.     WA_Title, "Peter's Window",
  91.     WA_SizeGadget, TRUE,
  92.     WA_DragBar, TRUE,
  93.     WA_CloseGadget, TRUE,
  94.     WA_DepthGadget, TRUE,
  95.     WA_IDCMP, CLOSEWINDOW,
  96.     WA_NoCareRefresh, TRUE,
  97.     WA_Activate, TRUE,
  98.     WA_SmartRefresh, TRUE,
  99.     WA_CustomScreen, parent,
  100.     WA_Top, 10,
  101.     WA_Height, 190,
  102.     WA_MinWidth, 100,
  103.     WA_MinHeight, 50,
  104.     WA_MaxWidth, -1,
  105.     WA_MaxHeight, -1,
  106.     TAG_DONE ) ))
  107.     {
  108.     error_exit("Couldn't open window");
  109.     }
  110.  
  111.     if (!(child = OpenScreenTags(NULL,
  112.     SA_DisplayID, LORES_KEY,
  113.     SA_Overscan, OSCAN_TEXT,
  114.     SA_Depth, 5,
  115.     SA_Top, 150,
  116.     SA_Height, 50,
  117.     SA_AutoScroll, 1,
  118.     SA_Attach, parent,
  119.     SA_Pens, Pens,
  120.     SA_Title, "Child",
  121.     TAG_DONE )))
  122.     {
  123.     error_exit("Couldn't open screen");
  124.     }
  125.  
  126.     if (!( childwin = OpenWindowTags(NULL,
  127.     WA_IDCMP, CLOSEWINDOW,
  128.     WA_NoCareRefresh, TRUE,
  129.     WA_Activate, TRUE,
  130.     WA_SmartRefresh, TRUE,
  131.     WA_CustomScreen, child,
  132.     WA_Top, 0,
  133.     TAG_DONE ) ))
  134.     {
  135.     error_exit("Couldn't open window");
  136.     }
  137.  
  138.     w = childwin->Width - 8;
  139.  
  140.     for (i=0; i < 31; i++)
  141.     {
  142.     SetAPen( childwin->RPort, i );
  143.     RectFill( childwin->RPort, (i*w)/32+4,2,((i+1)*w)/32+3, 47 );
  144.     }
  145.  
  146.     Move(parentwin->RPort, 50,50);
  147.     Text(parentwin->RPort, "Hello", 5);
  148.  
  149.     WaitPort( parentwin->UserPort );
  150.  
  151.     error_exit(NULL);
  152. }
  153.  
  154.  
  155. /*----------------------------------------------------------------------*/
  156.  
  157. void error_exit(STRPTR errorstring)
  158.  
  159.     {
  160.     if (childwin)
  161.     {
  162.     CloseWindow(childwin);
  163.     }
  164.  
  165.     if (parentwin)
  166.     {
  167.     CloseWindow(parentwin);
  168.     }
  169.  
  170.     if (child)
  171.     {
  172.     CloseScreen(child);
  173.     }
  174.  
  175.     if (parent)
  176.     {
  177.     CloseScreen(parent);
  178.     }
  179.  
  180.     if (IntuitionBase)
  181.     {
  182.     CloseLibrary(IntuitionBase);
  183.     }
  184.  
  185.     if (GfxBase)
  186.     {
  187.     CloseLibrary(GfxBase);
  188.     }
  189.  
  190.     if (errorstring)
  191.     {
  192.     printf(errorstring);
  193.     exit(20);
  194.     }
  195.  
  196.     exit(0);
  197.     }
  198.  
  199.  
  200. /*----------------------------------------------------------------------*/
  201.