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
| DATA | Type | Description |
|---|---|---|
hImageList | Handle | Win32 HIMAGELIST handle |
aBitmaps | Array | Array of TBitmap objects added to the list |
Methods
| Method | Description |
|---|---|
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
- TImageList is a non-visual class and does not inherit from TControl. It manages the lifecycle of a Win32 HIMAGELIST handle that can be shared across multiple common controls.
- All images in a single image list must be the same size (width and height), which is specified at creation time in
New(). - The
AddMasked()method is the most common way to add bitmaps, using a transparent color (typically CLR_MAGENTA or CLR_WHITE) to create the mask automatically. ReadBitmap()is useful for loading bitmap strips (multiple images arranged horizontally in a single bitmap file). Specify the number of images and the transparent color to split them automatically.- Always call
End()when the image list is no longer needed to avoid GDI handle leaks. The image list is often destroyed automatically when the parent window is destroyed.