OWLNext    7.0
Borland's Object Windows Library for the modern age
Loading...
Searching...
No Matches
Constructing TIcon

You can construct a TIcon in a number of ways: from an existing TIcon object, from a resource in the current application, from a resource in another module, or explicitly from size and data information.

You can create icon objects from an existing icon encapsulated in a TIcon object:

TIcon(HINSTANCE instance, const TIcon& icon);

instance can be any module instance. For example, you could get the instance of a DLL and get an icon from that instance:

TModule iconLib("MYICONS.DLL");
TIcon icon(iconLib, "MYICON");

Note the implicit conversion of the TModule iconLib into an HINSTANCE in the call to the TIcon constructor.

You can create a TIcon object from an icon resource in any module:

TIcon(HINSTANCE instance, TResId resId);

In this case, instance should be the HINSTANCE of the module from which you want to get the icon, and resId is the resource ID of the particular icon you want to get. Passing in 0 for instance gives you access to built-in Windows icons. You can also load an icon from a file:

TIcon(HINSTANCE instance, char far* filename, int index);

In this case, instance should be the instance of the current module, filename is the name of the file containing the icon, and index is the index of the icon to be retrieved.

You can also create a new icon:

TIcon(HINSTANCE instance, TSize& size, int
void far* andBits, void far* xorBits);

In this case, instance should be the instance of the current module, size indicates the size of the icon, planes indicates the number of color planes, bitsPixel indicates the number of bits per pixel, andBits points to an array containing the AND mask of the icon, and xorBits points to an array containing the XOR mask of the icon. The andBits array must specify a monochrome mask. The xorBits array can be a monochrome or device-dependent color bitmap.

You can also create a new TIcon object from an existing HICON handle:

TIcon(HICON handle, TAutoDelete autoDelete = NoAutoDelete);

This constructor is used to obtain an ObjectWindows object as an alias to a regular Windows handle received in a message.

There are two other constructors that are available only for 32-bit applications:

TIcon(const void* resBits, uint32 resSize);
TIcon(const ICONINFO* iconInfo);

The first constructor takes two parameters: resBits is a pointer to a buffer containing the icon data bits (usually obtained from a call to LookupIconIdFromDirectory or LoadResource functions) and resSize indicates the number of bits in the resBits buffer.

The second constructor takes a single parameter, an ICONINFO structure. The constructor creates an icon from the information in the ICONINFO structure. The fIcon member of the ICONINFO structure must be true, indicating that the ICONINFO structure contains an icon.

The destructor ~TIcon deletes the icon and its storage space.

See Also