- Offizieller Beitrag
Hallo,
ich habe mal ein Script geschrieben bei dem eine GUI vor einem sich graufärbenden Hintergrund befinden. Dabei wird einfach von dem aktuellen Bildschirminhalt ein Snapshot gemacht und als Hintergrund gesetzt. Dieser Hintergrund wird dann schrittweise eingegraut. Wenn die GUI beendet wird, wird der Hintergrund schrittweise wieder eingefärbt.
Die Schrittweite für das Eingrauen und Einfärben kann seperat mit den Variablen $iGrayStep und $iColorStep eingestellt werden.
Die GUI $hGUIforGrayBK kann an die eingenen Bedürfnisse angepasst werden.
Zum kompilieren wird noch die Auto3Lib von Paul Campbell benötigt.
Edit:
Jetzt wird der gesamte Bereich eingegraut, auch bei mehr als einem Monitor!
Spoiler anzeigen
#include <A3LGDIPlus.au3>
#include <A3LScreenCap.au3>
HotKeySet("!{TAB}", "NoAltTab") ; Alt-Tab verhindern
HotKeySet("+!{TAB}", "NoAltTab") ; Shift-alt-Tab verhindern
Global const $tagCOLORADJUSTMENT = "ushort caSize;ushort caFlags;ushort caIlluminantIndex;ushort caRedGamma;" & _
"ushort caGreenGamma;ushort caBlueGamma;ushort caReferenceBlack;ushort caReferenceWhite;" & _
"short caContrast;short caBrightness;short caColorfulness;short caRedGreenTint;"
Global Const $BLACKONWHITE = 1
Global Const $WHITEONBLACK = 2
Global Const $COLORONCOLOR = 3
Global Const $HALFTONE = 4
Global Const $MAXSTRETCHBLTMODE = 4
Global Const $STRETCH_ANDSCANS = $BLACKONWHITE
Global Const $STRETCH_ORSCANS = $WHITEONBLACK
Global Const $STRETCH_DELETESCANS = $COLORONCOLOR
Global Const $STRETCH_HALFTONE = $HALFTONE
Global Const $cszFileName = @TempDir & "\$$" & @YEAR & @MON & @MDAY & @HOUR & @MIN & @SEC & "$$.jpg"
Global Const $iGrayStep = 2 ; Schrittweite fürs eingrauen
Global Const $iColorStep = 10 ; Schrittweite fürs einfärben
Global $hBMP, $hGUIDskTop, $hImage, $iSaturation, $hGUIforGrayBK
Global $hDllGdi32 = DllOpen("gdi32.dll")
Global $VirtualDskTop = GetVirtualScreenSize()
$hBMP = _ScreenCap_Capture($cszFileName, 0, 0, $VirtualDskTop[0], $VirtualDskTop[1], False)
#region An diesem Fenster keine Änderungen vornehmen
$hGUIDskTop = GUICreate("", $VirtualDskTop[0], $VirtualDskTop[1], 0, 0, -1, BitOR($WS_EX_TOPMOST, $WS_EX_LAYERED))
GUISetState()
WinSetOnTop($hGUIDskTop, "", 1 )
#endregion
_GDIP_Startup ()
$hImage = _GDIP_ImageLoadFromFile($cszFileName)
$iSaturation = 0 ; Farbsättigung, mögliche Werte von -100 (Grau) bis 100 (Farbe); Standard 0
SaturationBitmap($hGUIDskTop,$hImage,$iSaturation) ; Hintergrund beim 1. mal normal malen
#region Dieses Fenster nach eigenen Bedürfnissen anpassen
; !!! Achtung den Namen ($hGUIforGrayBK) und den parent-Parameter ($hGUIDskTop) nicht ändern !!!
$hGUIforGrayBK = GUICreate("Fenster vor grauen Hintergrund", 500, 200, -1, -1, BitOR($WS_SYSMENU, $WS_DLGFRAME), -1, $hGUIDskTop)
Local $lblInfo = GUICtrlCreateLabel("Diesen Fenster wird vor einem, sich" & @CRLF & "eingrauenden, Hintergund angezeigt.",15,20, 470, 120)
GUICtrlSetFont(-1,16)
Local $ButOK = GUICtrlCreateButton("OK",210,150,80,25)
GUISetState()
#endregion
WinSetOnTop($hGUIforGrayBK, "", 1 )
While 1
; Hintergrund eingrauen
If $iSaturation > -100 Then
$iSaturation -= Abs($iGrayStep)
If $iSaturation < -100 Then $iSaturation = -100
SaturationBitmap($hGUIDskTop,$hImage,$iSaturation)
Endif
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE
ExitLoop
Case $ButOK
ExitLoop
EndSwitch
WEnd
GUISetState(@SW_HIDE,$hGUIforGrayBK)
; Hintergrund wieder einfärben
While $iSaturation < 0
$iSaturation += Abs($iColorStep)
If $iSaturation > 0 Then $iSaturation = 0
SaturationBitmap($hGUIDskTop,$hImage,$iSaturation)
Wend
_GDIP_Shutdown ()
If $hDllGdi32 > 0 Then DllClose($hDllGdi32)
FileDelete($cszFileName)
; + ----------------------------------------------------- +
; | Funktionen aus gdi32.dll |
; + ----------------------------------------------------- +
Func _GDI32_GetColorAdjustment($hDC)
Local $aResult
Local $tData = DllStructCreate($tagCOLORADJUSTMENT)
Local $pData = DllStructGetPtr($tData)
$aResult = DllCall($hDllGdi32, "int", "GetColorAdjustment", "hwnd", $hDC, "ptr", $pData)
Return SetError(1 * ($aResult[0] = 0), 0, $tData)
EndFunc
Func _GDI32_SetColorAdjustment($hDC, $tData)
Local $aResult
Local $pData = DllStructGetPtr($tData)
$aResult = DllCall($hDllGdi32, "int", "SetColorAdjustment", "hwnd", $hDC, "ptr", $pData)
Return SetError(1 * ($aResult[0] = 0), 0, $tData)
EndFunc
Func _GDI32_SetStretchBltMode($hDC, $iStretchMode)
Local $aResult
$aResult = DllCall($hDllGdi32, "int", "SetStretchBltMode", "hwnd", $hDC, "int", $iStretchMode)
Return SetError(1 * ($aResult[0] = 0), 0, $aResult[0])
EndFunc
Func _GDI32_StretchBlt($hdcDest,$nXOriginDest,$nYOriginDest,$nWidthDest,$nHeightDest,$hdcSrc,$nXOriginSrc,$nYOriginSrc,$nWidthSrc,$nHeightSrc,$dwRop)
Local $aResult
$aResult = DllCall($hDllGdi32, "int", "StretchBlt", _
"hwnd", $hdcDest, _
"int", $nXOriginDest, _
"int", $nYOriginDest, _
"int", $nWidthDest, _
"int", $nHeightDest, _
"hwnd", $hdcSrc, _
"int", $nXOriginSrc, _
"int", $nYOriginSrc, _
"int", $nWidthSrc, _
"int", $nHeightSrc, _
"dword", $dwRop _
)
Return SetError(1 * ($aResult[0] = 0), 0, ($aResult[0] = 1))
EndFunc
Func SaturationBitmap($hGUI, $hImage, $iSaturation)
Local $hScrDC, $hMemDC, $hBitmap, $hOldBitmap, $pSize, $tSize, $pSource, $tSource, $tCA
$hScrDC = _API_GetDC(0)
$hMemDC = _API_CreateCompatibleDC($hScrDC)
$hBitmap = _GDIP_BitmapCreateHBITMAPFromBitmap($hImage)
$hOldBitmap = _API_SelectObject($hMemDC, $hBitmap)
$tSize = DllStructCreate($tagSIZE)
$pSize = DllStructGetPtr($tSize )
DllStructSetData($tSize, "X", _GDIP_ImageGetWidth ($hImage))
DllStructSetData($tSize, "Y", _GDIP_ImageGetHeight($hImage))
$tSource = DllStructCreate($tagPOINT)
$pSource = DllStructGetPtr($tSource)
_GDI32_SetStretchBltMode($hMemDC,$HALFTONE)
$tCA = _GDI32_GetColorAdjustment($hMemDC)
DllStructSetData($tCA,"caColorfulness",$iSaturation)
_GDI32_SetColorAdjustment($hMemDC,$tCA)
_GDI32_StretchBlt($hMemDC,0,0,$VirtualDskTop[0],$VirtualDskTop[1],$hMemDC,0,0,$VirtualDskTop[0],$VirtualDskTop[1],$SRCCOPY)
_API_UpdateLayeredWindow($hGUI, $hScrDC, 0, $pSize, $hMemDC, $pSource, 0, 0, 0)
_API_ReleaseDC (0, $hScrDC)
_API_SelectObject($hMemDC, $hOldBitmap)
_API_DeleteObject($hBitmap)
_API_DeleteDC ($hMemDC)
EndFunc
Func NoAltTab()
; Pseudofunktion um den Hotkey
; Alt-Tab zu verhindern
EndFunc
Func GetVirtualScreenSize()
Local $aVSS[2] = [0, 0]
$aVSS[0] = _API_GetSystemMetrics($SM_CXVIRTUALSCREEN)
$aVSS[1] = _API_GetSystemMetrics($SM_CYVIRTUALSCREEN)
If ($aVSS[0] = 0) Or ($aVSS[1] = 0) Then
$aVSS[0] = 0
$aVSS[1] = 0
EndIf
Return SetError(($aVSS[0] Or $aVSS[1]),0, $aVSS)
EndFunc