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

  1. /* The example listed here shows how to create an AppIcon and obtain
  2.  * arguments from Workbench when the user drops other icons on top of
  3.  * it. The AppIcon will appear as a disk icon named "TestAppIcon" on the
  4.  * Workbench screen.  (All AppIcons appear on the Workbench screen or
  5.  * window.)
  6.  *
  7.  * For convenience, this example code uses GetDefDiskObject() to create
  8.  * the icon imagery for the AppIcon.  Applications should never do this.
  9.  * Use your own custom imagery for AppIcons instead.
  10.  */
  11.  
  12. /* appicon.c - Compiled under SAS C 5.10 with lc -L appicon.c               */
  13. /* Requires Kickstart version 37 or later.  Works from the Shell (CLI) only */
  14.  
  15. #include <exec/types.h>          /* Need this for the Amiga variable types  */
  16. #include <workbench/workbench.h> /* This has DiskObject and AppIcon structs */
  17. #include <workbench/startup.h>   /* This has WBStartup and WBArg structs    */
  18. #include <exec/libraries.h>      /* Need this to check library versions     */
  19.  
  20. #include <clib/icon_protos.h>    /* Icon (DiskObject) function prototypes   */
  21. #include <clib/exec_protos.h>    /* Exec message, port and library functions*/
  22. #include <clib/wb_protos.h>      /* AppIcon function protos                 */
  23.  
  24. #ifdef LATTICE
  25. int CXBRK(void) { return(0); }   /* Disable SAS Lattice CTRL/C handling */
  26. int chkabort(void) { return(0); }/* really */
  27. #endif
  28.  
  29. extern struct Library *SysBase;
  30. struct Library *IconBase;
  31. struct Library *WorkbenchBase;
  32.  
  33. void main(int argc, char **argv)
  34. {
  35. struct DiskObject   *dobj=NULL;
  36. struct MsgPort    *myport=NULL;
  37. struct AppIcon   *appicon=NULL;
  38. struct AppMessage *appmsg=NULL;
  39.  
  40. LONG dropcount=0L;
  41. ULONG x;
  42. BOOL success=0L;
  43.  
  44. /* Get the the right version of the Icon Library, initialize IconBase */
  45. if(IconBase = OpenLibrary("icon.library",37))
  46.   {
  47.   /* Get the the right version of the Workbench Library */
  48.   if (WorkbenchBase=OpenLibrary("workbench.library",37))
  49.     {
  50.     /* This is the easy way to get some icon imagery */
  51.     /* Real applications should use custom imagery   */
  52.     dobj=GetDefDiskObject(WBDISK);
  53.     if(dobj!=0)
  54.       {
  55.       /* The type must be set to NULL for a WBAPPICON */
  56.       dobj->do_Type=NULL;
  57.  
  58.       /* The CreateMsgPort() function is in Exec version 37 and later only */
  59.       myport=CreateMsgPort();
  60.       if(myport)
  61.         {
  62.         /* Put the AppIcon up on the Workbench window */
  63.         appicon=AddAppIconA(0L,0L,"TestAppIcon",myport,NULL,dobj,NULL);
  64.         if(appicon)
  65.           {
  66.           /* For the sake of this example, we allow the AppIcon */
  67.           /* to be activated only five times.                   */
  68.           printf("Drop files on the Workbench AppIcon\n");
  69.           printf("Example exits after 5 drops\n");
  70.  
  71.           while(dropcount<5)
  72.             {
  73.             /* Here's the main event loop where we wait for */
  74.             /* messages to show up from the AppIcon         */
  75.             WaitPort(myport);
  76.  
  77.             /* Might be more than one message at the port... */
  78.             while(appmsg=(struct AppMessage *)GetMsg(myport))
  79.               {
  80.               if(appmsg->am_NumArgs==0L)
  81.                 {
  82.                 /* If NumArgs is 0 the AppIcon was activated directly */
  83.                 printf("User activated the AppIcon.\n");
  84.                 printf("A Help window for the user would be good here\n");
  85.                 }
  86.               else if(appmsg->am_NumArgs>0L)
  87.                 {
  88.                 /* If NumArgs is >0 the AppIcon was activated by */
  89.                 /* having one or more icons dropped on top of it */
  90.                 printf("User dropped %ld icons on the AppIcon\n",
  91.                                               appmsg->am_NumArgs);
  92.                 for(x=0;x<appmsg->am_NumArgs;x++)
  93.                   {
  94.                   printf("#%ld name='%s'\n",x+1,appmsg->am_ArgList[x].wa_Name);
  95.                   }
  96.                 }
  97.               /* Let Workbench know we're done with the message */
  98.               ReplyMsg((struct Message *)appmsg);
  99.               }
  100.             dropcount++;
  101.             }
  102.           success=RemoveAppIcon(appicon);
  103.           }
  104.         /* Clear away any messages that arrived at the last moment */
  105.         while(appmsg=(struct AppMessage *)GetMsg(myport))
  106.             ReplyMsg((struct Message *)appmsg);
  107.         DeleteMsgPort(myport);
  108.         }
  109.       FreeDiskObject(dobj);
  110.       }
  111.     CloseLibrary(WorkbenchBase);
  112.     }
  113.   CloseLibrary(IconBase);
  114.   }
  115. }
  116.