home *** CD-ROM | disk | FTP | other *** search
/ Amiga MA Magazine 1998 #6 / amigamamagazinepolishissue1998.iso / coders / ibase / ibase.c < prev    next >
C/C++ Source or Header  |  1996-11-02  |  4KB  |  99 lines

  1. /* IBase.c
  2.  * programmed by DC Ross (e-mail: dcross@mail.netshop.net)
  3.  * 96-11-02
  4.  *
  5.  * Description:
  6.  *   This is a little programme I wrote today to test the functions LockIBase()
  7.  * and UnlockIBase().  By using a copy of IntuitionBase, you can access quite a
  8.  * few useful feature of Intuition, such as the addresses of all Intuition
  9.  * Screens and Windows (should work with CUSTOM and PUBLIC screens; I have only
  10.  * tested PUBLIC).  Handy if you want your window to open on a screen with a
  11.  * specific name.
  12.  *   I haven't bothered to look through my old Workbench 1.3 Includes to see
  13.  * if this can be made to work on Workbench 1.2/1.3.  If I ever feel I need
  14.  * this programme on my Workbench 1.3 A500 I will try to figure it out, but
  15.  * until then, you are on your own for Wb1.3 compatability.
  16.  *   This code was created using the very sparce information in the ROM Kernal
  17.  * Reference Manual: Libraries 3rd Edition for Workbench 2.04.  The information
  18.  * can be found in Chapter 11: Intuition Special Functions on page 283.
  19.  *   Send any comments, bug reports, suggestions, etc. to me via e-mail:
  20.  * dcross@mail.netshop.net.
  21.  *
  22.  * Compiling:
  23.  *   Used SAS/C 6.00 with the default options in SCOptions.  Doesn't need math
  24.  * or any other special options set.
  25.  *
  26.  * Requirements:
  27.  *   Workbench/Kickstart 2.x+ (tested on Wb3.0)
  28.  *   Any CPU
  29.  *   256K+ memory
  30.  *
  31.  * Release Notes:
  32.  *   This small example programme is placed on the Public Domain.  I accept no
  33.  * responsibility for any damage/loss.  Use at your own risk.
  34.  *   Feel free to use any/all of this code in your own work.
  35.  */
  36.  
  37. #define INTUI_V36_NAMES_ONLY
  38.  
  39. #include <StdIo.h>
  40. #include <cLib/Exec_protos.h>
  41. #include <Exec/Types.h>
  42. #include <cLib/Intuition_protos.h>
  43. #include <Intuition/IntuitionBase.h>
  44. #include <Intuition/Intuition.h>
  45. #include <Intuition/Screens.h>
  46.  
  47. UBYTE vers[] = "$VER: IBase (96-11-02)";
  48.  
  49. struct IntuitionBase *IntuitionBase;    /* needed to open intuition.library */
  50. struct IntuitionBase *CopyIBase;    /* used to store copy of IntuitionBase */
  51. struct Screen *Scrn;    /* used for accessing screen structures */
  52. struct Window *Win;    /* used for accessing window structures */
  53.  
  54. VOID main(VOID)
  55. {
  56.     ULONG iLock = NULL;    /* needed for LockIBase()/UnlockIBase() */
  57.  
  58.     if(IntuitionBase = OpenLibrary("intuition.library", 0L))
  59.     {
  60.         iLock = LockIBase(0L);    /* lock IntuitionBase; don't fail if gives zero */
  61.         /* copy all the IntuitionBase data to own structure */
  62.         CopyIBase->ViewLord = IntuitionBase->ViewLord;    /* not sure what this does */
  63.         CopyIBase->ActiveWindow = IntuitionBase->ActiveWindow;
  64.         CopyIBase->ActiveScreen = IntuitionBase->ActiveScreen;
  65.         CopyIBase->FirstScreen = IntuitionBase->FirstScreen;
  66.         CopyIBase->MouseY = IntuitionBase->MouseY;    /* other functions get this information also */
  67.         CopyIBase->MouseX = IntuitionBase->MouseX;    /*                    ""                     */
  68.         CopyIBase->Seconds = IntuitionBase->Seconds;
  69.         CopyIBase->Micros = IntuitionBase->Micros;
  70.         UnlockIBase(iLock);    /* unlock IntuitionBase so other programmes can use Intuition */
  71.  
  72.         printf("View Lord:  0x%X\n", CopyIBase->ViewLord);
  73.         printf("Active Screen:  %s (0x%X)\n", CopyIBase->ActiveScreen->Title, CopyIBase->ActiveScreen);
  74.         printf("Active Window:  %s (0x%X)\n", CopyIBase->ActiveWindow->Title, CopyIBase->ActiveWindow);
  75.         printf("Mouse X/Y:  0x%X, 0x%X\n", CopyIBase->MouseX, CopyIBase->MouseY);
  76.         printf("Seconds/Micros:  0x%X, 0x%X\n\n", CopyIBase->Seconds, CopyIBase->Micros);
  77.  
  78.         /* search through the screen & window structures to display info */
  79.         Scrn = CopyIBase->FirstScreen;
  80.         Win = Scrn->FirstWindow;
  81.         while(Scrn != NULL)
  82.         {
  83.             printf("Screen:  %s (0x%X)\n", Scrn->Title, Scrn);
  84.  
  85.             while(Win != NULL)
  86.             {
  87.                 printf(" Window:  %s (0x%X)\n", Win->Title, Win);
  88.  
  89.                 Win = Win->NextWindow;
  90.             };    /* while */
  91.  
  92.             Scrn = Scrn->NextScreen;
  93.             Win = Scrn->FirstWindow;
  94.         };    /* while */
  95.  
  96.         CloseLibrary(IntuitionBase);
  97.     };    /* if */
  98. }    /* main() */
  99.