Code : Tout sélectionner
#include <GDIPlus.au3>
#include <WindowsConstants.au3>
#include <GuiConstantsEx.au3>
_GDIPlus_Startup()
$autoitlogo = @tempdir & "\autoit_logo.png"
InetGet("http://affz.free.fr/autoit/autoit_logo.png", $autoitlogo)
$img = "c:\Program Files\AutoIt3\Examples\GUI\Torus.png"
$gui = _GUICreate_Alpha("gui_fond", $img)
$handle = WinGetHandle("gui_fond")
GUISetState()
$gui1 = GUICreate("cont", 400, 400, 0, 0, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_MDICHILD), $handle)
$exit = GUICtrlCreateButton("Exit", 100, 100, 50, 30)
GUISetBkColor(0xABCDEF)
_WinAPI_SetLayeredWindowAttributes($gui1, 0xABCDEF, 255)
GUISetState()
$gui2 = GUICreate("test2", 100, 100, -1, -1, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_MDICHILD), $handle)
$hImage = _GDIPlus_ImageLoadFromFile($autoitlogo)
SetBitMap($gui2, $hImage, 255)
GUISetState()
GUIRegisterMsg($WM_NCHITTEST, "WM_NCHITTEST")
While 1
$msg = GUIGetMsg()
Select
Case $msg = $exit
_GDIPlus_Shutdown()
Exit
EndSelect
WEnd
;=====================================================================
Func WM_NCHITTEST($hWnd, $iMsg, $iwParam, $ilParam)
If ($hwnd = $handle) And ($iMsg = $WM_NCHITTEST) Then Return $HTCAPTION
EndFunc
Func _GUICreate_Alpha($sTitle, $sPath, $iX=-1, $iY=-1, $iOpacity=255)
Local $hGUI, $hImage, $hScrDC, $hMemDC, $hBitmap, $hOld, $pSize, $tSize, $pSource, $tSource, $pBlend, $tBlend
$hImage = _GDIPlus_ImageLoadFromFile($sPath)
$width = _GDIPlus_ImageGetWidth($hImage)
$height = _GDIPlus_ImageGetHeight($hImage)
$hGUI = GUICreate($sTitle, $width, $height, $iX, $iY, $WS_POPUP, $WS_EX_LAYERED)
$hScrDC = _WinAPI_GetDC(0)
$hMemDC = _WinAPI_CreateCompatibleDC($hScrDC)
$hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
$hOld = _WinAPI_SelectObject($hMemDC, $hBitmap)
$tSize = DllStructCreate($tagSIZE)
$pSize = DllStructGetPtr($tSize)
DllStructSetData($tSize, "X", $width)
DllStructSetData($tSize, "Y", $height)
$tSource = DllStructCreate($tagPOINT)
$pSource = DllStructGetPtr($tSource)
$tBlend = DllStructCreate($tagBLENDFUNCTION)
$pBlend = DllStructGetPtr($tBlend)
DllStructSetData($tBlend, "Alpha", $iOpacity)
DllStructSetData($tBlend, "Format", 1)
_WinAPI_UpdateLayeredWindow($hGUI, $hScrDC, 0, $pSize, $hMemDC, $pSource, 0, $pBlend, 2)
_WinAPI_ReleaseDC(0, $hScrDC)
_WinAPI_SelectObject($hMemDC, $hOld)
_WinAPI_DeleteObject($hBitmap)
_WinAPI_DeleteObject($hImage)
_WinAPI_DeleteDC($hMemDC)
EndFunc ;==>_GUICreate_Alpha
Func SetBitmap($hGUI, $hImage, $iOpacity)
Local $hScrDC, $hMemDC, $hBitmap, $hOld, $pSize, $tSize, $pSource, $tSource, $pBlend, $tBlend
$hScrDC = _WinAPI_GetDC(0)
$hMemDC = _WinAPI_CreateCompatibleDC($hScrDC)
$hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
$hOld = _WinAPI_SelectObject($hMemDC, $hBitmap)
$tSize = DllStructCreate($tagSIZE)
$pSize = DllStructGetPtr($tSize)
DllStructSetData($tSize, "X", _GDIPlus_ImageGetWidth($hImage))
DllStructSetData($tSize, "Y", _GDIPlus_ImageGetHeight($hImage))
$tSource = DllStructCreate($tagPOINT)
$pSource = DllStructGetPtr($tSource)
$tBlend = DllStructCreate($tagBLENDFUNCTION)
$pBlend = DllStructGetPtr($tBlend)
DllStructSetData($tBlend, "Alpha", $iOpacity)
DllStructSetData($tBlend, "Format", 1) ;$AC_SRC_ALPHA = 1
_WinAPI_UpdateLayeredWindow($hGUI, $hScrDC, 0, $pSize, $hMemDC, $pSource, 0, $pBlend, $ULW_ALPHA)
_WinAPI_ReleaseDC(0, $hScrDC)
_WinAPI_SelectObject($hMemDC, $hOld)
_WinAPI_DeleteObject($hBitmap)
_WinAPI_DeleteDC($hMemDC)
EndFunc ;==>SetBitmap