home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD v1.2 / amidev_cd_12.iso / reference / amiga_mail_vol2 / iv-59 / appicon.c < prev    next >
C/C++ Source or Header  |  1996-01-30  |  5KB  |  151 lines

  1. ;/* AppIcon.c - Execute me to compile me with SAS/C 6.56
  2. sc NMINC STRMERGE NOSTKCHK NODEBUG DATA=NEAR IGNORE=73 AppIcon.c
  3. slink FROM LIB:c.o,AppIcon.o TO AppIcon LIBRARY LIB:sc.lib,LIB:Amiga.lib
  4. quit
  5. */
  6. /*
  7. Copyright (c) 1991 Commodore-Amiga, Inc.
  8.  
  9. This example is provided in electronic form by Commodore-Amiga,
  10. Inc. for use with the Amiga Mail Volume II technical publication.
  11. Amiga Mail Volume II contains additional information on the correct
  12. usage of the techniques and operating system functions presented in
  13. these examples.  The source and executable code of these examples may
  14. only be distributed in free electronic form, via bulletin board or
  15. as part of a fully non-commercial and freely redistributable
  16. diskette.  Both the source and executable code (including comments)
  17. must be included, without modification, in any copy.  This example
  18. may not be published in printed form or distributed with any
  19. commercial product. However, the programming techniques and support
  20. routines set forth in these examples may be used in the development
  21. of original executable software products for Commodore Amiga
  22. computers.
  23.  
  24. All other rights reserved.
  25.  
  26. This example is provided "as-is" and is subject to change; no
  27. warranties are made.  All use is at your own risk. No liability or
  28. responsibility is assumed.
  29. */
  30.  
  31. #include <intuition/intuition.h>
  32. #include <exec/memory.h>
  33. #include <workbench/startup.h>
  34. #include <workbench/workbench.h>
  35.  
  36. #include "appicon.h"
  37.  
  38. #ifdef LATTICE
  39. #include <stdio.h>
  40.  
  41. /* disable SAS/C CTRL-C handing */
  42. int
  43. CXBRK(void)
  44. {
  45.     return (0);
  46. }
  47. int
  48. chkabort(void)
  49. {
  50.     return (0);
  51. }
  52.  
  53. #include <clib/exec_protos.h>
  54. #include <clib/intuition_protos.h>
  55. #include <clib/wb_protos.h>
  56. #endif
  57.  
  58. struct IntuitionBase *IntuitionBase;
  59. struct WorkbenchBase *WorkbenchBase;
  60.  
  61. void            main(void);
  62.  
  63. void
  64. main(void)
  65. {
  66.     struct MsgPort *msgport;
  67.     struct Window  *window;
  68.     struct AppIcon *appicon;
  69.     struct IntuiMessage *imsg;
  70.     struct AppMessage *appmsg;
  71.     struct WBArg   *argptr;
  72.  
  73.     ULONG           id = 1, userdata = 0;
  74.     BOOL            ABORT = FALSE;
  75.     UCOUNT          i;
  76.  
  77.  
  78.     /* Open needed libraries. Fail silently if < 36 */
  79.     if (IntuitionBase = OpenLibrary("intuition.library", 36))
  80.     {
  81.         if (WorkbenchBase = OpenLibrary("workbench.library", 36))
  82.         {
  83.             if (msgport = CreateMsgPort())
  84.             {
  85.                 if (window =
  86.                     OpenWindowTags(NULL, WA_Left, 0, WA_Top, 1, WA_Width, 160,
  87.                                    WA_Height, 50, WA_IDCMP, CLOSEWINDOW,
  88.                                    WA_Flags, WINDOWCLOSE | WINDOWDRAG,
  89.                                    WA_Title, "AppIcon", TAG_END))
  90.                 {
  91.  
  92.                     /* Add the icon to Workbench */
  93.                     if (appicon = AddAppIcon(id, userdata, "AppIcon",
  94.                         msgport, NULL, &AppIconDObj, NULL))
  95.                     {
  96.                         do
  97.                         {
  98.                             Wait(1 << window->UserPort->mp_SigBit |
  99.                                 1 << msgport->mp_SigBit);
  100.                             while (imsg = (struct IntuiMessage *)
  101.                                 GetMsg(window->UserPort))
  102.                             {
  103.                                 if (imsg->Class = CLOSEWINDOW)
  104.                                     ABORT = TRUE;
  105.                                 ReplyMsg((struct Message *) imsg);
  106.                             }
  107.                             while (appmsg = (struct AppMessage *) GetMsg(msgport))
  108.                             {
  109.                                 printf(
  110.                        "ai: appmsg=%lx, Type=%ld, ID=%ld, UserData=%ld, NumArgs=%ld\n",
  111.                                        appmsg, appmsg->am_Type, appmsg->am_ID,
  112.                                        appmsg->am_UserData, appmsg->am_NumArgs);
  113.                                 argptr = appmsg->am_ArgList;
  114.  
  115.                                 /*
  116.                                  * If am->NumArgs is zero the user
  117.                                  * double-clicked on our icon, otherwise one or
  118.                                  * more icons were dropped on top of it.
  119.                                  */
  120.                                 for (i = 0; i < appmsg->am_NumArgs; i++)
  121.                                 {
  122.                                     printf("\targ(%ld): Name='%s', Lock=%lx\n",
  123.                                     i, argptr->wa_Name, argptr->wa_Lock);
  124.                                     argptr++;
  125.                                 }
  126.                                 ReplyMsg((struct Message *) appmsg);
  127.                             }
  128.                         } while (ABORT == FALSE);
  129.                         /* Remove the AppIcon and clean up */
  130.                         RemoveAppIcon(appicon);
  131.                     }
  132.                     else
  133.                         printf("Couldn't add AppIcon\n");
  134.                     CloseWindow(window);
  135.                 }
  136.                 else
  137.                     printf("Couldn't open window\n");
  138.                 DeleteMsgPort(msgport);
  139.             }
  140.             else
  141.                 printf("Couldn't create messageport\n");
  142.             CloseLibrary(WorkbenchBase);
  143.         }
  144.         else
  145.             printf("Couldn't open workbench.library\n");
  146.         CloseLibrary(IntuitionBase);
  147.     }
  148.     else
  149.         printf("Couldn't open intuition.library\n");
  150. }
  151.