Code : Tout sélectionner
#include <GDIPlus.au3>
#include <WindowsConstants.au3>
#include <GuiConstantsEx.au3>
Global Const $AC_SRC_ALPHA = 1
_Notification("RL77LUC au boulot !", 0, "cp")
;===============================================
Func _Notification($text, $timeout, $background = "default")
_GDIPlus_Startup()
$hImage = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\" & $background & ".png")
$GUI = GUICreate("Test", 0, 73, -1, -1, $WS_POPUP, $WS_EX_LAYERED + $WS_EX_TOPMOST)
SetBitMap($GUI, $hImage, 255)
$hBmp = _ImageDrawText($hImage, $text, 90, 27, 0xD3D3D3, 11, 0, "Helvetica-Bold")
SetBitMap($GUI, $hBmp, 255)
$GUI2 = GUICreate("msg", 300, 150, -1, -1, $WS_POPUP, $WS_EX_LAYERED + $WS_EX_TOPMOST + $WS_EX_COMPOSITED + $WS_EX_MDICHILD, $GUI)
GUISetBkColor(0x1D570B)
;~ $label = GuiCtrlCreateLabel($text, 80, 27, 200, 50)
;~ GUICtrlSetBkColor($label,$GUI_BKCOLOR_TRANSPARENT)
;~ GUICtrlSetFont(-1, 11, 400, 0, "Helvetica-Bold")
;~ GUICtrlSetColor(-1, 0xD3D3D3)
;~ GUICtrlSetState($label,$GUI_ONTOP)
$croix = GuiCtrlCreatePic("file3.bmp", 4, 4, 19, 19)
;~ _WinAPI_SetLayeredWindowAttributes($GUI2, 0x1D570B, 255)
WinMove("Test","", @DesktopWidth - 353, @DesktopHeight - 130)
For $i = 0 to 255 step 5
If $i = 5 Then
GUISetState(@SW_SHOW,$GUI)
GUISetState(@SW_SHOW,$GUI2)
EndIf
SetBitMap($GUI, $hImage, $i)
_WinAPI_SetLayeredWindowAttributes($GUI2, 0x1D570B, $i)
Sleep(30)
Next
$start = TimerInit()
If $timeout=0 Then
$TimeOutEnable = False
Else
$TimeOutEnable = True
EndIf
While 1
If (TimerDiff($start)>$timeout AND $TimeOutEnable = True) OR GuiGetMsg() = $croix Then
For $i = 255 to 0 step -5
SetBitMap($GUI, $hImage, $i)
_WinAPI_SetLayeredWindowAttributes($GUI2, 0x1D570B, $i)
Sleep(30)
Next
_GDIPlus_ImageDispose($hImage)
_GDIPlus_Shutdown()
ExitLoop
EndIf
Wend
EndFunc
;=========================================================
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
Func _ImageDrawText($hImage, $sText, $iX = 0, $iY = 0, $iRGB = 0x000000, $iSize = 9, $iStyle = 0, $sFont = "Arial")
Local $w, $h, $hGraphic1, $hBitmap, $hGraphic2, $hBrush, $hFormat, $hFamily, $hFont, $tLayout, $aInfo
$w = _GDIPlus_ImageGetWidth($hImage)
$h = _GDIPlus_ImageGetHeight($hImage)
;Create a new bitmap, this way the original opened png is left unchanged
$hGraphic1 = _GDIPlus_GraphicsCreateFromHWND(_WinAPI_GetDesktopWindow())
$hBitmap = _GDIPlus_BitmapCreateFromGraphics($w, $h, $hGraphic1)
$hGraphic2 = _GDIPlus_ImageGetGraphicsContext($hBitmap)
; Draw the original opened png into my newly created bitmap
_GDIPlus_GraphicsDrawImageRect($hGraphic2, $hImage, 0, 0, $w, $h)
;Create the font
$hBrush = _GDIPlus_BrushCreateSolid ("0xFF" & Hex($iRGB, 6))
$hFormat = _GDIPlus_StringFormatCreate()
$hFamily = _GDIPlus_FontFamilyCreate ($sFont)
$hFont = _GDIPlus_FontCreate ($hFamily, $iSize, $iStyle)
$tLayout = _GDIPlus_RectFCreate ($iX, $iY, 0, 0)
$aInfo = _GDIPlus_GraphicsMeasureString ($hGraphic2, $sText, $hFont, $tLayout, $hFormat)
;Draw the font onto the new bitmap
_GDIPlus_GraphicsDrawStringEx ($hGraphic2, $sText, $hFont, $aInfo[0], $hFormat, $hBrush)
;Cleanup the no longer needed resources
_GDIPlus_FontDispose ($hFont)
_GDIPlus_FontFamilyDispose ($hFamily)
_GDIPlus_StringFormatDispose ($hFormat)
_GDIPlus_BrushDispose ($hBrush)
_GDIPlus_GraphicsDispose ($hGraphic2)
_GDIPlus_GraphicsDispose ($hGraphic1)
;Return the new bitmap
Return $hBitmap
EndFunc