函数参考


_WinAPI_CreateDIBSection

创建应用程序可以直接写入的 DIB(设备无关位图文件).

#Include <WinAPIEx.au3>
_WinAPI_CreateDIBSection ( $hDC, ByRef $tBITMAPINFO, $iUsage, ByRef $pBits [, $hSection [, $iOffset]] )

参数

$hDC 设备环境句柄. 如果 $iUsage 为 $DIB_PAL_COLORS,
 函数使用设备环境的逻辑调色板初始 DIB 颜色.
$tBITMAPINFO tagBITMAPINFO 结构, 指定 DIB 的各种属性,包括位图的尺寸和颜色.
$iUsage $pBits 数据的类型.(逻辑调色板的索引或 RGB 值).
 有下列定义值:
 $DIB_PAL_COLORS --- 颜色表包含当前逻辑调色板的16位索引数组.
 $DIB_RGB_COLORS --- 颜色表包含 RGB 值
$pBits 指向 DIB 位值的定位指针.
$hSection [可选参数] 函数用于创建 DIB 文件映射对象的句柄.
$iOffset [可选参数] $hSection 文件映射对象位图存储开始位值的偏移量.
 如果 $hSection 为 0, 此值将被忽略.

返回值

成功: 返回新创建 DIB 的句柄, $pBits 指向位图的位值.
可以使用 $pBits 指针创建结构, 以便进一步填充 DIB,
例如:DllStructCreate('dword[4]', $pBits).
失败: 返回 0,设置 @error 标志为非 0 值, $pBits 也为 0.

注意/说明

使用完图标, 调用 _WinAPI_DestroyIcon() 函数将其销毁.

相关

详情参考

在MSDN中搜索


示例/演示


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

Opt('MustDeclareVars', 1)

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

Global $hForm, $Pic, $hPic, $tBIV5HDR, $tBits, $pBits, $hBitmap, $hObj

; Create 32 bits-per-pixel device-independent bitmap (DIB) that use a mask
$tBIV5HDR = DllStructCreate($tagBITMAPV5HEADER)

DllStructSetData($tBIV5HDR, 'bV5Size', DllStructGetSize($tBIV5HDR))
DllStructSetData($tBIV5HDR, 'bV5Width', 256)
DllStructSetData($tBIV5HDR, 'bV5Height', 256)
DllStructSetData($tBIV5HDR, 'bV5Planes', 1)
DllStructSetData($tBIV5HDR, 'bV5BitCount', 32)
DllStructSetData($tBIV5HDR, 'biCompression', $BI_BITFIELDS)
DllStructSetData($tBIV5HDR, 'bV5SizeImage', 0)
DllStructSetData($tBIV5HDR, 'bV5XPelsPerMeter', 0)
DllStructSetData($tBIV5HDR, 'bV5YPelsPerMeter', 0)
DllStructSetData($tBIV5HDR, 'bV5ClrUsed', 0)
DllStructSetData($tBIV5HDR, 'bV5ClrImportant', 0)
DllStructSetData($tBIV5HDR, 'bV5RedMask', 0x00FF0000)
DllStructSetData($tBIV5HDR, 'bV5GreenMask', 0x0000FF00)
DllStructSetData($tBIV5HDR, 'bV5BlueMask', 0x000000FF)
DllStructSetData($tBIV5HDR, 'bV5AlphaMask', 0xFF000000)
DllStructSetData($tBIV5HDR, 'bV5CSType', 0)
DllStructSetData($tBIV5HDR, 'bV5Endpoints', 0, 1)
DllStructSetData($tBIV5HDR, 'bV5Endpoints', 0, 2)
DllStructSetData($tBIV5HDR, 'bV5Endpoints', 0, 3)
DllStructSetData($tBIV5HDR, 'bV5GammaRed', 0)
DllStructSetData($tBIV5HDR, 'bV5GammaGreen', 0)
DllStructSetData($tBIV5HDR, 'bV5GammaBlue', 0)
DllStructSetData($tBIV5HDR, 'bV5Intent', 0)
DllStructSetData($tBIV5HDR, 'bV5ProfileData', 0)
DllStructSetData($tBIV5HDR, 'bV5ProfileSize', 0)
DllStructSetData($tBIV5HDR, 'bV5Reserved', 0)

$hBitmap = _WinAPI_CreateDIBSection(0, $tBIV5HDR, $DIB_RGB_COLORS, $pBits)

; Fill bitmap green with variable alpha chanel
$tBits = DllStructCreate('dword[65536]', $pBits)
For $y = 0 To 255
    For $x = 1 To 256
        DllStructSetData($tBits, 1, BitOR(0x00FF00, BitShift($y, -24)), $x + (256 * $y))
    Next
Next

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

; Set bitmap to control
_SendMessage($hPic, $STM_SETIMAGE, 0, $hBitmap)
$hObj = _SendMessage($hPic, $STM_GETIMAGE)
If $hObj <> $hBitmap Then
    _WinAPI_DeleteObject($hBitmap)
EndIf

; Set background color to green and show GUI
GUISetBkColor(0x0000FF)
GUISetState()

Do
Until GUIGetMsg() = -3