Important: The information in this document is obsolete and should not be used for new development.
Drawing Icons That Are Not Part of an Icon Family
To draw icons of resource type'ICON'
or'cicn'
in menus and dialog boxes, you can use the Menu Manager and Dialog Manager as described in Inside Macintosh: Macintosh Toolbox Essentials. You can also use Menu Manager routines to draw resources of type'SICN'
.To draw resources of resource type
'ICON'
,'cicn'
, or'SICN'
in your application's windows, you can use these routines:
Resource type Routines 'ICON' PlotIconHandle
PlotIcon'cicn' PlotCIconHandle
PlotCIcon'SICN' PlotSICNHandle The routines in this list that end in
Handle
allow you to specify alignment and transforms for the icons. You are responsible for disposing of the handle you pass to any of these routines.
The listings that follow provide examples of how to draw each of the three icon resource types that are not part of an icon family.
- Note
- Unlike
PlotCIcon
,PlotCIconHandle
doesn't honor the current foreground and background colors.Listing 5-5 shows how to use
PlotIcon
to draw an icon of resource type'ICON'
without specifying alignment or transforms. The application-defined procedureMyPlotAnICON
usesGetIcon
to get a handle to the data for the desired icon and then passes the destination rectangle and the handle toPlotIcon
.Listing 5-5 Drawing an icon of resource type
'ICON'
PROCEDURE MyPlotAnICON (resID: Integer; destRect: Rect; VAR myIcon: Handle); BEGIN myIcon := GetIcon(resID); PlotIcon(destRect, myIcon); END;Listing 5-6 shows how to use
- IMPORTANT
- When you are finished using a handle obtained from
GetIcon
, use theReleaseResource
procedure to release the memory occupied by the icon resource data; for more information aboutReleaseResource
, see the chapter "Resource Manager" in this book.PlotIconHandle
to draw an icon of resource type'ICON'
with a specific alignment and transform. The application-defined procedureMyPlotAnICONWithAlignAndTransform
usesGetIcon
to get a handle to the data for the desired icon and then passes the destination rectangle, alignment, transform, and handle toPlotIconHandle
.Listing 5-6 Drawing an icon of resource type
'ICON'
with a specific alignment and transform
PROCEDURE MyPlotAnICONWithAlignAndTransform (resID: Integer; destRect: Rect; align: IconAlignmentType; transform: IconTransformType; VAR myIcon: Handle); VAR myErr: OSErr; BEGIN myIcon := GetIcon(resID); myErr := PlotIconHandle(destRect, align, transform, myIcon); END;For thePlotIconHandle
function in Listing 5-6 to draw the icon without
stretching it, the destination rectangle passed in thedestRect
parameter ofMyPlotAnICONWithAlignAndTransform
must be exactly 32 by 32 pixels. If the destination rectangle is not 32 by 32 pixels,PlotIconHandle
expands or shrinks the icon to fit.Listing 5-7 shows how to use
PlotCIcon
to draw an icon of resource type'cicn'
without specifying alignment or transform. TheMyPlotAcicn
procedure usesGetCIcon
to get a handle to the color icon record of the desired icon and then passes the destination rectangle and handle toPlotCIcon
.Listing 5-7 Drawing an icon of resource type
'cicn'
PROCEDURE MyPlotAcicn (resID: Integer; destRect: Rect; VAR myCicnIcon: CIconHandle); BEGIN myCicnIcon := GetCIcon(resID); PlotCIcon(destRect, myCicnIcon); END;Listing 5-8 shows how to usePlotCIconHandle
to draw an icon of resource type'cicn'
with a specific alignment and transform. Listing 5-8 usesGetCIcon
to get a handle to the color icon record of the desired icon and then passes the destination rectangle, alignment, transform, and handle toPlotCIconHandle
.Listing 5-8 Drawing an icon of resource type
'cicn'
with a specific alignment and transform
PROCEDURE MyPlotAcicnWithAlignAndTransform (resID: Integer; destRect: Rect; align: IconAlignmentType; transform: IconTransformType; VAR myCicnIcon: CIconHandle); VAR myErr: OSErr; BEGIN myCicnIcon := GetCIcon(resID); myErr := PlotCIconHandle(destRect, align, transform, myCicnIcon); END;Listing 5-9 shows how to usePlotSICNHandle
to draw an icon of resource type'SICN'
with a specific alignment and transform. The application-defined procedureMyPlotAnSICNWithAlignAndTransform
usesGetResource
to get a handle to the data for the desired icon and then passes the destination rectangle, alignment, transform, and handle toPlotSICNHandle
.Listing 5-9 Drawing an icon of resource type
'SICN'
with a specific alignment and transform
PROCEDURE MyPlotAnSICNWithAlignAndTransform (resID: Integer; destRect: Rect; align: IconAlignmentType; transform: IconTransformType; VAR myIcon: Handle); VAR myErr: OSErr; BEGIN myIcon := GetResource('SICN', resID); myErr := PlotSICNHandle(destRect, align, transform, myIcon); END;For thePlotSICNHandle
function in Listing 5-9 to draw the icon without
stretching it, the destination rectangle passed in thedestRect
parameter ofMyPlotAnSICNWithAlignAndTransform
must be exactly 16 by 16 pixels. If the destination rectangle is not this size,PlotSICNHandle
expands or shrinks the
icon to fit.