GetStockObject Function

 

GetStockObject Function

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

Syntax

HGDIOBJ GetStockObject(
  __in  int fnObject
);

Parameters

fnObject [in]

The type of stock object. This parameter can be one of the following values.

ValueMeaning
BLACK_BRUSH

Black brush.

DKGRAY_BRUSH

Dark gray brush.

DC_BRUSH

Solid color brush. The default color is white. The color can be changed by using the SetDCBrushColor function. For more information, see the Remarks section.

GRAY_BRUSH

Gray brush.

HOLLOW_BRUSH

Hollow brush (equivalent to NULL_BRUSH).

LTGRAY_BRUSH

Light gray brush.

NULL_BRUSH

Null brush (equivalent to HOLLOW_BRUSH).

WHITE_BRUSH

White brush.

BLACK_PEN

Black pen.

DC_PEN

Solid pen color. The default color is white. The color can be changed by using the SetDCPenColor function. For more information, see the Remarks section.

NULL_PEN

NULL pen. The null pen draws nothing.

WHITE_PEN

White pen.

ANSI_FIXED_FONT

Windows fixed-pitch (monospace) system font.

ANSI_VAR_FONT

Windows variable-pitch (proportional space) system font.

DEVICE_DEFAULT_FONT

Device-dependent font.

DEFAULT_GUI_FONT

Default font for user interface objects such as menus and dialog boxes. It is not recommended that you use DEFAULT_GUI_FONT or SYSTEM_FONT to obtain the font used by dialogs and windows; for more information, see the remarks section.

The default font is Tahoma.

OEM_FIXED_FONT

Original equipment manufacturer (OEM) dependent fixed-pitch (monospace) font.

SYSTEM_FONT

System font. By default, the system uses the system font to draw menus, dialog box controls, and text. It is not recommended that you use DEFAULT_GUI_FONT or SYSTEM_FONT to obtain the font used by dialogs and windows; for more information, see the remarks section.

The default system font is Tahoma.

SYSTEM_FIXED_FONT

Fixed-pitch (monospace) system font. This stock object is provided only for compatibility with 16-bit Windows versions earlier than 3.0.

DEFAULT_PALETTE

Default palette. This palette consists of the static colors in the system palette.

 

Return Value

If the function succeeds, the return value is a handle to the requested logical object.

If the function fails, the return value is NULL.

Remarks

It is not recommended that you employ this method to obtain the current font used by dialogs and windows. Instead, use the SystemParametersInfo function with the SPI_GETNONCLIENTMETRICS parameter to retrieve the current font. SystemParametersInfo will take into account the current theme and provides font information for captions, menus, and message dialogs.

Use the DKGRAY_BRUSH, GRAY_BRUSH, and LTGRAY_BRUSH stock objects only in windows with the CS_HREDRAW and CS_VREDRAW 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.

The HOLLOW_BRUSH and NULL_BRUSH stock objects are equivalent.

It is not necessary (but it is not harmful) to delete stock objects by calling DeleteObject.

Both DC_BRUSH and DC_PEN can be used interchangeably with other stock objects like BLACK_BRUSH and BLACK_PEN. For information on retrieving the current pen or brush color, see GetDCBrushColor and GetDCPenColor. See Setting the Pen or Brush Color for an example of setting colors. The GetStockObject function with an argument of DC_BRUSH or DC_PEN can be used interchangeably with the SetDCPenColor and SetDCBrushColor functions.

Examples

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

Requirements

Minimum supported clientWindows 2000 Professional
Minimum supported serverWindows 2000 Server
HeaderWingdi.h (include Windows.h)
LibraryGdi32.lib
DLLGdi32.dll

See Also

Device Contexts Overview Device Context Functions DeleteObject SelectObject

Send comments about this topic to Microsoft

SetDIBits函数是Visual Basic 6 (VB6) 中用于向设备无关位图(DIB)添加颜色信息的一个功能。它通常用于处理图像数据,特别是当需要逐像素地操作位图时。下面是一个简单的示例: ```vb Private Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hBitmap As Long) As Long Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long Private Declare Function DeleteDC Lib "gdi32" (ByVal hdc As Long) As Long Private Declare Function GetStockObject Lib "gdi32" (ByVal obj As Long) As Long Private Declare Function CreateDIBSection Lib "gdi32" (ByVal hdc As Long, lpbih As DIBSECTION, ByVal fl PixelFormat As Long, ByVal pBits As Long, ByVal hMem As Long, ByVal iUsage As Long) As Long Private Declare Sub BitBlt Lib "gdi32" (ByVal hdcDest As Long, ByVal nXDest As Long, ByVal nYDest As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hdcSrc As Long, ByVal nXSrc As Long, ByVal nYSrc As Long, ByVal dwRop As Long) ' 假设有一个已经创建好的位图和颜色数组 Dim hBitmap As Long Dim hMem DCB As DIBSECTION Dim pBits() As Byte ' 假设我们有32位的位图 ' 创建兼容设备上下文 Dim hdcDC As Long hdcDC = CreateCompatibleDC(0) ' 选择源设备上下文中的位图 Dim hOldBitmap As Long hOldBitmap = SelectObject(hdcDC, hBitmap) ' 创建DIB If CreateDIBSection(hdcDC, DibHeader, PFO_DDB, pBits, hMem, DBI_COLOR) = 0 Then ' 处理创建失败的情况 End If ' 使用SetDIBits将颜色信息设置到DIB中 SetDIBits hdcDC, hMem, 0, 1, 1, 1, 1, 1, pBits(0 To 31), DIB_RGB_COLORS ' 这里假设每个像素由32位表示 ' 将结果复制回原始位图 BitBlt BitMapHandle, 0, 0, 1, 1, hdcDC, 0, 0, SRCCOPY ' 清理 SelectObject(hdcDC, hOldBitmap) DeleteObject hOldBitmap DeleteDC hdcDC
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值