home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 8 / FreshFishVol8-CD1.bin / useful / dev / c / rkrm / workbench / appicon.c < prev    next >
C/C++ Source or Header  |  1992-09-03  |  5KB  |  133 lines

  1. ;/* appicon.c - Compiled under SAS C 5.10 with:
  2. lc -L -j73 appicon.c
  3. quit
  4. */
  5. /* Requires Kickstart version 37 or later.  Works from the Shell (CLI) only */
  6. /*
  7. Copyright (c) 1992 Commodore-Amiga, Inc.
  8.  
  9. This example is provided in electronic form by Commodore-Amiga, Inc. for
  10. use with the "Amiga ROM Kernel Reference Manual: Libraries", 3rd Edition,
  11. published by Addison-Wesley (ISBN 0-201-56774-1).
  12.  
  13. The "Amiga ROM Kernel Reference Manual: Libraries" contains additional
  14. information on the correct usage of the techniques and operating system
  15. functions presented in these examples.  The source and executable code
  16. of these examples may only be distributed in free electronic form, via
  17. bulletin board or as part of a fully non-commercial and freely
  18. redistributable diskette.  Both the source and executable code (including
  19. comments) must be included, without modification, in any copy.  This
  20. example may not be published in printed form or distributed with any
  21. commercial product.  However, the programming techniques and support
  22. routines set forth in these examples may be used in the development
  23. of original executable software products for Commodore Amiga computers.
  24.  
  25. All other rights reserved.
  26.  
  27. This example is provided "as-is" and is subject to change; no
  28. warranties are made.  All use is at your own risk. No liability or
  29. responsibility is assumed.
  30. */
  31.  
  32. #include <exec/types.h>          /* Need this for the Amiga variable types  */
  33. #include <workbench/workbench.h> /* This has DiskObject and AppIcon structs */
  34. #include <workbench/startup.h>   /* This has WBStartup and WBArg structs    */
  35. #include <exec/libraries.h>      /* Need this to check library versions     */
  36.  
  37. #include <clib/icon_protos.h>    /* Icon (DiskObject) function prototypes   */
  38. #include <clib/exec_protos.h>    /* Exec message, port and library functions*/
  39. #include <clib/wb_protos.h>      /* AppIcon function protos                 */
  40.  
  41. #ifdef LATTICE
  42. int CXBRK(void) { return(0); }   /* Disable SAS Lattice CTRL/C handling */
  43. int chkabort(void) { return(0); }/* really */
  44. #endif
  45.  
  46. extern struct Library *SysBase;
  47. struct Library *IconBase;
  48. struct Library *WorkbenchBase;
  49.  
  50. void main(int argc, char **argv)
  51. {
  52. struct DiskObject   *dobj=NULL;
  53. struct MsgPort    *myport=NULL;
  54. struct AppIcon   *appicon=NULL;
  55. struct AppMessage *appmsg=NULL;
  56.  
  57. LONG dropcount=0L;
  58. ULONG x;
  59. BOOL success=0L;
  60.  
  61. /* Get the the right version of the Icon Library, initialize IconBase */
  62. if(IconBase = OpenLibrary("icon.library",37))
  63.   {
  64.   /* Get the the right version of the Workbench Library */
  65.   if (WorkbenchBase=OpenLibrary("workbench.library",37))
  66.     {
  67.     /* This is the easy way to get some icon imagery */
  68.     /* Real applications should use custom imagery   */
  69.     dobj=GetDefDiskObject(WBDISK);
  70.     if(dobj!=0)
  71.       {
  72.       /* The type must be set to NULL for a WBAPPICON */
  73.       dobj->do_Type=NULL;
  74.  
  75.       /* The CreateMsgPort() function is in Exec version 37 and later only */
  76.       myport=CreateMsgPort();
  77.       if(myport)
  78.         {
  79.         /* Put the AppIcon up on the Workbench window */
  80.         appicon=AddAppIconA(0L,0L,"TestAppIcon",myport,NULL,dobj,NULL);
  81.         if(appicon)
  82.           {
  83.           /* For the sake of this example, we allow the AppIcon */
  84.           /* to be activated only five times.                   */
  85.           printf("Drop files on the Workbench AppIcon\n");
  86.           printf("Example exits after 5 drops\n");
  87.  
  88.           while(dropcount<5)
  89.             {
  90.             /* Here's the main event loop where we wait for */
  91.             /* messages to show up from the AppIcon         */
  92.             WaitPort(myport);
  93.  
  94.             /* Might be more than one message at the port... */
  95.             while(appmsg=(struct AppMessage *)GetMsg(myport))
  96.               {
  97.               if(appmsg->am_NumArgs==0L)
  98.                 {
  99.                 /* If NumArgs is 0 the AppIcon was activated directly */
  100.                 printf("User activated the AppIcon.\n");
  101.                 printf("A Help window for the user would be good here\n");
  102.                 }
  103.               else if(appmsg->am_NumArgs>0L)
  104.                 {
  105.                 /* If NumArgs is >0 the AppIcon was activated by */
  106.                 /* having one or more icons dropped on top of it */
  107.                 printf("User dropped %ld icons on the AppIcon\n",
  108.                                               appmsg->am_NumArgs);
  109.                 for(x=0;x<appmsg->am_NumArgs;x++)
  110.                   {
  111.                   printf("#%ld name='%s'\n",x+1,appmsg->am_ArgList[x].wa_Name);
  112.                   }
  113.                 }
  114.               /* Let Workbench know we're done with the message */
  115.               ReplyMsg((struct Message *)appmsg);
  116.               }
  117.             dropcount++;
  118.             }
  119.           success=RemoveAppIcon(appicon);
  120.           }
  121.         /* Clear away any messages that arrived at the last moment */
  122.         while(appmsg=(struct AppMessage *)GetMsg(myport))
  123.             ReplyMsg((struct Message *)appmsg);
  124.         DeleteMsgPort(myport);
  125.         }
  126.       FreeDiskObject(dobj);
  127.       }
  128.     CloseLibrary(WorkbenchBase);
  129.     }
  130.   CloseLibrary(IconBase);
  131.   }
  132. }
  133.