Export (0) Print
Expand All

SelectObject function

The SelectObject function selects an object into the specified device context (DC). The new object replaces the previous object of the same type.

Syntax


HGDIOBJ SelectObject(
  _In_  HDC hdc,
  _In_  HGDIOBJ hgdiobj
);

Parameters

hdc [in]

A handle to the DC.

hgdiobj [in]

A handle to the object to be selected. The specified object must have been created by using one of the following functions.

ObjectFunctions
Bitmap

CreateBitmap, CreateBitmapIndirect, CreateCompatibleBitmap, CreateDIBitmap, CreateDIBSection

Bitmaps can only be selected into memory DC's. A single bitmap cannot be selected into more than one DC at the same time.

Brush

CreateBrushIndirect, CreateDIBPatternBrush, CreateDIBPatternBrushPt, CreateHatchBrush, CreatePatternBrush, CreateSolidBrush

Font

CreateFont, CreateFontIndirect

Pen

CreatePen, CreatePenIndirect

Region

CombineRgn, CreateEllipticRgn, CreateEllipticRgnIndirect, CreatePolygonRgn, CreateRectRgn, CreateRectRgnIndirect

 

Return value

If the selected object is not a region and the function succeeds, the return value is a handle to the object being replaced. If the selected object is a region and the function succeeds, the return value is one of the following values.

ValueMeaning
SIMPLEREGIONRegion consists of a single rectangle.
COMPLEXREGIONRegion consists of more than one rectangle.
NULLREGIONRegion is empty.

 

If an error occurs and the selected object is not a region, the return value is NULL. Otherwise, it is HGDI_ERROR.

Remarks

This function returns the previously selected object of the specified type. An application should always replace a new object with the original, default object after it has finished drawing with the new object.

An application cannot select a single bitmap into more than one DC at a time.

ICM: If the object being selected is a brush or a pen, color management is performed.

Examples

For an example, see Setting the Pen or Brush Color.

Requirements

Minimum supported client

Windows 2000 Professional [desktop apps only]

Minimum supported server

Windows 2000 Server [desktop apps only]

Header

Wingdi.h (include Windows.h)

Library

Gdi32.lib

DLL

Gdi32.dll

See also

Device Contexts Overview
Device Context Functions
CombineRgn
CreateBitmap
CreateBitmapIndirect
CreateBrushIndirect
CreateCompatibleBitmap
CreateDIBitmap
CreateDIBPatternBrush
CreateEllipticRgn
CreateEllipticRgnIndirect
CreateFont
CreateFontIndirect
CreateHatchBrush
CreatePatternBrush
CreatePen
CreatePenIndirect
CreatePolygonRgn
CreateRectRgn
CreateRectRgnIndirect
CreateSolidBrush
SelectClipRgn
SelectPalette

 

 

Community Additions

ADD
Show:
© 2014 Microsoft