GetStockObject

2.x

  HGDIOBJ GetStockObject(fnObject)    
  int fnObject; /* type of stock object */

The GetStockObject function retrieves a handle of one of the predefined stock pens, brushes, or fonts.

Parameters

fnObject

Specifies the type of stock object for which to retrieve a handle. This parameter can be one of the following values:

Value Meaning

BLACK_BRUSH Black brush.
DKGRAY_BRUSH Dark-gray brush.
GRAY_BRUSH Gray brush.
HOLLOW_BRUSH Hollow brush.
LTGRAY_BRUSH Light-gray brush.
NULL_BRUSH Null brush.
WHITE_BRUSH White brush.
BLACK_PEN Black pen.
NULL_PEN Null pen.
WHITE_PEN White pen.
ANSI_FIXED_FONT Windows fixed-pitch system font.
ANSI_VAR_FONT Windows variable-pitch system font.
DEVICE_DEFAULT_FONT Device-dependent font.
OEM_FIXED_FONT OEM-dependent fixed font.
SYSTEM_FONT System font. By default, Windows uses the system font to draw menus, dialog box controls, and other text. In Windows versions 3.0 and later, the system font is a variable-pitch font width; earlier versions of Windows use a fixed-pitch system font.
SYSTEM_FIXED_FONT Fixed-pitch system font used in Windows versions earlier than 3.0. This object is available for compatibility with earlier versions of Windows.
DEFAULT_PALETTE Default color palette. This palette consists of the static colors in the system palette.

Return Value

The return value is the handle of the specified object if the function is successful. Otherwise, it is NULL.

Comments

The DKGRAY_BRUSH, GRAY_BRUSH, and LTGRAY_BRUSH objects should be used only in windows with the CS_HREDRAW and CS_VREDRAW class styles. Using a gray stock brush in any other style of window can lead to misalignment of brush patterns after a window is moved or sized. The origins of stock brushes cannot be adjusted.

Example

The following example retrieves the handle of a black brush by calling the GetStockObject function, selects the brush into the device context, and fills a rectangle by using the black brush:

HBRUSH hbr, hbrOld;

hbr = GetStockObject(BLACK_BRUSH);
hbrOld = SelectObject(hdc, hbr);
Rectangle(hdc, 10, 10, 100, 100);

See Also

GetObject, SetBrushOrg