home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD v1.2 / amidev_cd_12.iso / reference / amiga_mail_vol2 / iv-3 / clonewb.c < prev    next >
C/C++ Source or Header  |  1996-01-30  |  8KB  |  191 lines

  1. ;/* CloneWB.c -  V36 Clone Workbench screen.  Compiled with SAS/C 6.56
  2. sc NMINC STRMERGE STREQ NOSTKCHK SAVEDS IGNORE=73 LINK CloneWB.c
  3. quit
  4.  
  5. Copyright (c) 1990 Commodore-Amiga, Inc.
  6.  
  7. This example is provided in electronic form by Commodore-Amiga,
  8. Inc. for use with the Amiga Mail Volume II technical publication.
  9. Amiga Mail Volume II contains additional information on the correct
  10. usage of the techniques and operating system functions presented in
  11. these examples.  The source and executable code of these examples may
  12. only be distributed in free electronic form, via bulletin board or
  13. as part of a fully non-commercial and freely redistributable
  14. diskette.  Both the source and executable code (including comments)
  15. must be included, without modification, in any copy.  This example
  16. may not be published in printed form or distributed with any
  17. commercial product. However, the programming techniques and support
  18. routines set forth in these examples may be used in the development
  19. of original executable software products for Commodore Amiga
  20. computers.
  21.  
  22. All other rights reserved.
  23.  
  24. This example is provided "as-is" and is subject to change; no
  25. warranties are made.  All use is at your own risk. No liability or
  26. responsibility is assumed.
  27. */
  28.  
  29. #include <stdio.h>
  30. #include <stdlib.h>
  31. #include <intuition/intuition.h>
  32. #include <intuition/screens.h>
  33. #include <graphics/displayinfo.h>
  34.  
  35. #include <clib/exec_protos.h>
  36. #include <clib/intuition_protos.h>
  37. #include <clib/graphics_protos.h>
  38.  
  39. #include <pragmas/exec_pragmas.h>
  40. #include <pragmas/intuition_pragmas.h>
  41. #include <pragmas/graphics_pragmas.h>
  42.  
  43. struct IntuitionBase *IntuitionBase;
  44. struct GfxBase *GfxBase;
  45. extern struct Library *SysBase;
  46.  
  47. struct EasyStruct failedES = {
  48.     sizeof(struct EasyStruct), 0, "CWB",
  49.     "%s",
  50.     "OK",
  51. };
  52.  
  53. void            main(void);
  54.  
  55. void
  56. main(void)
  57. {
  58.     struct Screen *wbscreen;
  59.     struct Screen *clonescreen;
  60.     struct Window *window;
  61.     struct ViewPort *vp;
  62.     struct IntuiMessage *msg;
  63.     ULONG modeID;
  64.  
  65.     struct DisplayInfo displayinfo;
  66.     struct MonitorInfo monitorinfo;
  67.     struct DimensionInfo dimensioninfo;
  68.     struct NameInfo nameinfo;
  69.     struct DrawInfo *drawinfo;
  70.  
  71.     ULONG result;
  72.  
  73.     /* Fails silently when not V36 */
  74.     if (IntuitionBase = OpenLibrary("intuition.library", 36)) {
  75.         if (GfxBase = OpenLibrary("graphics.library", 36)) {
  76.  
  77.             if (wbscreen = LockPubScreen("Workbench")) {
  78.                 /* Using intuition.library/GetScreenDrawInfo(), we get the pen
  79.                  * array we'll use for the screen clone the easy way. */
  80.                 drawinfo = GetScreenDrawInfo(wbscreen);
  81.  
  82.                 vp = &(wbscreen->ViewPort);
  83.                 /* Use graphics.library/GetVPModeID() to get the ModeID of the
  84.                  * Workbench screen. */
  85.                 if ((modeID = GetVPModeID(vp)) != INVALID_ID) {
  86.                     /* OK, we got a valid ModeID for the Workbench
  87.                      * screen (surprise) */
  88.  
  89.                     /* With just the ModeID, the lock on the Workbench
  90.                      * screen & drawinfo->dri_Pens we're able to clone the
  91.                      * Workbench exactly, displaymode and all. When you want
  92.                      * to know everything there is to know about this
  93.                      * displaymode, use graphics.library/GetDisplayInfoData().
  94.                      */
  95.                     /* 'result' is the actual # of bytes copies
  96.                      * into the buffer.
  97.                      * See graphics/displayinfo.h for definitions
  98.                      * of the various structures.
  99.                      */
  100.                     result = GetDisplayInfoData(NULL,
  101.                                                 (UBYTE *)&monitorinfo,
  102.                                                 sizeof(struct MonitorInfo),
  103.                                                 DTAG_MNTR, modeID);
  104.                     result = GetDisplayInfoData(NULL,
  105.                                                 (UBYTE *)&displayinfo,
  106.                                                 sizeof(struct DisplayInfo),
  107.                                                 DTAG_DISP, modeID);
  108.                     result = GetDisplayInfoData(NULL,
  109.                                                 (UBYTE *)&dimensioninfo,
  110.                                                 sizeof(struct DimensionInfo),
  111.                                                 DTAG_DIMS,
  112.                                                 modeID);
  113.                     result = GetDisplayInfoData(NULL,
  114.                                                 (UBYTE *)&nameinfo,
  115.                                                 sizeof(struct NameInfo),
  116.                                                 DTAG_NAME,
  117.                                                 modeID);
  118.  
  119.                     /* If you don't want to clone the workbench exactly,
  120.                      * you could use one of the other overscan modes
  121.                      * and/or min/max.
  122.                      * dimensions in dimensioninfo or open a regular screen.
  123.                      */
  124.                     if (clonescreen = OpenScreenTags(NULL,
  125.                         /* Could use STDSCREENWIDTH/HEIGHT for non-scrollable
  126.                          * screens. Those make */
  127.                         SA_Width, wbscreen->Width,
  128.  
  129.                         /* OpenScreen() use the textoverscan values */
  130.                         SA_Height, wbscreen->Height,
  131.  
  132.                         SA_DisplayID, modeID,
  133.  
  134.                         SA_Depth, wbscreen->BitMap.Depth,
  135.  
  136.                         /*Workbench always sizes up to OSCAN_TEXT, so do we */
  137.                         SA_Overscan, OSCAN_TEXT,
  138.  
  139.                         SA_Pens, drawinfo->dri_Pens,
  140.  
  141.                         SA_Title, nameinfo.Name,
  142.  
  143.                         /* Doesn't hurt for screens which don't scroll */
  144.                         SA_AutoScroll, TRUE,
  145.  
  146.                         TAG_END)) {
  147.  
  148.                         if (window = OpenWindowTags(NULL,
  149.                             WA_Top, clonescreen->BarHeight + 1,
  150.                             WA_Height, clonescreen->Height
  151.                                                 - (clonescreen->BarHeight + 1),
  152.                             WA_CustomScreen, clonescreen,
  153.                             WA_MinWidth, 320,
  154.                             WA_MinHeight, 100,
  155.                             WA_MaxWidth, clonescreen->Width,
  156.                             WA_MaxHeight, clonescreen->Height,
  157.  
  158.                             /* I'm only interested in CLOSEWINDOW messages */
  159.                             WA_IDCMP, CLOSEWINDOW,
  160.                             WA_Flags, WINDOWSIZING|WINDOWDRAG|
  161.                                            WINDOWDEPTH|WINDOWCLOSE|ACTIVATE,
  162.                             WA_Title, "Close to exit.",
  163.                             TAG_END)) {
  164.  
  165.                             /* Wait for the closewindow message */
  166.                             WaitPort(window->UserPort);
  167.                             /* And remove message from the port */
  168.                             while(msg = (struct IntuiMessage *)
  169.                                   GetMsg(window->UserPort))
  170.                                 ReplyMsg((struct Message *)msg);
  171.                             CloseWindow(window);
  172.                         } else
  173.                             EasyRequest(NULL, &failedES, NULL,
  174.                                         "Can't open window");
  175.                         CloseScreen(clonescreen);
  176.                     } else
  177.                         EasyRequest(NULL, &failedES, NULL,
  178.                                     "Can't open screen");
  179.                 } else
  180.                     EasyRequest(NULL, &failedES, NULL, "Invalide ModeID");
  181.                 FreeScreenDrawInfo(wbscreen, drawinfo);
  182.                 UnlockPubScreen(NULL, wbscreen);
  183.             } else
  184.                 EasyRequest(NULL, &failedES, NULL,
  185.                             "Can't lock Workbench screen");
  186.             CloseLibrary(GfxBase);
  187.         }
  188.         CloseLibrary(IntuitionBase);
  189.     }
  190. }
  191.