TIcon
Source: source/classes/icon.prg
Inherits from: TControl
TIcon is a control for displaying Windows icons (.ico) from files or program resources. It supports click actions, dynamic icon switching, border display, and proper resource cleanup. TIcon is commonly used for toolbar indicators, status icons, and decorative elements in windows and dialogs.
Key DATA Members
| DATA | Type | Description |
|---|---|---|
hIcon | Numeric (Handle) | Windows icon handle (HICON) |
cIcoFile | Character | Path to the .ico file |
cResName | Character | Name of the icon resource in the executable |
Methods
| Method | Description |
|---|---|
New( nRow, nCol, cRes, cFile, lBorder, bClick, oWnd ) | Create an icon control. Provide either cRes (resource name) or cFile (.ico file path). |
ReDefine( nId, cRes, cFile, bClick, lUpdate, oDlg ) | Redefine from a dialog resource template |
SetName( cResName ) | Switch to a different icon resource by name. Destroys the old icon handle. |
SetFile( cIcoFile ) | Switch to a different .ico file. Destroys the old icon handle. |
End() | Destroy the icon handle and call the superclass End() |
ICON Command
@ nRow, nCol ICON oIcon OF oWnd FILE cFile
Example
#include "FiveWin.ch"
function Main()
local oWnd, oIcon
DEFINE WINDOW oWnd TITLE "Icon Demo" SIZE 300, 200
// Display an icon from a file
@ 10, 10 ICON oIcon OF oWnd FILE "myapp.ico"
// Make the icon clickable
oIcon:bLClicked := {|| MsgInfo( "Icon clicked!" ) }
ACTIVATE WINDOW oWnd CENTERED
return nil
Notes
- The icon is loaded from either a file (
cIcoFileviaExtractIcon()) or a program resource (cResNameviaLoadIcon()). One of the two must be provided. - The default icon size is 32x32 pixels, determined by the class constants
ICO_CHARPIX_H(14) andICO_CHARPIX_W(8) multiplied by row/column coordinates. - Use
SetName()andSetFile()to change the displayed icon at runtime. Both methods properly destroy the previous icon handle to prevent resource leaks. - Assign a code block to
bLClickedto handle click events on the icon. - The
Destroy()method ensures the icon handle is released viaDestroyIcon()when the control is destroyed.