函数参考


_WinAPI_CreateBrushIndirect

创建指定样式,颜色和图案的逻辑画笔.

#Include <WinAPIEx.au3>
_WinAPI_CreateBrushIndirect ( $iStyle, $iRGB, $iHatch )

参数

$iStyle 画笔样式. 参数可以是以下样式之一:

$BS_DIBPATTERN --- 由设备无关位图(DIB)规范定义.如此参数为 $iHatch 成员,则包含压缩的 DIB 的句柄
$BS_DIBPATTERN8X8 --- 见 BS_DIBPATTERN
$BS_DIBPATTERNPT --- 由设备无关位图(DIB)规范定义,如此参数为 $iHatch 成员, 则包含一个指向压缩 DIB 的指针.
$BS_HATCHED --- 阴影线画笔
$BS_HOLLOW --- 中空画笔
$BS_NULL --- 与 BS_HOLLOW 相同
$BS_PATTERN --- 由内存位图定义的画笔样式
$BS_PATTERN8X8 --- 见 BS_PATTERN
$BS_SOLID --- 实心画笔
$iRGB 画笔颜色, RGB 或以下值之一:

$DIB_PAL_COLORS --- 颜色表包含当前逻辑调色板的16位索引数组.
$DIB_RGB_COLORS --- 颜色表包含 RGB 值
$iHatch 影线样式. 含义取决于 $iStyle 参数定义的画笔样式.

$BS_DIBPATTERN
包含压缩 DIB 的句柄.

$BS_DIBPATTERNPT
包含指向压缩 DIB 的指针.

$BS_HATCHED
阴影线画笔,指定用于创建阴影线的路线方向.它可以是常量方向 ($HS_*).

$BS_PATTERN
包含位图句柄定义的样式. 位图不能是 DIB 位图.

$BS_HOLLOW 中空画笔, $BS_SOLID 实心画笔
忽略.

返回值

成功: 返回逻辑画笔的标识值.
失败: 返回 0,并设置@error标志为非 0 值.

注意/说明

应用程序调用本函数创建逻辑画笔后, 可调用 _WinAPI_SelectObject() 函数选择任何设备环境.
 不再需要画笔时,调用 _WinAPI_DeleteObject() 函数删除它.
 调用 _WinAPI_DeleteObject() 函数删除它.

相关

详情参考

在MSDN中搜索


示例/演示


#Include <APIConstants.au3>
#Include <WinAPIEx.au3>

Opt('MustDeclareVars', 1)

Global Const $STM_SETIMAGE = 0x0172
Global Const $STM_GETIMAGE = 0x0173

Global $hForm, $Pic, $hPic, $tRECT, $hObj, $hBrush, $hOldBrush, $hPen, $hOldPen, $hFont, $hRgn, $hPattern, $hBitmap, $hSource, $hDev, $hDC, $hSv
Global $aPoint1[19][2] = [[50, 20], [70, 0], [70, 0], [90, 20], [100, 30], [110, 40], [120, 50], [130, 60], [130, 70], [120, 70], [110, 70], [30, 70], [20, 70], [10, 70], [10, 60], [20, 50], [30, 40], [40, 30], [50, 20]]
Global $aPoint2[6][2] = [[0, 129], [55, 75], [75, 0], [95, 75], [150, 129], [75, 108]]

; 创建 GUI
$hForm = GUICreate('MyGUI', 400, 400)
$Pic = GUICtrlCreatePic('', 0, 0, 400, 400)
$hPic = GUICtrlGetHandle($Pic)

; 创建位图
$hDev = _WinAPI_GetDC($hPic)
$hDC = _WinAPI_CreateCompatibleDC($hDev)
$hSource = _WinAPI_CreateCompatibleBitmapEx($hDev, 400, 400, _WinAPI_SwitchColor(_WinAPI_GetSysColor($COLOR_3DFACE)))
$hSv = _WinAPI_SelectObject($hDC, $hSource)

