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
Handleallow 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,PlotCIconHandledoesn't honor the current foreground and background colors.
Listing 5-5 shows how to use
PlotIconto draw an icon of resource type'ICON'without specifying alignment or transforms. The application-defined procedureMyPlotAnICONusesGetIconto 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 theReleaseResourceprocedure to release the memory occupied by the icon resource data; for more information aboutReleaseResource, see the chapter "Resource Manager" in this book.
PlotIconHandleto draw an icon of resource type'ICON'with a specific alignment and transform. The application-defined procedureMyPlotAnICONWithAlignAndTransformusesGetIconto 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 thePlotIconHandlefunction in Listing 5-6 to draw the icon without
stretching it, the destination rectangle passed in thedestRectparameter ofMyPlotAnICONWithAlignAndTransformmust be exactly 32 by 32 pixels. If the destination rectangle is not 32 by 32 pixels,PlotIconHandleexpands or shrinks the icon to fit.Listing 5-7 shows how to use
PlotCIconto draw an icon of resource type'cicn'without specifying alignment or transform. TheMyPlotAcicnprocedure usesGetCIconto 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 usePlotCIconHandleto draw an icon of resource type'cicn'with a specific alignment and transform. Listing 5-8 usesGetCIconto 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 usePlotSICNHandleto draw an icon of resource type'SICN'with a specific alignment and transform. The application-defined procedureMyPlotAnSICNWithAlignAndTransformusesGetResourceto 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 thePlotSICNHandlefunction in Listing 5-9 to draw the icon without
stretching it, the destination rectangle passed in thedestRectparameter ofMyPlotAnSICNWithAlignAndTransformmust be exactly 16 by 16 pixels. If the destination rectangle is not this size,PlotSICNHandleexpands or shrinks the
icon to fit.
 
  
  
 