home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Programming / Misc / TRSICAT.LZX / CATS_CD2_TRSI / Reference_Library / lib_examples / appwindow.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-08-21  |  3.9 KB  |  108 lines

  1. /* This example shows how to create an AppWindow and obtain arguments
  2.  * from Workbench when the user drops an icon into it.  The AppWindow
  3.  * will appear on the Workbench screen with the name "AppWindow" and
  4.  * will run until the window's close gadget is selected.  If any icons
  5.  * are dropped into the AppWindow, the program prints their arguments in
  6.  * the Shell window.
  7.  */
  8.  
  9. /* appwindow.c - Compiled under SAS C 5.10 with lc -L appwindow.c           */
  10. /* Requires Kickstart version 37 or later.  Works from the Shell (CLI) only */
  11.  
  12. #include <exec/types.h>          /* Need this for the Amiga variable types  */
  13. #include <workbench/workbench.h> /* This has DiskObject and AppWindow       */
  14. #include <workbench/startup.h>   /* This has WBStartup and WBArg structs    */
  15. #include <exec/libraries.h>      /* Need this to check library versions     */
  16.  
  17. #include <stdio.h>
  18.  
  19. #include <clib/intuition_protos.h>
  20. #include <clib/exec_protos.h>
  21. #include <clib/wb_protos.h>
  22.  
  23. #ifdef LATTICE
  24. int CXBRK(void) { return(0); }   /* Disable SAS Lattice CTRL/C handling */
  25. int chkabort(void) { return(0); }/* really */
  26. #endif
  27.  
  28. struct Library      *IntuitionBase;
  29. struct Library      *WorkbenchBase;
  30.  
  31. void main(int argc, char **argv)
  32. {
  33.   struct MsgPort *awport;
  34.   struct Window  *win;
  35.   struct AppWindow *appwin;
  36.   struct IntuiMessage *imsg;
  37.   struct AppMessage *amsg;
  38.   struct WBArg   *argptr;
  39.  
  40.   ULONG           winsig, appwinsig, signals, id = 1, userdata = 0;
  41.   BOOL            done = FALSE;
  42.   int             i;
  43.  
  44.   if (IntuitionBase = OpenLibrary("intuition.library", 37))
  45.     {
  46.     if (WorkbenchBase = OpenLibrary("workbench.library", 37))
  47.       {
  48.       /* The CreateMsgPort() function is in Exec version 37 and later only */
  49.       if (awport = CreateMsgPort())
  50.          {
  51.          if (win = OpenWindowTags(NULL,
  52.                                   WA_Width, 200,        WA_Height, 50,
  53.                                   WA_IDCMP, CLOSEWINDOW,
  54.                                   WA_Flags, WINDOWCLOSE | WINDOWDRAG,
  55.                                   WA_Title, "AppWindow",
  56.                                   TAG_DONE))
  57.           {
  58.           if (appwin = AddAppWindow(id, userdata, win, awport, NULL))
  59.             {
  60.             printf("AppWindow added... Drag files into AppWindow\n");
  61.             winsig    = 1L << win->UserPort->mp_SigBit;
  62.             appwinsig = 1L << awport->mp_SigBit;
  63.  
  64.             while (! done)
  65.               {
  66.               /* Wait for IDCMP messages and AppMessages */
  67.               signals = Wait( winsig | appwinsig );
  68.  
  69.               if(signals & winsig)      /* Got an IDCMP message */
  70.                 {
  71.                 while (imsg = (struct IntuiMessage *) GetMsg(win->UserPort))
  72.                   {
  73.                   if (imsg->Class = CLOSEWINDOW)   done = TRUE;
  74.                   ReplyMsg((struct Message *) imsg);
  75.                   }
  76.                 }
  77.               if(signals & appwinsig)   /* Got an AppMessage */
  78.                 {
  79.                 while (amsg = (struct AppMessage *) GetMsg(awport))
  80.                   {
  81.                   printf("AppMsg: Type=%ld, ID=%ld, NumArgs=%ld\n",
  82.                            amsg->am_Type, amsg->am_ID, amsg->am_NumArgs);
  83.                   argptr = amsg->am_ArgList;
  84.                   for (i = 0; i < amsg->am_NumArgs; i++)
  85.                     {
  86.                     printf("   arg(%ld): Name='%s', Lock=%lx\n",
  87.                              i, argptr->wa_Name, argptr->wa_Lock);
  88.                     argptr++;
  89.                     }
  90.                   ReplyMsg((struct Message *) amsg);
  91.                   }
  92.                 }
  93.               }     /* done */
  94.             RemoveAppWindow(appwin);
  95.             }
  96.           CloseWindow(win);
  97.       }
  98.         /* Make sure there are no more outstanding messages */
  99.         while(amsg = (struct AppMessage *)GetMsg(awport))
  100.               ReplyMsg((struct Message *)amsg);
  101.         DeleteMsgPort(awport);
  102.         }
  103.       CloseLibrary(WorkbenchBase);
  104.       }
  105.     CloseLibrary(IntuitionBase);
  106.     }
  107. }
  108.