The SelectObject function selects an object into the specified device context (DC). The object could be a bitmap, brush, font, palette, or region.
HGDIOBJ SelectObject(
HDC hdc,
HGDIOBJ hgdiobj
);
| Parameter | Description |
|---|---|
hdc |
A handle to the device context. |
hgdiobj |
A handle to the object (bitmap, brush, font, palette, or region) to be selected into the DC. |
If the function succeeds, the return value is a handle to the object that was previously selected into the specified device context. If the object that was previously selected into the DC was a region, the return value is of type HRGN.
If the function fails, the return value is NULL.
The handle returned by SelectObject can be HGDI_ERROR if the selection fails.
Always delete GDI objects that you create when you no longer need them, using functions like DeleteObject or DeleteDC. Do not delete an object that is currently selected into a device context.
// Assume hdc is a valid device context handle and hNewFont is a handle to a font
// Save the old font handle
HGDIOBJ hOldFont = SelectObject(hdc, hNewFont);
// ... Perform drawing operations with the new font ...
// Select the old font back into the DC
if (hOldFont != NULL && hOldFont != HGDI_ERROR) {
SelectObject(hdc, hOldFont);
}
// Delete the new font (if you created it)
// DeleteObject(hNewFont);
| Description | |
|---|---|
| Minimum supported client | Windows 2000 Professional |
| Minimum supported server | Windows 2000 Server |
| Header | wingdi.h (include Windows.h) |
| Library | Gdi32.lib |
| DLL | Gdi32.dll |