TImageList

Source: source/classes/timaglst.prg

Standalone class (not derived from TControl)

TImageList is a standalone wrapper around the Win32 HIMAGELIST API for managing collections of icons and bitmaps of equal size. Image lists are used extensively by tree views, list views, tab controls, toolbars, and other common controls to efficiently manage icon sets.

Key DATA Members

DATATypeDescription
hImageListHandleWin32 HIMAGELIST handle
aBitmapsArrayArray of TBitmap objects added to the list

Methods

MethodDescription
New( nWidth, nHeight )Create a new image list. Default size is 16x16 pixels.
Add( oBmpImage, oBmpMask )Add an image with optional mask bitmap to the list. Returns the image index.
AddMasked( oBmpImage, nClrMask )Add an image using a transparent color as mask. Returns the image index.
AddIcon( oIcon )Add an icon (TIcon object or icon file/resource name) to the list. Returns the image index.
AddImage( cFile )Load and add an image from a file path. Returns the image index.
ReadBitmap( cFile, nWidth, nImages, nClrTransparent )Load a bitmap strip from a file, split into nImages frames, using nClrTransparent as the transparent mask color.
SetBkColor( nColor )Set the background color used when rendering masked images. Use CLR_NONE for transparent background.
End()Destroy the image list and release all associated resources.

Example: Creating an Image List for a Toolbar

#include "FiveWin.ch"

function Main()

   local oWnd, oImgList, oBar

   DEFINE WINDOW oWnd TITLE "ImageList Demo" SIZE 500, 300

   // Create a 24x24 image list
   oImgList := TImageList():New( 24, 24 )

   // Add masked bitmaps (using magenta as transparent color)
   oImgList:AddMasked( TBitmap():Load( "bitmaps\new.bmp"  ), CLR_MAGENTA )
   oImgList:AddMasked( TBitmap():Load( "bitmaps\open.bmp" ), CLR_MAGENTA )
   oImgList:AddMasked( TBitmap():Load( "bitmaps\save.bmp" ), CLR_MAGENTA )

   // Attach to a toolbar button bar
   oBar := TButtonBar():New( oWnd, , , oImgList )

   ACTIVATE WINDOW oWnd CENTERED

return nil

Notes

See Also