home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD 2.1 / Amiga Developer CD v2.1.iso / Reference / DevCon / Atlanta_1990 / Atlanta-Devcon.1 / Libraries / Workbench / AppIcon.c next >
Encoding:
C/C++ Source or Header  |  1992-08-26  |  4.0 KB  |  121 lines

  1. /***********************************************************************
  2.  *                                                                     *
  3.  *                            COPYRIGHTS                               *
  4.  *                                                                     *
  5.  *   Copyright (c) 1990  Commodore-Amiga, Inc.  All Rights Reserved.   *
  6.  *                                                                     *
  7.  **********************************************************************/
  8.  
  9. /*
  10.  * Code to test AppIcon feature of Workbench
  11.  */
  12.  
  13. #include <intuition/intuition.h>
  14. #include <exec/memory.h>
  15. #include <workbench/startup.h>
  16. #include <workbench/workbench.h>
  17.  
  18. #include <stdio.h>
  19.  
  20. #include <clib/exec_protos.h>
  21. #include <clib/intuition_protos.h>
  22. #include <clib/icon_protos.h>
  23. #include <clib/wb_protos.h>
  24. #include <clib/dos_protos.h>
  25.  
  26.  
  27. #include "appicon.image"
  28.  
  29. struct IntuitionBase *IntuitionBase;
  30. struct WorkbenchBase *WorkbenchBase;
  31. struct IconBase *IconBase;
  32.  
  33. void            main(void);
  34.  
  35. void 
  36. main(void)
  37. {
  38.   struct MsgPort *msgport;
  39.   struct Window  *win;
  40.   struct AppIcon *ai;
  41.   struct IntuiMessage *imsg;
  42.   struct AppMessage *amsg;
  43.   struct WBArg   *argptr;
  44.   struct DiskObject *dobj;
  45.  
  46.   ULONG           id = 1, userdata = 0;
  47.   BOOL            done = FALSE;
  48.   int             i, imagememsize = 0;
  49.  
  50.   printf("ai: enter\n");
  51.  
  52.   if (IntuitionBase = OpenLibrary("intuition.library", 36)) {
  53.     if (WorkbenchBase = OpenLibrary("workbench.library", 36)) {
  54.       if (IconBase = OpenLibrary("icon.library", 36)) {
  55.     if (msgport = CreateMsgPort()) {
  56.       if (win = OpenWindowTags(NULL,
  57.                    WA_Left, 0,
  58.                    WA_Top, 1,
  59.                    WA_Width, 160,
  60.                    WA_Height, 50,
  61.                    WA_IDCMP, CLOSEWINDOW,
  62.                    WA_Flags, WINDOWCLOSE | WINDOWDRAG,
  63.                    WA_Title, "AppIcon",
  64.                    TAG_END)) {
  65.         if (dobj = GetDiskObject(NULL)) {
  66.           dobj->do_Gadget.Width = image1.Width;
  67.           dobj->do_Gadget.Height = image1.Height;
  68.           dobj->do_Gadget.GadgetRender = &image1;
  69.           imagememsize = (image1.Width * image1.Height * image1.Depth) / 8;
  70.           if (image1.ImageData = (USHORT *) AllocMem(imagememsize, MEMF_CHIP)) {
  71.         CopyMem(imageData1, image1.ImageData, imagememsize);
  72.                 printf("ai: calling AddAppIcon...\n");
  73.         if (ai = AddAppIcon(id, userdata, "AppIcon", msgport, NULL, dobj, NULL)) {
  74.                   printf("ai: ok, ai = %lx, going to sleep\n", ai);
  75.           do {
  76.             Wait(1 << win->UserPort->mp_SigBit | 1 << msgport->mp_SigBit);
  77.             while (imsg = (struct IntuiMessage *) GetMsg(win->UserPort)) {
  78.               if (imsg->Class = CLOSEWINDOW)
  79.             done = TRUE;
  80.               ReplyMsg((struct Message *) imsg);
  81.             }
  82.             while (amsg = (struct AppMessage *) GetMsg(msgport)) {
  83.               printf("ai: appmsg=%lx, Type=%ld, ID=%ld, UserData=%ld, NumArgs=%ld\n", amsg, amsg->am_Type, amsg->am_ID, amsg->am_UserData, amsg->am_NumArgs);
  84.               argptr = amsg->am_ArgList;
  85.               for (i = 0; i < amsg->am_NumArgs; i++) {
  86.             printf("\targ(%ld): Name='%s', Lock=%lx\n", i, argptr->wa_Name, argptr->wa_Lock);
  87.             argptr++;
  88.               }
  89.               ReplyMsg((struct Message *) amsg);
  90.             }
  91.           } while (!done);
  92.           RemoveAppIcon(ai);
  93.         } else        /* !ai */
  94.           printf("Couldn't AddAppIcon\n");
  95.         FreeMem(image1.ImageData, imagememsize);
  96.           } else        /* !image1.ImageData */
  97.         printf("Couldn't get memory for imagedata\n");
  98.           FreeDiskObject(dobj);
  99.         } else        /* !dobj */
  100.           printf("Couldn't get DiskObject(NULL)");
  101.         CloseWindow(win);
  102.       } else        /* !win */
  103.         printf("Couldn't open window\n");
  104.           /* Make sure there are no more outstanding messages */
  105.           while(amsg = (struct AppMessage *)GetMsg(msgport))
  106.             ReplyMsg((struct Message *)amsg);
  107.       DeleteMsgPort(msgport);
  108.     } else            /* !msgport */
  109.       printf("Couldn't create messageport\n");
  110.     CloseLibrary(IconBase);
  111.       } else            /* !IconBase */
  112.     printf("Couldn't open icon.library\n");
  113.       CloseLibrary(WorkbenchBase);
  114.     } else            /* !WorkbenchBase */
  115.       printf("Couldn't open workbench.library\n");
  116.     CloseLibrary(IntuitionBase);
  117.   } else            /* !IntuitionBase */
  118.     printf("Couldn't open intuition.library\n");
  119.   printf("ai: done\n");
  120. }
  121.