HANDLE SelectObject(hDC,hObject)
This function selects the logical object specified by the hObject parameter as the selected object of the specified device context. The new object replaces the previous object of the same type. For example, if hObject is the handle to a logical pen, the SelectObject function replaces the selected pen with the pen specified by hObject.
Selected objects are the default objects used by the GDI output functions to draw lines, fill interiors, write text, and clip output to specific areas of the device surface. Although a device context can have six selected objects (pen, brush, font, bitmap, region, and logical palette), no more than one object of any given type can be selected at one time. Select-Object does not select a logical palette; to select a logical palette, the application must use SelectPalette.
Parameter | Type/Description |
hDC | HDC Identifies the device context. | ||
hObject | HANDLE Identifies the object to be selected. It may be any one of the following, and must have been created by using one of the following functions: | ||
Object | Function | ||
Bitmap (Bitmaps can be selected for memory device contexts only, and for only one device context at a time.) | CreateBitmap CreateBitmapIndirect CreateCompatibleBitmap CreateDIBitmap |
||
Brush | CreateBrushIndirect CreateHatchBrush CreatePatternBrush CreateSolidBrush | ||
Font | CreateFont CreateFontIndirect | ||
Pen | CreatePen CreatePenIndirect | ||
Region | CombineRgn CreateEllipticRgn CreateEllipticRgnIndirect CreatePolygonRgn CreateRectRgn CreateRectRgnIndirect |
The return value identifies the object being replaced by the object specified by the hObject parameter. It is NULL if there is an error.
If the hDC parameter specifies a metafile, the return value is nonzero if the function is successful. Otherwise, it is zero.
If a region is being selected, the return is the same as for SelectClipRgn.
When you select a font, pen, or brush by using the SelectObject function, GDI allocates space for that object in its data segment. Because data-segment space is limited, you should use the DeleteObject function to delete each drawing object that you no longer need.
Before deleting the last of the unneeded drawing objects, an application should select the original (default) object back into the device context, unless the device context is a metafile. The SelectObject function does not return the previously selected object when the hDC parameter identifies a metafile device context. Calling SelectObject with the hObject parameter set to a value returned by a previous call to SelectObject can cause unpredictable results. Metafiles perform their own object cleanup. As a result, an application does not have to reselect default objects when recording a metafile.
An application cannot select a bitmap into more than one device context at any time.