MakeIcon.c

/*
    File:       MakeIcon.c
 
    Contains:   this program shows how to take any size pixmap and scale it down to any size or
                depth icon.
 
    Written by: Brigham Stevens 
 
    Copyright:  Copyright © 1992-1999 by Apple Computer, Inc., All Rights Reserved.
 
                You may incorporate this Apple sample source code into your program(s) without
                restriction. This Apple sample source code has been provided "AS IS" and the
                responsibility for its operation is yours. You are not permitted to redistribute
                this Apple sample source code as "Apple sample source code" after having made
                changes. If you're going to re-distribute the source, we require that you make
                it clear in the source that the code was descended from Apple sample source
                code, but that you've made changes.
 
    Change History (most recent first):
                7/9/1999    Karl Groethe    Updated for Metrowerks Codewarror Pro 2.1
                
 
*/
#include <QDOffScreen.h>
#include "IconUtil.h"
#include "InitMac.h"
#include <Windows.h>
#include <Resources.h>
#include "MiscCode.h"
#define ICONID 128
 
void main()
{
 
    WindowPtr   cwp;
    Handle      icon;
    GWorldPtr   gwp;
    Rect        demo;
    short       ref;
    
    
    InitToolBox(4);                 // Witch Chant + 4 calls to More Masters
    
    /* load map of earth in color - no hilite palette */
    cwp = GetNewCWindow(128,nil,(void*)-1L);
    gwp = LoadPictToGWorld(128, cwp, 256, 8, 8, true);  
    SetWTitle(cwp,"\pFlailing about rapidly contorting");
    ShowWindow(cwp);
    DrawImage(cwp);
 
    while(!Button());                   // after a click then we make a small icon thang....
    FlushEvents(everyEvent,0);
    SetRect(&demo,100,100,132,132);     // this is the area of pixmap we make icon from
                                        // it can be the entire portRect if we want
    
    
    
    ref = OpenResFile("\pMakeIcon.output");     // THIS FILE MUST EXIST, or we may croak
    if(ResError())  ExitToShell();
    
    icon = MakeIcon(gwp,&demo,1,32);            // make 32x32 1-bit color icon
    
    if(icon)
    {
        TryRemoveResource('ICON',ICONID);
        AddResource( icon, 'ICON', ICONID, "\p");
        CheckError("\pAddResFail ICON",ResError());
    }
 
    icon = MakeIcon(gwp,&demo,1,16);            // make 16x16 1-bit color icon
    
    if(icon)
    {
        TryRemoveResource('SICN',ICONID);
        AddResource( icon, 'SICN', ICONID, "\p");
        CheckError("\pAddResFail SICN",ResError());
    }
 
    icon =  MakeICN_pound(gwp, &demo, 32);      // create 32x32 1-bit color icon AND MASK
    if(icon)
    {
        TryRemoveResource('ICN#',ICONID);
        AddResource( icon, 'ICN#', ICONID, "\p");
        CheckError("\pAddResFail ICN#",ResError());
    }
 
    icon =  MakeICN_pound(gwp, &demo, 16);      // create 16x16 1-bit color icon AND MASK
    if(icon)
    {
        TryRemoveResource('ics#',ICONID);
        AddResource( icon, 'ics#', ICONID, "\p");
        CheckError("\pAddResFail ics#",ResError());
    }
 
    icon = MakeIcon(gwp,&demo,8,32);            // make 32x32 8-bit color icon
    
    if(icon)
    {
        TryRemoveResource('icl8',ICONID);
        AddResource( icon, 'icl8', ICONID, "\p");
        CheckError("\pAddResFail icl8",ResError());
    }
 
    icon = MakeIcon(gwp,&demo,4,32);            // make 32x32 4-bit color icon
    
    if(icon)
    {
        TryRemoveResource('icl4',ICONID);
        AddResource( icon, 'icl4', ICONID, "\p");
        CheckError("\pAddResFail icl4",ResError());
    }
 
 
    icon = MakeIcon(gwp,&demo,8,16);                // make 16x16 8-bit color mask
    
    if(icon)
    {
        TryRemoveResource('ics8',ICONID);
        AddResource( icon, 'ics8', ICONID, "\p");
        CheckError("\pAddResFail ics8",ResError());
    }
 
    icon = MakeIcon(gwp,&demo,4,16);                // make 16x16 4-bit color mask
    
    if(icon)
    {
        TryRemoveResource('ics4',ICONID);
        AddResource( icon, 'ics4', ICONID, "\p");
        CheckError("\pAddResFail ics4",ResError());
    }
 
    CloseResFile(ref);
}