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

You can construct a TDib object either directly or indirectly.

Using direct construction, you can specify the bitmap's width, height, and so on. Using indirect construction, you can specify an existing bitmap object, pointer to a BITMAP structure, a metafile, a TDC device context, and more.

Here is the constructor for directly constructing a TDib object:

TDib(int width, int height, int nColors, uint16 mode=DIB_RGB_COLORS);

width and height specify the width and height in pixels of the DIB. nColors specifies the number of colors actually used in the DIB. mode can be either DIB_RGB_COLORS or DIB_PAL_COLORS. DIB_RGB_COLORS indicates that the color table consists of literal RGB values. DIB_PAL_COLORS indicates that the color table consists of an array of 16-bit indexes into the currently realized logical palette.

You can create a TDib object by loading it from an executable application module. This constructor takes two parameters: the first is the HINSTANCE of the module containing the bitmap and the second is the resource ID of the bitmap you want to load:

TDib(HINSTANCE instance, TResId resId);

To create a TDib object from the Clipboard, pass a reference to a TClipboard object to the constructor. The constructor gets the handle of the bitmap in the Clipboard and constructs a bitmap object from the handle.

TDib(const TClipboard& clipboard);

You can load a DIB from a file (typically a .BMP file) into a TDib object by specifying the name as the only parameter of the constructor:

TDib(const char* name);

You can also construct a TDib object given a TBitmap object and a TPalette object. If no palette is given, this constructor uses the focus window's currently realized palette.

TDib(const TBitmap& bitmap, const TPalette* pal = 0);

You can create a DIB object from an existing DIB object:

TDib(const TDib& dib);
TDib(HGLOBAL 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. Because an HGLOBAL handle can point to many different kinds of objects, you must ensure that the HGLOBAL you use in this constructor is actually the handle to a device-independent bitmap. If you pass a handle to another type of object, the constructor throws an exception.

If ShouldDelete is true, the destructor ~TDib frees the resource and unlocks and frees the chunk of global memory as needed.

See Also