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.
Declare Function GetStockObject Lib "gdi32.dll" (ByVal nIndex As Long) As Long
Exactly one of the following flags specifying which of the stock objects to create a handle to:
ANSI_FIXED_FONT = 11
The system's normal monospaced font.
ANSI_VAR_FONT = 12
The system's normal proportional-width font.
BLACK_BRUSH = 4
A solid black brush.
BLACK_PEN = 7
A solid black pen.
DEFAULT_GUI_FONT = 17
Win 95/98 only: The default font for user objects under Windows.
DEFAULT_PALETTE = 15
The default system palette.
DEVICE_DEFAULT_FONT = 14
Win NT only: a device-dependent font.
DKGRAY_BRUSH = 3
A solid dark gray brush.
GRAY_BRUSH = 2
A solid gray brush.
HOLLOW_BRUSH = 5
Same as NULL_BRUSH.
LTGRAY_BRUSH = 1
A solid light gray brush.
NULL_BRUSH = 5
A null brush; i.e., a brush that does not draw anything on the device.
NULL_PEN = 8
A null pen; i.e., a pen that does not draw anything on the device.
OEM_FIXED_FONT = 10
The Original Equipment Manufacturer's default monospaced font.
SYSTEM_FIXED_FONT = 16
The system monospaced font under pre-3.x versions of Windows.
SYSTEM_FONT = 13
The system font (used for most system objects under Windows).
WHITE_BRUSH = 0
A solid white brush.
WHITE_PEN = 6
A solid white pen.
Dim hbrush As Long, holdbrush As Long
Dim hpen As Long, holdpen As Long
Dim retval As Long
hpen = GetStockObject(BLACK_PEN)
hbrush = GetStockObject(LTGRAY_BRUSH)
holdpen = SelectObject(Form1.hDC, hpen)
holdbrush = SelectObject(Form1.hDC, hbrush)
retval = Rectangle(Form1.hDC, 20, 25, 200, 175)
retval = SelectObject(Form1.hDC, holdpen)
retval = SelectObject(Form1.hDC, holdbrush)