home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / alib / d1xx / d120 / iconimage.lha / IconImage / IconImage.c < prev    next >
C/C++ Source or Header  |  1987-12-28  |  2KB  |  72 lines

  1. #include <stdio.h>
  2. #include <exec/types.h>
  3. #include <workbench/workbench.h>
  4. #include <workbench/icon.h>
  5. #include <workbench/startup.h>
  6. /***********************************************************
  7.             iconimage.c
  8.  This program will replace an old icon  image with a new
  9. image without effecting icontype and drawer data etc.
  10. eg A tool image can be used to change the image of a
  11. disk icon.
  12.        by Denis Green 18 Nov 1987
  13. compile under Lattice 4.0 using lc -Lcd  iconimage
  14. ************************************************************/
  15. int IconBase;
  16.  
  17. void main()
  18. {
  19. char name[20];
  20. char newimage[20];
  21. char *key;
  22.     struct DiskObject *newdiskobj, *olddiskobj, *GetDiskObject();
  23. key = "  ";
  24. printf("CHANGE ICON IMAGE\n ");
  25. printf("by GREENSOFT 1987\n\n ");
  26.  
  27. printf("Enter icon name to change\n ");
  28. gets(name);
  29. printf("Enter new image name\n ");
  30. gets(newimage);
  31.     if ( (IconBase = OpenLibrary( ICONNAME, 1)) == NULL)
  32.         exit(2);
  33.  
  34.     /* read the icon to modify from disk */
  35.     if ( (olddiskobj = GetDiskObject(name)) == NULL)
  36.         {
  37.         printf("Cannot read icon for %s\n", name);
  38.         CloseLibrary( IconBase );
  39.                printf("Press RETURN to exit. ");
  40.                gets(key);
  41.         exit(3);
  42.         }
  43.  
  44.     /* read the second icon to get its image */
  45.     if ( (newdiskobj= GetDiskObject(newimage)) == NULL)
  46.         {
  47.         printf("Cannot read icon for %s\n", name);
  48.         FreeDiskObject(olddiskobj);
  49.         CloseLibrary( IconBase );
  50.                 printf("Press RETURN to exit. ");
  51.                 gets(key);
  52.         exit(4);
  53.         }
  54.     olddiskobj->do_Gadget.GadgetRender = newdiskobj->do_Gadget.GadgetRender;
  55.         olddiskobj->do_Gadget.SelectRender = newdiskobj->do_Gadget.SelectRender;
  56.     /* modify the flags so that it can use an alternate image */
  57.  
  58.     olddiskobj->do_Gadget.Flags = newdiskobj->do_Gadget.Flags;
  59.         olddiskobj->do_Gadget.Width = newdiskobj->do_Gadget.Width;
  60.         olddiskobj->do_Gadget.Height = newdiskobj->do_Gadget.Height;
  61.     /* now write the modified  icon to disk */
  62.     if (!PutDiskObject( name, olddiskobj))
  63.         printf("Cannot write new icon - code %d\n", IoErr() );
  64.  
  65.  
  66.  
  67.     FreeDiskObject( olddiskobj );
  68.     FreeDiskObject( newdiskobj);
  69.     CloseLibrary( IconBase );
  70.  
  71. }
  72.