Code : Tout sélectionner
; nom du script = [b]notif_base.au3[/b] (sinon, corriger le nom dans le script de lancement commande.au3)
#include <GDIPlus.au3>
#include <WindowsConstants.au3>
#include <GuiConstantsEx.au3>
#Include <Clipboard.au3>
_Notification(_ClipBoard_GetData())
;===============================================
Func _Notification($data)
$elmts = StringSplit ($data, "#")
$text = $elmts[1]
$timeout = 0
$bk = 1
If $elmts[0] = 2 Then $timeout = $elmts[2]
If $elmts[0] = 3 Then
$timeout = $elmts[2]
$bk = $elmts[3]
EndIf
Opt("WinTitleMatchMode", 2)
_GDIPlus_Startup()
If $bk = 1 Then
$hImage = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\file2.png") ; $bk = 1 pour background n°1
Else
$hImage = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\file2.png") ; $bk = 2 pour background n°2
EndIf
$var = WinList("Notification")
For $i = 1 to $var[0][0] [color=#008000]; vérifie s'il existe déjà des notifications[/color]
If WinExists($var[$i][0]) Then [color=#008000]; si oui, les déplace de 80 px vers le haut[/color]
$prevpos = WinGetPos($var[$i][0]) [color=#008000]; pour faire la place à la nouvelle[/color]
WinMove($var[$i][0], "", $prevpos[0], $prevpos[1]-80)
EndIf
Next
$Xposition = @desktopwidth - 400
$Yposition = @desktopheight - 160
Global $GUI = GUICreate("Notification"& $i, 323, 73, $Xposition, $Yposition, $WS_POPUP, $WS_EX_LAYERED)
SetBitMap($GUI, $hImage, 255)
$hBmp = _ImageDrawText($hImage, $text, 90, 25, 0xffffff, 12, 0, "Comic Sans MS")
SetBitMap($GUI, $hBmp, 255)
GUISetState()
$GUI2 = GUICreate("msg" & $i, 25, 25, -1, -1, $WS_POPUP, $WS_EX_LAYERED + $WS_EX_COMPOSITED + $WS_EX_MDICHILD, $GUI)
GUISetBkColor(0x000005)
$croix = GuiCtrlCreatePic("file3.bmp", 4, 4, 19, 19)
_WinAPI_SetLayeredWindowAttributes($GUI2, 0x000005, 255)
GUISetState()
Local $start = TimerInit()
While 1
If (TimerDiff($start)>$timeout AND $timeout>0) OR GuiGetMsg() = $croix Then
For $i = 255 to 0 step -10
SetBitMap($GUI, $hImage, $i)
GUISetState (@SW_ENABLE, $GUI)
SetBitMap($GUI, $hBmp, $i)
_WinAPI_SetLayeredWindowAttributes($GUI2, 0x000005, $i)
Sleep(21)
Next
$guititle = WinGetTitle($GUI)
$pos0 = WinGetPos($guititle)
GuiDelete($GUI)
GuiDelete($GUI2)
$var2 = WinList("Notification")
If $var2[0][0]>0 Then
For $i = 1 to $var2[0][0] [color=#008000]; compte les notifications[/color]
$pos = WinGetPos($var2[$i][0]) [color=#008000]; vérifie leur position[/color]
If $pos[1]<$pos0[1] Then WinMove($var2[$i][0], "", $pos[0], $pos[1]+80) [color=#008000]; si ya un espace, descend de 80 px celles qui sont au-dessus[/color]
Next
EndIf
ExitLoop
EndIf
Wend
_GDIPlus_ImageDispose($hBmp)
_GDIPlus_ImageDispose($hImage)
_GDIPlus_Shutdown()
Exit
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", 1) ;Global Const $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
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