GDI操作,并图像一直存在
#include <WindowsConstants.au3>
#Include <WinAPIEx.au3>
$image1="1111.bmp"
$image2="2222.bmp"
;让窗口的绘制交给函数OWNER_WM_PAINT
GUIRegisterMsg($WM_PAINT, "OWNER_WM_PAINT")
$hGui=GUICreate("",200,100)
GUISetState(@SW_SHOW)
While GUIGetMsg()+3
WEnd
;绘制函数OWNER_WM_PAINT
Func OWNER_WM_PAINT($hWnd, $Msg, $wParam, $lParam)
;读入图像
Local $hTotalImage = _WinAPI_LoadImage(0, $image1, $IMAGE_BITMAP, 0, 0, $LR_LOADFROMFILE)
Local $hBackImage = _WinAPI_LoadImage(0, $image2, $IMAGE_BITMAP, 0, 0, $LR_LOADFROMFILE)
;WM_PAINT必须
Local $tPAINTSTRUCT
Local $hDC = _WinAPI_BeginPaint($hWnd, $tPAINTSTRUCT)
;背景图像读入内存DC
Local $hBackDC = _WinAPI_CreateCompatibleDC($hDC)
Local $hBackSv = _WinAPI_SelectObject($hBackDC, $hBackImage)
;图标图像读入内存DC
Local $hTotalDC = _WinAPI_CreateCompatibleDC($hDC)
Local $hTotalSv = _WinAPI_SelectObject($hTotalDC, $hTotalImage)
;处理图标透明所需的掩码图像DC
Local $hMaskDC = _WinAPI_CreateCompatibleDC($hDC)
Local $hMask = _WinAPI_CreateCompatibleBitmap($hDC, 23, 23)
Local $hMaskSv = _WinAPI_SelectObject($hMaskDC, $hMask)
_WinAPI_BitBlt($hMaskDC, 0,0,23,23,$hTotalDC,0,0,$NOTSRCCOPY);23是掩码图像的长宽,掩码在0,0
;掩码图像和所需图标XOR操作
Local $hTempDC = _WinAPI_CreateCompatibleDC($hDC)
Local $hTemp = _WinAPI_CreateCompatibleBitmap($hDC, 23, 23)
Local $hTempSv = _WinAPI_SelectObject($hTempDC, $hTemp)
_WinAPI_BitBlt($hTempDC, 0,0,23,23,$hTotalDC,23,0,$SRCCOPY);所需图标在23,0、后一个在46,0
_WinAPI_BitBlt($hTempDC, 0,0,23,23,$hMaskDC,0,0,$SRCINVERT);掩码图像与图标XOR操作
;把背景图像拉伸绘制到窗口上
_WinAPI_StretchBlt($hDC, 0,0,200,100,$hBackDC,0,0,128,48,$SRCCOPY)
;把掩码图像和背景图像AND操作
_WinAPI_BitBlt($hDC, 60, 20, 23, 23,$hMaskDC, 0, 0, $SRCAND)
;把 “掩码图像和所需图标XOR操作” 合成后的图像 与 上面的掩码OR操作,完成透明
_WinAPI_BitBlt($hDC, 60, 20, 23, 23,$hTempDC, 0, 0, $SRCPAINT)
;删除用过的对象
_WinAPI_SelectObject($hTempDC, $hTempSv)
_WinAPI_SelectObject($hMaskDC, $hMaskSv)
_WinAPI_SelectObject($hBackDC, $hBackSv)
_WinAPI_SelectObject($hTotalDC, $hTotalSv)
_WinAPI_DeleteObject($hMask)
_WinAPI_DeleteObject($hTemp)
_WinAPI_DeleteObject($hTotalImage)
_WinAPI_DeleteObject($hBackImage)
_WinAPI_DeleteDC($hTotalDC)
_WinAPI_DeleteDC($hTempDC)
_WinAPI_DeleteDC($hMaskDC)
_WinAPI_DeleteDC($hBackDC)
Return _WinAPI_EndPaint($hWnd, $tPAINTSTRUCT)
EndFunc
|