显示位图透明或半透明的像素.
#Include <WinAPIEx.au3>
_WinAPI_AlphaBlend ( $hDestDC, $iXDest, $iYDest, $iWidthDest, $iHeightDest, $hSrcDC, $iXSrc, $iYSrc, $iWidthSrc, $iHeightSrc, $iAlpha [, $fAlpha] )
$hDestDC | 目标设备环境句柄. |
$iXDest | 目标矩形左上角 x 坐标的逻辑单位值. |
$iYDest | 目标矩形左上角 y 坐标的逻辑单位值. |
$iWidthDest | 目标矩形宽度逻辑单位值. |
$iHeightDest | 目标矩形高度逻辑单位值. |
$hSrcDC | 源设备环境句柄. |
$iXSrc | 源矩形左上角 x 坐标的逻辑单位值. |
$iYSrc | 源矩形左上角 y 坐标的逻辑单位值. |
$iWidthSrc | 源矩形宽度逻辑单位值. |
$iHeightSrc | 源矩形高度逻辑单位值. |
$iAlpha | 用于整个源位图的 Alpha 透明度值. 此值为源位图每像素的 Alpha 值. 如果设置 $iAlpha为 0, 则图片是透明的; 当仅需使用每像素 alpha 值时, 设置 $iAlpha 值为 255(不透明). |
$fAlpha | [可选参数] 指定是否使用源位图的 Alpha 通道, 有效值为: 1 - 使用 Alpha 通道(即每像素 alpha).请注意, API 使用预乘 alpha, 即位图中的红, 绿和蓝色通道值必须与 Alpha 通道值预乘. 例如, 假设 Alpha 通道值是 x,在调用前, 红、绿和蓝色通道必须乘以 x 并除以 255. 0 - 不使用 Alpha 通道. (默认值) |
成功: | 返回 1. |
失败: | 返回 0,并设置@error标志为非 0 值. |
在MSDN中搜索
#Include <APIConstants.au3>
#include <GUIConstantsEx.au3>
#Include <SliderConstants.au3>
#Include <WinAPIEx.au3>
Opt('MustDeclareVars', 1)
Opt('TrayAutoPause', 0)
Global Const $STM_SETIMAGE = 0x0172
Global Const $STM_GETIMAGE = 0x0173
Global $hForm, $Msg, $Pic, $Slider, $hSlider, $tSIZE, $W, $H, $hBitmap
; Load image
$hBitmap = _WinAPI_LoadImage(0, @ScriptDir & '\Extras\AutoIt.bmp', $IMAGE_BITMAP, 0, 0, $LR_LOADFROMFILE)
$tSIZE = _WinAPI_GetBitmapDimension($hBitmap)
$W = DllStructGetData($tSIZE, 'X')
$H = DllStructGetData($tSIZE, 'Y')
; 创建 GUI
$hForm = GUICreate('MyGUI', $W, $H + 26)
$Pic = GUICtrlCreatePic('', 0, 0, $W, $H)
GUICtrlCreateGraphic(0, $H, $W, 1)
GUICtrlSetBkColor(-1, 0xDFDFDF)
$Slider = GUICtrlCreateSlider(0, $H + 1, $W, 25, BitOR($TBS_BOTH, $TBS_NOTICKS))
$hSlider = GUICtrlGetHandle(-1)
GUICtrlSetLimit(-1, 255, 0)
GUICtrlSetData(-1, 255)
; Set bitmap to control with alpha
_SetBitmapAlpha($Pic, $hBitmap, 255)
; Register WM_HSCROLL message for live scrolling and show GUI
GUIRegisterMsg($WM_HSCROLL, 'WM_HSCROLL')
GUISetState()
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
Func _SetBitmapAlpha($hWnd, $hBitmap, $iAlpha)
Local $tRECT, $tSIZE, $W[2], $H[2], $hDC, $hDestDC, $hDestSv, $hSrcDC, $hSrcSv, $hBmp, $hObj
If Not IsHWnd($hWnd) Then
$hWnd = GUICtrlGetHandle($hWnd)
If Not $hWnd Then
Return 0
EndIf
EndIf
$tRECT = _WinAPI_GetClientRect($hWnd)
$W[0] = DllStructGetData($tRECT, 3) - DllStructGetData($tRECT, 1)
$H[0] = DllStructGetData($tRECT, 4) - DllStructGetData($tRECT, 2)
$tSIZE = _WinAPI_GetBitmapDimension($hBitmap)
$W[1] = DllStructGetData($tSIZE, 1)
$H[1] = DllStructGetData($tSIZE, 2)
$hDC = _WinAPI_GetDC($hWnd)
$hDestDC = _WinAPI_CreateCompatibleDC($hDC)
$hBmp = _WinAPI_CreateCompatibleBitmapEx($hDC, $W[0], $H[0], 0xFFFFFF)
$hDestSv = _WinAPI_SelectObject($hDestDC, $hBmp)
$hSrcDC = _WinAPI_CreateCompatibleDC($hDC)
$hSrcSv = _WinAPI_SelectObject($hSrcDC, $hBitmap)
_WinAPI_AlphaBlend($hDestDC, 0, 0, $W[0], $H[0], $hSrcDC, 0, 0, $W[1], $H[1], $iAlpha, 0)
_WinAPI_SelectObject($hDestDC, $hDestSv)
_WinAPI_DeleteDC($hDestDC)
_WinAPI_SelectObject($hSrcDC, $hSrcSv)
_WinAPI_DeleteDC($hSrcDC)
_WinAPI_ReleaseDC($hWnd, $hDC)
$hObj = _SendMessage($hWnd, $STM_SETIMAGE, $IMAGE_BITMAP, $hBmp)
If $hObj Then
_WinAPI_DeleteObject($hObj)
EndIf
$hObj = _SendMessage($hWnd, $STM_GETIMAGE)
If $hObj <> $hBmp Then
_WinAPI_DeleteObject($hBmp)
EndIf
Return 1
EndFunc ;==>_SetBitmapAlpha
Func WM_HSCROLL($hWnd, $iMsg, $wParam, $lParam)
Switch $hWnd
Case $hForm
Switch $lParam
Case $hSlider
_SetBitmapAlpha($Pic, $hBitmap, GUICtrlRead($Slider))
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_HSCROLL