Code : Tout sélectionner
#include <StructureConstants.au3>
#include <WindowsConstants.au3>
#include <GDIPlus.au3>
#include <WinAPI.au3>
#include <GuiConstantsEx.au3>
Opt("MustDeclareVars", 1)
; ===============================================================================================================================
; Description ...: Shows how to create an alpha blended form
; Author ........: Paul Campbell (PaulIA)
; Notes .........: The images used for this demo MUST be 32 bpp with alpha channel
; Credits .......: Thanks to lod3n for supplying links to the technical documentation that was necessary to build this demo
; ===============================================================================================================================
; ===============================================================================================================================
; Global constants
; ===============================================================================================================================
Global Const $AC_SRC_ALPHA = 1
;Global Const $ULW_ALPHA = 2
; ===============================================================================================================================
; Global variables
; ===============================================================================================================================
Global $hGUI1, $hGUI2, $iLabel1, $iLabel2, $iSlider, $hImage, $hMemD, $player, $nMsg, $CONTROL_GUI
; Create layered child window
$hGUI1 = GUICreate("Test", 250, 250, -1, -1, $WS_POPUP, $WS_EX_LAYERED)
; Load layered image
_GDIPlus_Startup()
$hImage = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\Background1.png")
SetBitMap($hGUI1, $hImage, 255)
$CONTROL_GUI = GUICreate("aaaaaaaaaa", 250, 250, 0, 0, $WS_POPUP, Bitor($WS_EX_LAYERED, $WS_EX_MDICHILD), $hGUI1)
GUISetBkColor(0xABCDEF,$CONTROL_GUI )
_WinAPI_SetLayeredWindowAttributes($CONTROL_GUI, 0xABCDEF)
$player = GUICtrlCreateLabel("", 46, 26, 30, 30)
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
GUICtrlSetCursor(-1, 0)
GUICtrlCreateInput("blablabla", 200, 5, 50, 15)
GUISetState(@SW_SHOW, $hGUI1)
GUISetState(@SW_SHOW, $CONTROL_GUI)
; Register notification messages
;~ GUIRegisterMsg($WM_HSCROLL , "WM_HSCROLL" )
GUIRegisterMsg($WM_NCHITTEST, "WM_NCHITTEST")
; Loop until user exits
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
case $player
MsgBox(0, "", "player", 5)
EndSwitch
WEnd
; Release resources
_GDIPlus_ImageDispose($hImage)
_GDIPlus_Shutdown()
; ===============================================================================================================================
; Handle the WM_HSCROLL notificaton so that we can change the opacity in real time
; ===============================================================================================================================
Func WM_HSCROLL($hWnd, $iMsg, $iwParam, $ilParam)
SetBitMap($hGUI2, $hImage, GUICtrlRead($iSlider))
EndFunc
; ===============================================================================================================================
; Handle the WM_NCHITTEST for the layered window so it can be dragged by clicking anywhere on the image.
; ===============================================================================================================================
Func WM_NCHITTEST($hWnd, $iMsg, $iwParam, $ilParam)
if ($hWnd = $hGUI2) and ($iMsg = $WM_NCHITTEST) then Return $HTCAPTION
EndFunc
; ===============================================================================================================================
; SetBitMap
; ===============================================================================================================================
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", $AC_SRC_ALPHA)
_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