; 描绘对象
$hOldBrush = _WinAPI_SelectObject($hDC, _WinAPI_GetStockObject($DC_BRUSH))
$hOldPen = _WinAPI_SelectObject($hDC, _WinAPI_GetStockObject($DC_PEN))
_WinAPI_SetDCBrushColor($hDC, 0x990404)
_WinAPI_SetDCPenColor($hDC, 0x990404)
$tRECT = _WinAPI_CreateRect(0, 0, 100, 100)
_WinAPI_OffsetRect($tRECT, 30, 30)
_WinAPI_Rectangle($hDC, $tRECT)
_WinAPI_OffsetRect($tRECT, 20, 20)
_WinAPI_InvertRect($hDC, $tRECT)
_WinAPI_OffsetRect($tRECT, 20, 20)
_WinAPI_InvertRect($hDC, $tRECT)
_WinAPI_SetDCPenColor($hDC, 0x00A820)
_WinAPI_SetBkColor($hDC, _WinAPI_SwitchColor(_WinAPI_GetSysColor($COLOR_3DFACE)))
$hBrush = _WinAPI_CreateBrushIndirect($BS_HATCHED, 0x00A820, $HS_DIAGCROSS)
$hObj = _WinAPI_SelectObject($hDC, $hBrush)
$tRECT = _WinAPI_CreateRect(0, 0, 140, 140)
_WinAPI_OffsetRect($tRECT, 220, 118)
_WinAPI_Ellipse($hDC, $tRECT)
_WinAPI_SelectObject($hDC, $hObj)
_WinAPI_DeleteObject($hBrush)
_WinAPI_SetTextColor($hDC, 0xCD0091)
_WinAPI_SetBkMode($hDC, $TRANSPARENT)
$hFont = _WinAPI_CreateFont(38, 0, 0, 0, $FW_NORMAL , 0, 0, 0, $DEFAULT_CHARSET, $OUT_DEFAULT_PRECIS, $CLIP_DEFAULT_PRECIS, $ANTIALIASED_QUALITY, $DEFAULT_PITCH, 'Arial Black')
$hObj = _WinAPI_SelectObject($hDC, $hFont)
_WinAPI_TextOut($hDC, 30, 185, 'Simple Text')
_WinAPI_SelectObject($hDC, $hObj)
_WinAPI_DeleteObject($hFont)
$hRgn = _WinAPI_CreatePolygonRgn($aPoint2)
_WinAPI_SetDCBrushColor($hDC, 0x0060C4)
_WinAPI_OffsetRgn($hRgn, 25, 240)
_WinAPI_PaintRgn($hDC, $hRgn)
_WinAPI_DeleteObject($hRgn)
_WinAPI_SetDCPenColor($hDC, 0xFF8000)
_WinAPI_OffsetPoints($aPoint1, 219, 25)
_WinAPI_PolyBezier($hDC, $aPoint1)
$hBrush = _WinAPI_CreateBrushIndirect($BS_SOLID, 0xFF8000)
$hObj = _WinAPI_SelectObject($hDC, $hBrush)
_WinAPI_ExtFloodFill($hDC, 70 + 219, 40 + 25, 0xFF8000, 0)
_WinAPI_SelectObject($hDC, $hObj)
_WinAPI_SelectObject($hDC, $hObj)
_WinAPI_DeleteObject($hBrush)
_WinAPI_SetDCPenColor($hDC, 0xFFFFFF)
$hPattern = _WinAPI_LoadImage(0, @ScriptDir & '\Extras\Pattern.bmp', $IMAGE_BITMAP, 0, 0, $LR_LOADFROMFILE)
;$hPattern = _WinAPI_LoadBitmap(_WinAPI_GetModuleHandle(@SystemDir & '\shell32.dll'), 138)
$hBrush = _WinAPI_CreateBrushIndirect($BS_PATTERN, 0, $hPattern)
$hObj = _WinAPI_SelectObject($hDC, $hBrush)
$tRECT = _WinAPI_CreateRect(0, 0, 140, 90)
_WinAPI_OffsetRect($tRECT, 220, 279)
_WinAPI_RoundRect($hDC, $tRECT, 20, 20)
_WinAPI_SelectObject($hDC, $hObj)
_WinAPI_DeleteObject($hPattern)
_WinAPI_DeleteObject($hBrush)

; 合并位图
$hBitmap = _WinAPI_CreateCompatibleBitmap($hDev, 400, 400)
$hBrush = _WinAPI_SelectObject($hDC, $hOldBrush)
_WinAPI_DeleteObject($hBrush)
$hPen = _WinAPI_SelectObject($hDC, $hOldPen)
_WinAPI_DeleteObject($hPen)
_WinAPI_SelectObject($hDC, $hBitmap)
_WinAPI_DrawBitmap($hDC, 0, 0, $hSource, $MERGECOPY)
_WinAPI_ReleaseDC($hPic, $hDev)
_WinAPI_SelectObject($hDC, $hSv)
_WinAPI_DeleteObject($hSource)
_WinAPI_DeleteDC($hDC)

; 设置位图到控件
_SendMessage($hPic, $STM_SETIMAGE, 0, $hBitmap)
$hObj = _SendMessage($hPic, $STM_GETIMAGE)
If $hObj <> $hBitmap Then
    _WinAPI_DeleteObject($hBitmap)
EndIf

GUISetState()

Do
Until GUIGetMsg() = -3