Guten Morgen allerseits.
Ich habe mir vor einiger Zeit ein Skript zusammen gebastelt, dass die aktuelle Uhrzeit und das Datum
zusammen mit einem benutzerdefinierten Bild als Wallpaper verwendet.
Zusammengebastelt deshalb, weil der GDIPlus Teil mehr hingeklotzt ist, als sonst was, da mir GDIPlus seit je her ein Rätsel ist,
dass mir einfach nicht in die Birne gehn will, egal wie lange ich mich damit auseinander setz.
Nun, das Skript funktioniert soweit super und tut genau das was es soll, sieht halt an manschen Stellen nur aus wie Hund...
Da ich das Skript im Umfang noch erweitern will und es mit einigen anderen Skripten zusammen schließen will,
würde ich den GDIPlus Teil gerne etwas verbessern.
Hier aber erstmal der Code:
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <ScreenCapture.au3>
#include <GDIPlus.au3>
HotKeySet("^!o", "_openOptions")
HotKeySet("^!l", "_load")
Global $sOptionsFile = @AppDataDir & "\Clock_Wallpaper_Options.ini"
Global $sCaptureFilePath = @TempDir & "\TempClockFile.bmp"
Global $sTimeCheck
_load()
If NOT FileExists($sOptionsFile) Then
MsgBox(16, "ERROR - Clock Wallpaper v2", "Options file not found!" & @CRLF & $sOptionsFile)
EndIf
_Update()
AdlibRegister("_Update", 1000)
While 1
Sleep(100)
WEnd
Func _openOptions()
Run("notepad.exe " & $sOptionsFile)
EndFunc
Func _load()
Global $sBGFilePath = IniRead($sOptionsFile, "options", "image", 0)
Global $sFont = IniRead($sOptionsFile, "options", "font", 0)
Global $sSizeTime = IniRead($sOptionsFile, "options", "size_time", 0)
Global $sSizeDate = IniRead($sOptionsFile, "options", "size_date", 0)
Global $sPosTime = IniRead($sOptionsFile, "options", "pos_time", 0)
Global $sPosDate = IniRead($sOptionsFile, "options", "pos_date", 0)
If @HotKeyPressed = "^!l" Then
_SetWalpaper()
EndIf
EndFunc
Func _Update()
Local $Checksum = @HOUR & @MIN
If $sTimeCheck < $Checksum Then
$sTimeCheck = $Checksum
_SetWalpaper()
ElseIf $sTimeCheck = 2359 And $Checksum = 0000 Then
$sTimeCheck = $Checksum
_SetWalpaper()
EndIf
EndFunc ;==>_Update
Func _SetWalpaper()
_GDIPlus_StartUp ()
$aHour = StringSplit(@HOUR, "")
$aMin = StringSplit(@MIN, "")
$aDay = StringSplit("SO.|MO.|DI.|MI.|DO.|FR.|SA.", "|")
$sTime = $aHour[1] & " " & $aHour[2] & " : " & $aMin[1] & " " & $aMin[2]
$sDate = $aDay[@WDAY] & " " & @MDAY & "." & @MON & "." & @YEAR
$hImage = _GDIPlus_ImageLoadFromFile ($sBGFilePath)
$hGraphic = _GDIPlus_ImageGetGraphicsContext ($hImage)
$hFamily = _GDIPlus_FontFamilyCreate ($sFont)
; Set Time
$hFont1 = _GDIPlus_FontCreate ($hFamily, $sSizeTime, 0)
$hFormat1 = _GDIPlus_StringFormatCreate (0x4000)
_GDIPlus_StringFormatSetAlign ($hFormat1, 1)
$hBrush1 = _GDIPlus_BrushCreateSolid (0xff000000)
$hPen1 = _GDIPlus_PenCreate (0xC4000000, 1)
$tLayout1 = _GDIPlus_RectFCreate (200, $sPosTime)
$aInfo1 = _GDIPlus_GraphicsMeasureString ($hGraphic, $sTime, $hFont1, $tLayout1, $hFormat1)
_GDIPlus_GraphicsDrawStringEx ($hGraphic, $sTime, $hFont1, $aInfo1[0], $hFormat1, $hBrush1)
; Set Date
$hFont2 = _GDIPlus_FontCreate ($hFamily, $sSizeDate, 0)
$hFormat2 = _GDIPlus_StringFormatCreate (0x4000)
_GDIPlus_StringFormatSetAlign ($hFormat2, 1)
$hBrush2 = _GDIPlus_BrushCreateSolid (0xff000000)
$hPen2 = _GDIPlus_PenCreate (0xC4000000, 1)
$tLayout2 = _GDIPlus_RectFCreate (200, $sPosDate)
$aInfo2 = _GDIPlus_GraphicsMeasureString ($hGraphic, $sDate, $hFont2, $tLayout2, $hFormat2)
_GDIPlus_GraphicsDrawStringEx ($hGraphic, $sDate, $hFont2, $aInfo2[0], $hFormat2, $hBrush2)
_GDIPlus_ImageSaveToFile ($hImage, $sCaptureFilePath)
_GDIPlus_PenDispose ($hPen1)
_GDIPlus_PenDispose ($hPen2)
_GDIPlus_BrushDispose ($hBrush1)
_GDIPlus_BrushDispose ($hBrush2)
_GDIPlus_StringFormatDispose ($hFormat1)
_GDIPlus_StringFormatDispose ($hFormat2)
_GDIPlus_FontDispose ($hFont1)
_GDIPlus_FontDispose ($hFont2)
_GDIPlus_FontFamilyDispose ($hFamily)
_GDIPlus_GraphicsDispose ($hGraphic)
_GDIPlus_ImageDispose ($hImage)
_GDIPlus_ShutDown ()
_ChangeDesktopWallpaper($sCaptureFilePath, 0)
FileDelete($sCaptureFilePath)
EndFunc ;==>_SetWalpaper
Func _ChangeDesktopWallpaper($bmp, $style = 0)
If Not FileExists($bmp) Then Return -1
;The $SPI* values could be defined elsewhere via #include - if you conflict,
; remove these, or add if Not IsDeclared "SPI_SETDESKWALLPAPER" Logic
Local $SPI_SETDESKWALLPAPER = 20
Local $SPIF_UPDATEINIFILE = 1
Local $SPIF_SENDCHANGE = 2
Local $REG_DESKTOP = "HKEY_CURRENT_USER\Control Panel\Desktop"
If $style = 1 Then
RegWrite($REG_DESKTOP, "TileWallPaper", "REG_SZ", 1)
RegWrite($REG_DESKTOP, "WallpaperStyle", "REG_SZ", 0)
Else
RegWrite($REG_DESKTOP, "TileWallPaper", "REG_SZ", 0)
RegWrite($REG_DESKTOP, "WallpaperStyle", "REG_SZ", $style)
EndIf
DllCall("user32.dll", "int", "SystemParametersInfo", _
"int", $SPI_SETDESKWALLPAPER, _
"int", 0, _
"str", $bmp, _
"int", BitOR($SPIF_UPDATEINIFILE, $SPIF_SENDCHANGE))
Return 0
EndFunc ;==>_ChangeDestopWallpaper
Alles anzeigen
Es geht mir hier um die Funktion _SetWallpaper.
Aktuell wird ja erst die Zeit, dann das Datum auf das Bild gesetzt.
Und genau das hätte ich gerne in einer gesonderten Funktion.
Der Code für Zeit und Datum sind ja sehr gleich und wenn jetzt noch ein dritter oder vierter
Text dazu kommen soll, müsste ich, so wie es aktuell ist diesen Code noch weitere male verwenden.
Genau dafür ist ja ne Funktion da, um eben unnötige Wiederholungen im Code zu vermeiden.
Leider schaffe ich es aber nicht, das ganze in eine Funktion zu pressen.
Deshalb wäre ich Euch sehr dankbar, wenn Ihr mir da etwas bei helfen könntet.
Anstatt den Code für jeden Text zu wiederholen, möchte ich einfach eine Funktion aufrufen in dem ich alle Parameter wie Text, Font, Größe, Position u.s.w. übergebe.
Hoffe Ihr könnt mir da etwas helfen.
Liebe Grüße
Micha