Dieses Mini Script Sucht alle Bilder im Scriptverzeichnis eigestellten Verzeichnis und setzt zufällig Eines als neuen Desktophintergrund (Ja ich weiß, dass das nichts besonderes ist).
Unterstützte Dateiformate: jpg; png; bmp; gif
Spoiler anzeigen
#include <File.au3>
#include <Array.au3>
#include <GDIPlus.au3>
Opt("TrayMenuMode", 1)
Opt("TrayOnEventMode", 1)
Global $sPicFolder = IniRead("Settings.ini", "Paths", "PicPath", @ScriptDir)
[/autoit] [autoit][/autoit] [autoit]Global $aExtPics[6]
$aExtPics[0] = 5
$aExtPics[1] = 'jpeg'
$aExtPics[2] = 'jpg'
$aExtPics[3] = 'png'
$aExtPics[4] = 'bmp'
$aExtPics[5] = 'gif'
$sTempFilePath = @TempDir & "\+~RandomWallPaper~+.bmp"
$sBackUpFilePath = @TempDir & "\+~RandomWallPaperBackUp~+.bmp"
$cRandomWallpaper = TrayCreateItem("Zufälliges WallPaper")
$cUndo = TrayCreateItem("Letztes WallPaper wiederherstellen")
$cPicPath = TrayCreateItem("Bilderpfad auswählen")
$cExit = TrayCreateItem("Beenden")
TrayItemSetOnEvent($cRandomWallpaper, "_SetRandomWallPaper")
TrayItemSetOnEvent($cPicPath, "_PicPath")
TrayItemSetOnEvent($cUndo, "_Undo")
TrayItemSetOnEvent($cExit, "_Exit")
$aPics = _FileListToArrayEx($sPicFolder, $aExtPics)
If $aPics = 0 Then _PathInValid()
While Sleep(100)
WEnd
Func _SetRandomWallPaper()
TrayItemSetState($cRandomWallpaper, 4)
If FileExists($sTempFilePath) Then FileCopy($sTempFilePath, $sBackUpFilePath, 1)
_GDIPlus_Startup()
$hBitmapWallPaper = _GDIPlus_BitmapCreateFromFile($sPicFolder & "\" & $aPics[Random(1, $aPics[0], 1)])
_GDIPlus_ImageSaveToFile($hBitmapWallPaper, $sTempFilePath)
_GDIPlus_BitmapDispose($hBitmapWallPaper)
_GDIPlus_Shutdown()
_SetWallPaper($sTempFilePath)
EndFunc ;==>_SetRandomWallPaper
Func _PicPath()
TrayItemSetState($cPicPath, 4)
$sPicFolderTmp = FileSelectFolder("Dateipfad auswählen", "", 7, $sPicFolder)
If Not @error And IsArray(_FileListToArrayEx($sPicFolderTmp, $aExtPics)) Then
If StringRight($sPicFolderTmp, 1) = "\" Then $sPicFolderTmp = StringTrimRight($sPicFolderTmp, 1)
$sPicFolder = $sPicFolderTmp
$aPics = _FileListToArrayEx($sPicFolder, $aExtPics)
IniWrite("Settings.ini", "Paths", "PicPath", $sPicFolder)
Return 1
EndIf
Return 0
EndFunc ;==>_PicPath
Func _PathInValid()
Switch MsgBox(52, "Fehler", "Im angegebenen Pfad wurden keine kompatiblen Bilddateien gefunden oder der Pfad ist ungültig. Möchten sie den Pfad jetzt neu bestimmen?")
Case 6
If Not _PicPath() Then _PathInValid()
Case 7
MsgBox(64, "Info", "Da keine Bilder gefunden wurden sind einige Funktionen des Programms deaktiviert, wenn sie einen neuen Pfad zu ihren Bildern auswählen möchten klicken sie auf 'Bilderpfad auswählen'.")
TrayItemSetState($cRandomWallpaper, 128)
EndSwitch
EndFunc ;==>_PathInValid
Func _FileListToArrayEx($sPath, $aExt)
If Not IsArray($aExt) Then Return SetError(1, 0, 0)
Local $aFilesRaw = _FileListToArray($sPath, '*', 1)
Local $aFilesReturn[1]
For $i = 1 To $aFilesRaw[0]
$sExtTmp = StringRight($aFilesRaw[$i], StringLen($aFilesRaw[$i]) - StringInStr($aFilesRaw[$i], ".", 0, -1))
$bValid = False
For $j = 1 To $aExt[0]
If $sExtTmp = $aExt[$j] Then $bValid = True
Next
If $bValid = True Then _ArrayAdd($aFilesReturn, $aFilesRaw[$i])
Next
If UBound($aFilesReturn) <= 1 Then Return SetError(2, 0, 0)
$aFilesReturn[0] = UBound($aFilesReturn) - 1
Return $aFilesReturn
EndFunc ;==>_FileListToArrayEx
Func _Undo()
TrayItemSetState($cUndo, 4)
If FileExists($sBackUpFilePath) Then
FileCopy($sTempFilePath, $sTempFilePath & '.copybuffer', 1)
FileCopy($sBackUpFilePath, $sTempFilePath, 1)
FileCopy($sTempFilePath & '.copybuffer', $sBackUpFilePath, 1)
FileDelete($sTempFilePath & '.copybuffer')
_SetWallPaper($sTempFilePath)
EndIf
EndFunc ;==>_Undo
Func _SetWallPaper($sImagePath)
RegWrite("HKEY_CURRENT_USER\Control Panel\Desktop", "TileWallPaper", "REG_SZ", 0)
RegWrite("HKEY_CURRENT_USER\Control Panel\Desktop", "WallpaperStyle", "REG_SZ", -1)
RegWrite("HKEY_CURRENT_USER\Control Panel\Desktop", "Wallpaper", "REG_SZ", $sImagePath)
DllCall("user32.dll", "int", "SystemParametersInfo", "int", 20, "int", 0, "str", $sImagePath, "int", BitOR(1, 2))
EndFunc ;==>_SetWallPaper
Func _Exit()
Exit
EndFunc ;==>_Exit
Edit: Großes Update !
Änderungen:
- TrayMenu hinzugefügt
- Einstellungen hinzugefügt
- Bessere Überprüfung des Bilderpfads
- Undo Funktion
- Kleinere Bugs behoben