GetObjectType function
Retrieves the type of a GDI object.
Syntax
Parameters
Return value
Remarks
Example
int GetObjectType(
HGDIOBJ hObject
);
| Parameter | Description |
|---|---|
hObject | Handle to the GDI object whose type is to be retrieved. |
If the function succeeds, the return value indicates the object type. The possible values are:
#define OBJ_PEN 1
#define OBJ_BRUSH 2
#define OBJ_DC 3
#define OBJ_METADC 4
#define OBJ_METAFILE 5
#define OBJ_PAL 6
#define OBJ_FONT 7
#define OBJ_BITMAP 8
#define OBJ_REGION 9
#define OBJ_METAFILEPICT 10
#define OBJ_TEXT 11
#define OBJ_SPARE0 12
#define OBJ_SPARE1 13
#define OBJ_SPARE2 14
#define OBJ_SPARE3 15
#define OBJ_SPARE4 16
#define OBJ_SPARE5 17
#define OBJ_SPARE6 18
#define OBJ_SPARE7 19
#define OBJ_SPARE8 20
On failure, the return value is zero. Use GetLastError for extended error information.
Remarks
- The function works with any GDI object that can be selected into a device context.
- For object types
OBJ_FONT,OBJ_PEN, andOBJ_BRUSH, the handle can be created by functions such asCreateFont,CreatePen, andCreateSolidBrush, respectively. - Do not call
DeleteObjecton a stock object (e.g.,GetStockObject(SYSTEM_FONT)).
Example: Determine if a handle is a bitmap.
#include <windows.h>
#include <stdio.h>
int main()
{
HBITMAP hbmp = (HBITMAP)LoadImage(NULL, L"sample.bmp", IMAGE_BITMAP, 0, 0,
LR_LOADFROMFILE | LR_CREATEDIBSECTION);
if (!hbmp) { printf("Failed to load bitmap\n"); return 1; }
int type = GetObjectType(hbmp);
if (type == OBJ_BITMAP)
printf("Handle is a bitmap.\n");
else
printf("Handle is not a bitmap (type=%d).\n", type);
DeleteObject(hbmp);
return 0;
}
See also: SelectObject, DeleteObject, GetObject