DeleteObject

2.x

  BOOL DeleteObject(hgdiobj)    
  HGDIOBJ hgdiobj; /* handle of object to delete */

The DeleteObject function deletes an object from memory by freeing all system storage associated with the object. (Objects include pens, brushes, fonts, bitmaps, regions, and palettes.)

Parameters

hgdiobj

Identifies a pen, brush, font, bitmap, region, or palette.

Return Value

The return value is nonzero if the function is successful. Otherwise, it is zero.

Comments

After the object is deleted, the handle given in the hgdiobj parameter is no longer valid.

An application should not delete an object that is currently selected into a device context.

When a pattern brush is deleted, the bitmap associated with the brush is not deleted. The bitmap must be deleted independently.

Example

The following example creates a pen, selects it into a device context, and uses the pen to draw a rectangle. To delete the pen, the original pen is selected back into the device context and the DeleteObject function is called.

HPEN hpen, hpenOld;

hpen = CreatePen(PS_SOLID, 6, RGB(0, 0, 255));
hpenOld = SelectObject(hdc, hpen);

Rectangle(hdc, 10, 10, 100, 100);

SelectObject(hdc, hpenOld);
DeleteObject(hpen);

See Also

SelectObject