函数参考


_WinAPI_DrawBitmap

绘制位图到指定的设备环境.

#Include <WinAPIEx.au3>
_WinAPI_DrawBitmap ( $hDC, $iX, $iY, $hBitmap [, $iRop] )

参数

$hDC 设备环境句柄.
$iX 位图左上角逻辑 x 坐标.
$iY 位图左上角逻辑 y 坐标.
$hBitmap 位图句柄.
$iRop [可选参数] 光栅操作代码(与 _WinAPI_BitBlt() 相同).

返回值

成功: 返回 1.
失败: 返回 0,设置@error标志为非 0 值.

注意/说明

本函数不支持 Alpha 通道的位图, 有此需求请使用 _WinAPI_AlphaBlend().

相关

详情参考

None

示例/演示


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

Opt('MustDeclareVars', 1)

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

Global $hForm, $Pic, $hPic, $tSIZE, $W, $H, $hObj, $hBitmap, $hSource, $hDC, $hDestDC, $hDestSv

; 加载图像
$hSource = _WinAPI_LoadImage(0, @ScriptDir & '\Extras\Logo.bmp', $IMAGE_BITMAP, 0, 0, $LR_LOADFROMFILE)
$tSIZE = _WinAPI_GetBitmapDimension($hSource)
$W = DllStructGetData($tSIZE, 'X')
$H = DllStructGetData($tSIZE, 'Y')

; 创建 GUI
$hForm = GUICreate('MyGUI', $W, 4 * $H)
$Pic = GUICtrlCreatePic('', 0, 0, $W, 4 * $H)
$hPic = GUICtrlGetHandle($Pic)

; 创建位图
$hDC = _WinAPI_GetDC($hPic)
$hDestDC = _WinAPI_CreateCompatibleDC($hDC)
$hBitmap = _WinAPI_CreateCompatibleBitmap($hDC, $W, 4 * $H)
$hDestSv = _WinAPI_SelectObject($hDestDC, $hBitmap)
For $i = 0 To 3
    _WinAPI_DrawBitmap($hDestDC, 0, $i * $H, $hSource)
Next

_WinAPI_ReleaseDC($hPic, $hDC)
_WinAPI_SelectObject($hDestDC, $hDestSv)
_WinAPI_DeleteObject($hSource)
_WinAPI_DeleteDC($hDestDC)

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

GUISetState()

Do
Until GUIGetMsg() = -3