Declare Function GetStockObject Lib "gdi32.dll" (ByVal nIndex As Long) As Long
Platforms: Win 32s, Win 95/98, Win NT
GetStockObject accesses one of Windows's stock pens, brushes, fonts, or palettes. This function provides fast access to these commonly used objects, instead of having to use more complicated functions. The function returns a handle to the pen, brush, font, or palette which the function accesses. Although the program isn't required to delete the handle using DeleteObject, doing so doesn't have any adverse effects.
Example:
' Draw a rectangle with a black border and light gray filled interior
' on window Form1. Use stock pens and brushes to do this.
Dim hbrush As Long, holdbrush As Long ' handles to stock brush & default brush
Dim hpen As Long, holdpen As Long ' handles to stock pen & default pen
Dim retval As Long ' return value
' Load the stock pen and brush needed for this operation
hpen = GetStockObject(BLACK_PEN) ' load the black solid pen
hbrush = GetStockObject(LTGRAY_BRUSH) ' load the light gray solid brush
' Select the two objects in Form1 and save the defaults
holdpen = SelectObject(Form1.hDC, hpen) ' select the pen
holdbrush = SelectObject(Form1.hDC, hbrush) ' select the brush
' Draw the rectangle using the pen and brush. The rectangle has corners (20,25)-(200,175)
retval = Rectangle(Form1.hDC, 20, 25, 200, 175)
' Restore Form1's previously selected pen and brush
retval = SelectObject(Form1.hDC, holdpen) ' reselect old pen
retval = SelectObject(Form1.hDC, holdbrush) ' reselect old brush
' Note that it is not necessary to delete hpen and hbrush, but we could if we wanted.
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/g/getstockobject.html