Windows API Reference

DeleteObject Function

BOOL DeleteObject(
  HGDIOBJ hObject
);

Description

The DeleteObject function deletes a graphics object that was created by a GDI graphics object creation function. It releases the system memory that the object occupied. Do not delete a GDI object that is currently selected into a device context (DC).

A GDI object is a handle that identifies a bitmap, brush, font, palette, or pen. The system creates GDI objects in response to calls to various GDI functions, such as CreateBitmap, CreateBrushIndirect, CreateFont, CreatePalette, and CreatePen.

You can delete an object by calling DeleteObject with its handle. After the object is deleted, the handle is no longer valid.

Parameters

  • hObject [in]
    A handle to the GDI object to be deleted. This parameter can be a handle to a logical bitmap, brush, font, palette, or pen.

Return Value

If the function succeeds, the return value is nonzero.

If the function fails, the return value is zero. To get extended error information, call GetLastError.

Remarks

It is important to delete GDI objects when you no longer need them, as GDI objects consume system resources. Failure to delete GDI objects can lead to resource leaks and poor application performance.

Objects that are created with a stock object creation function (such as GetStockObject) cannot be deleted.

If an object is selected into a device context, it cannot be deleted. You must first select a different object into the device context before deleting the original object.

Requirements

Header: Wingdi.h (include Windows.h)

Library: Gdi32.lib

DLL: Gdi32.dll

See Also