home *** CD-ROM | disk | FTP | other *** search
/ Amiga MA Magazine 1998 #6 / amigamamagazinepolishissue1998.iso / opus / v4 / opus-geil / closewindow.lha / CloseWindow.doc < prev   
Text File  |  1994-03-28  |  3KB  |  104 lines

  1. /*CloseWindow v0.2 by Lars Dannenberg (21.03.94) L.DANNENBERG@KDS.ZER.SUB.ORG
  2.  
  3.  schließt ein beliebiges Fenster auf einem PubScreen
  4.  
  5.  Syntax: CloseWindow <Screenname> <Windowname>
  6.  
  7.                                       (Groß- und Kleinschreibung beachten)
  8.  
  9.  das Ganze läuft systemkonform ab:
  10.  
  11.  an das Fenster wird ein InputEvent IECLASS_CLOSEWINDOW
  12.  gesendet, also kein intuition/CloseWindow()-Hack wie mit
  13.  anderen Programmen.
  14.  
  15. */
  16.  
  17.  
  18. #include <exec/types.h>
  19. #include <exec/memory.h>
  20. #include <exec/io.h>
  21. #include <devices/input.h>
  22. #include <devices/inputevent.h>
  23. #include <intuition/intuition.h>
  24.  
  25. #include <clib/exec_protos.h>
  26. #include <clib/intuition_protos.h>
  27.  
  28. #include <stdio.h>
  29.  
  30. #define LIBVER 37 /* Brauche OS>=2.0 !!! */
  31.  
  32. struct Library *IntuitionBase = NULL;
  33.  
  34.  
  35. int main(int argc,char *argv[])
  36. {
  37.     struct MsgPort *InputMP;
  38.     struct IOStdReq *InputIO;
  39.     struct Screen *ScreenPtr;
  40.     struct Window *WindowPtr;
  41.     struct InputEvent myevent;
  42.  
  43.     BOOL    window_found = FALSE;
  44.  
  45.     if((argc==3))
  46.     {
  47.       if((IntuitionBase = (struct Library*) OpenLibrary("intuition.library",LIBVER)))
  48.       {
  49.         if((InputMP = (struct MsgPort*)  CreateMsgPort()))
  50.         {
  51.           if((InputIO = (struct IOStdReq*) CreateIORequest(InputMP,sizeof(struct IOStdReq))))
  52.           {
  53.             if(!(OpenDevice("input.device",0,(struct IORequest*) InputIO,0)))
  54.             {
  55.               if((ScreenPtr = (struct Screen*) LockPubScreen(argv[1])))
  56.               {
  57.                 WindowPtr=ScreenPtr->FirstWindow;       /*Zeiger auf 1.Window*/
  58.                 while ((!window_found) && (WindowPtr))  /*Window suchen bis
  59.                                                           gefunden oder letztes Window */
  60.  
  61.                 {
  62.                   if(!(strcmp(argv[2],WindowPtr->Title)))
  63.                      window_found=TRUE;
  64.                   /* Stimmt der Titel überein ? */
  65.                   else WindowPtr=WindowPtr->NextWindow;
  66.                   /* Nein, dann nächstes */
  67.                 }
  68.                 if (window_found)
  69.                 {
  70.                     if (WindowPtr->Flags & WFLG_CLOSEGADGET)
  71.                     {
  72.                         Forbid();
  73.                         ActivateWindow(WindowPtr);
  74.  
  75.                         InputIO->io_Data=&myevent;
  76.                         InputIO->io_Length=sizeof (struct InputEvent);
  77.                         InputIO->io_Command=IND_WRITEEVENT;
  78.                         myevent.ie_Class=IECLASS_CLOSEWINDOW;
  79.                         DoIO((struct IORequest*) InputIO);
  80.                         /* IORequest abschicken */
  81.                         Permit();
  82.                     }
  83.                     else printf("Fenster \"%s\" hat kein CloseGadget !\n",argv[2]);
  84.                 }
  85.                 else printf("Kann Fenster \"%s\" nicht finden !\n",argv[2]);
  86.                 UnlockPubScreen(NULL,ScreenPtr);
  87.               }
  88.               else printf("Bekomme keinen Lock auf Screen \"%s\" !\n",argv[1]);
  89.               CloseDevice((struct IORequest*) InputIO);
  90.             }
  91.             else printf("Kann input.device nicht öffnen !\n");
  92.           DeleteMsgPort(InputMP);
  93.           DeleteIORequest(InputIO);
  94.         }
  95.         else printf("Kann keinen IORequest erstellen !\n");
  96.       }
  97.       else printf("Kann keinen MessagePort öffnen !\n");
  98.       CloseLibrary(IntuitionBase);
  99.     }
  100.     else printf("Kann intuition.library v%d nicht öffnen !\n",LIBVER);
  101.   }
  102.   else printf("Usage: %s <ScreenName> <Windowname>\n",argv[0]);
  103. }
  104.