SelectObject Function

Declare Function SelectObject Lib "gdi32.dll" (ByVal hdc As Long, ByVal hObject As Long) As Long

Platforms: Win 32s, Win 95/98, Win NT

SelectObject selects a given object for use on a device. Possible objects to use with this function include bitmaps, brushes, fonts, pens, and regions. Once selected, this object will be used by the device whenever necessary. (For example, the selected brush will be used whenever the device needs to perform a fill.) The function returns a handle to the object previously selected by the device to do that task (e.g., the old brush). The program should re-select the old object when it is finished using it in order to preserve the device's default objects (see the example for a demonstration of this).

hdc
A device context to the device to select an object for.
hObject
A handle to the bitmap, brush, font, pen, or region to select for the device.

Example:

' Draw a rectangle with corners (10,20) and (175,100)
' on window Form1.  Use a solid yellow brush to fill the rectangle.
Dim hbrush As Long  ' receives handle to the solid yellow brush
Dim holdbrush As Long  ' receives handle to Form1's default brush
Dim retval As Long  ' return value

hbrush = CreateSolidBrush(RGB(255, 255, 0))  ' create a solid yellow brush
' Save Form1's default brush so we can restore it after the program is finished
holdbrush = SelectObject(Form1.hDC, hbrush)  ' select the brush
' Draw the rectangle filled using the solid yellow brush
retval = Rectangle(Form1.hDC, 10, 20, 175, 100)
' Restore Form1's previous brush before destroying the created one
retval = SelectObject(Form1.hDC, holdbrush)  ' select old brush
retval = DeleteObject(hbrush)  ' destroy the solid yellow brush

Category: Devices

Go back to the alphabetical Function listing.
Go back to the Reference section index.


This page is copyright © 2000 Paul Kuliniewicz. Copyright Information.
Go back to the Windows API Guide home page.
E-mail: vbapi@vbapi.com Send Encrypted E-Mail
This page is at http://www.vbapi.com/ref/s/selectobject.html