Ok, trotzdem werd ich mir das Format mal näher ansehn. Kann nich schaden
Beiträge von Michi91
-
-
Wow, ich dachte mir schon, dass es einfacher geht, aber das is wirklich nice 👍
Vielen dank, das hat mir auf jeden Fall schon sehr weiter geholfen.
Spucken solche APIs immer Strings im JSON Format aus?
Werd mir jetzt erstmal die Struktur von JSON ansehn. -
Hey, hätte mal ne Frage.
Ich arbeite aktuell an einem privaten Projekt, zu dem Ihr mir hier im Forum auch schon super geholfen habt.
Für dieses Projekt arbeite ich nun das erste mal mit APIs. (War vorher halt nie nötig ^^)
Genauer mit der Wetter API von openweathermap.org.
Wenn ich die API nutze kommt z.B. solch ein String dabei rausSpoiler anzeigen
Code{"coord":{"lon":139,"lat":35},"weather":[{"id":804,"main":"Clouds","description":"Bedeckt","icon":"04d"}],"base":"stations","main":{"temp":27.4,"feels_like":31.13,"temp_min":26.65,"temp_max":27.4,"pressure":1010,"humidity":84},"visibility":10000,"wind":{"speed":0.54,"deg":131,"gust":1.2},"clouds":{"all":92},"dt":1659846407,"sys":{"type":2,"id":2019346,"country":"JP","sunrise":1659815850,"sunset":1659865332},"timezone":32400,"id":1851632,"name":"Shuzenji","cod":200}
Nun hatte ich erst etwas Schwierigkeiten diese ganzen Informationen auseinander zu dröseln.
Gelöst habe ich das nun so:Spoiler anzeigen
Code
Alles anzeigenFunc _GetWeather() Local $sLat = "XXXXX" Local $sLon = "XXXXX" Local $sKey = "XXXXX" Local $sURL = "https://api.openweathermap.org/data/2.5/weather?lat=" & $sLat & "&lon=" & $sLon & "&appid=" & $sKey & "&lang=de&units=metric" Local $aData[5] $sSource = _INetGetSource($sURL, True) $aSplitMain = StringSplit($sSource, ",") $aSplit1 = StringSplit($aSplitMain[5], ":") ;==> description $aData[0] = StringReplace($aSplit1[2], '"', '') $aSplit2 = StringSplit($aSplitMain[8], ":") ;==> temp $aSplitTemp = StringSplit($aSplit2[3], ".") $aData[1] = $aSplitTemp[1] & " °C" $aSplit3 = StringSplit($aSplitMain[13], ":") ;==> humidity $aData[2] = StringReplace($aSplit3[2], "}", '') & " %" $aSplit4 = StringSplit($aSplitMain[17], ":") ;==> wind speed $aData[3] = $aSplit4[3] & " m/s" $aSplit5 = StringSplit($aSplitMain[29], ":") ;==> city $aData[4] = StringReplace($aSplit5[2], '"', '') Return $aData EndFunc
Da ich für mein Projekt nur 5 Daten brauche fische ich auch nur diese raus, da is also längst nicht alles drin was die API hergibt.
Was mich aber interessiert is, wie Ihr diesen String in brauchbare Informationen aufspaltet.
Meine Methode funktioniert zwar prima, scheint mir aber recht umständlich.
Mir gehts einfach darum, zu lernen wie ich das künftig besser machen kann.
Liebe Grüße
Micha -
Hi, ich hatte mir deinen Code gestern angesehen und fand es unglücklich, dass du jede Minute ein neues Bild erstellst, es als Datei speicherst und dann als Hintergrund setzt.
Das ist eine echt gute Methode, wie du sehr schnell deine Festplatte kaputt schreibst. Bei mir ist das Hintergrundbild (2x4K und 2xFHD Bildschirm) ca. 11MB groß...
Das wären ~15.840MB => ~16GB in 24 Stunden, die dort geschrieben werden...
Deshalb hab ich mir gestern ein paar Stunden angeschaut, wie genau die Fenster vom Desktop funktionieren und hab eine UDF geschrieben, mit der man auf den Desktop zeichnen kann.
Ich hab dein Script mal mit der UDF umgesetzt. Das würde dann so ausschauen:
AutoIt
Alles anzeigen;Author: Kanashius@autoitscript.com, Kanashius@autoit.de, https://www.kanashius.com #include "WallpaperUDF.au3" #include <StaticConstants.au3> HotKeySet("^!o", "_openOptions") HotKeySet("^!l", "_load") Global $hFamily, $hFontTime, $hFontDate, $hFormat, $hBrush, $hPen, $iPosDate = 25, $iPosTime = 60, $arDays = StringSplit("SO.|MO.|DI.|MI.|DO.|FR.|SA.", "|") Global $sOptionsFile = @AppDataDir & "\Clock_Wallpaper_Options.ini" ; initialize own tray __Wallpaper_InitDefaultTray() ; start the wallpaper drawing loop __Wallpaper_Start(_draw, _init, _shutdown) If @error Then MsgBox(16, "Error", "Something went wrong starting initializing the wallpaper: "&@error) Func _draw(ByRef $hGraphics, $iWidth, $iHeight, ByRef $arScreenInfo) ; will be called for each drawing cicle. ; Draw Date Local $sDate = StringFormat("%s %02i.%02i.%04i", $arDays[@WDAY], @MDAY, @MON, @YEAR) Local $tLayoutDate = _GDIPlus_RectFCreate($arScreenInfo[0][0] + 200, $arScreenInfo[0][1] + $iPosDate) ; Draw at the primary screen Local $aInfoDate = _GDIPlus_GraphicsMeasureString($hGraphics, $sDate, $hFontDate, $tLayoutDate, $hFormat) _GDIPlus_GraphicsDrawStringEx($hGraphics, $sDate, $hFontDate, $aInfoDate[0], $hFormat, $hBrush) ; Draw Time Local $sTime = StringFormat("%02i:%02i:%02i", @HOUR, @MIN, @SEC) $tLayoutTime = _GDIPlus_RectFCreate($arScreenInfo[0][0] + 200, $arScreenInfo[0][1] + $iPosTime) ; Draw at the primary screen $aInfoTime = _GDIPlus_GraphicsMeasureString($hGraphics, $sTime, $hFontTime, $tLayoutTime, $hFormat) _GDIPlus_GraphicsDrawStringEx($hGraphics, $sTime, $hFontTime, $aInfoTime[0], $hFormat, $hBrush) ; Return redraw areas Local $arAreas[0][4] _addRect($arAreas, $aInfoDate) _addRect($arAreas, $aInfoTime) return SetExtended(100, $arAreas) ; Change extended to the (min) time in ms to wait between each redraw. (This does not influence _process) EndFunc Func _addRect(ByRef $arAreas, $aTag) ReDim $arAreas[UBound($arAreas)+1][4] For $i = 1 To 4 Step 1 $arAreas[UBound($arAreas)-1][$i-1] = DllStructGetData($aTag[0], $i) Next EndFunc Func _init($iWidth, $iHeight, ByRef $arScreenInfo) ; The initialization method is called once before the draw loop starts. If UBound($arScreenInfo) = 0 Then MsgBox(16, "Error", "It is difficult to draw a wallpaper without a screen.") Exit EndIf _load() $hFormat = _GDIPlus_StringFormatCreate(0x4000) _GDIPlus_StringFormatSetAlign($hFormat, 1) $hBrush = _GDIPlus_BrushCreateSolid(0xff000000) $hPen = _GDIPlus_PenCreate(0xC4000000, 1) EndFunc Func _shutdown() ; The shutdown method is called at the end of the draw loop, after __Wallpaper_Exit was called. _cleanUp() _GDIPlus_BrushDispose($hBrush) _GDIPlus_StringFormatDispose($hFormat) _GDIPlus_PenDispose($hPen) EndFunc Func _load() Local $bIsPaused = __Wallpaper_IsPause() ; pause drawing, while changing the fonts if Not $bIsPaused Then __Wallpaper_PauseResume() ; Local $sBGFilePath = IniRead($sOptionsFile, "options", "image", 0) $iPosDate = Int(IniRead($sOptionsFile, "options", "pos_date", $iPosDate)) $iPosTime = Int(IniRead($sOptionsFile, "options", "pos_time", $iPosTime)) _cleanUp() $hFamily = _GDIPlus_FontFamilyCreate(IniRead($sOptionsFile, "options", "font", "Arial")) $hFontDate = _GDIPlus_FontCreate($hFamily, IniRead($sOptionsFile, "options", "size_date", 25), 0) $hFontTime = _GDIPlus_FontCreate($hFamily, IniRead($sOptionsFile, "options", "size_time", 25), 0) if Not $bIsPaused Then __Wallpaper_PauseResume() EndFunc Func _cleanUp() _GDIPlus_FontDispose($hFontTime) _GDIPlus_FontDispose($hFontDate) _GDIPlus_FontFamilyDispose($hFamily) EndFunc Func _openOptions() Run("notepad.exe " & $sOptionsFile) EndFunc
Ich hab noch die Sekunden hinzugefügt, weil warum nicht
Edit: Link zur UDF: Wallpaper UDF
Edit2: _getMaxRect() removed
In Zeile 73 (mein letzter Post) wird doch das Bild nachdem es als Wallpaper gesetzt wurde gelöscht.
Der Speicherverbrauch sollte eigl. minimal sein und in der Zeit von TB Festplatten nicht mehr ins Gewicht fallen. -
So.
Hab versucht den Code zu implementieren und kleinere Fehler zu beheben.
Das Problem ist aber, jetzt wird nur der Text im fertigen Wallpaper angezeigt, der als letztes über die Funktion eingefügt wurde.
Hier der Code:Spoiler anzeigen
C
Alles anzeigen#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 GDIPlus_Add_TextToImage($sTime, $sPosTime, $sSizeTime) GDIPlus_Add_TextToImage($sDate, $sPosDate, $sSizeDate) _ChangeDesktopWallpaper($sCaptureFilePath, 0) FileDelete($sCaptureFilePath) EndFunc ;==>_SetWalpaper Func GDIPlus_Add_TextToImage(Const $sText, $sPos, $sSize) ;$sSize kann weg, wenn es "berechnet" wird Local $hImage = _GDIPlus_ImageLoadFromFile ($sBGFilePath) Local $hGraphic = _GDIPlus_ImageGetGraphicsContext ($hImage) Local Const $hFamily = _GDIPlus_FontFamilyCreate($sFont) ;~ Local Const $sSize = ;Du musst Size errechnen oder sie der Funktion übergeben, Siehe dazu: https://www.autoitscript.com/forum/topic/182271-solved_gdiplus-how-calculate-font-size-to-fill-a-_gdiplus_rectfcreate/ Local Const $hFont = _GDIPlus_FontCreate($hFamily, $sSize, 0) Local Const $hFormat = _GDIPlus_StringFormatCreate(0x4000) _GDIPlus_StringFormatSetAlign($hFormat, 1) Local Const $hBrush = _GDIPlus_BrushCreateSolid(0xff000000) Local Const $hPen = _GDIPlus_PenCreate(0xC4000000, 1) Local Const $tLayout = _GDIPlus_RectFCreate(200, $sPos) Local Const $aInfo = _GDIPlus_GraphicsMeasureString($hGraphic, $sText, $hFont, $tLayout, $hFormat) _GDIPlus_GraphicsDrawStringEx($hGraphic, $sText, $hFont, $aInfo[0], $hFormat, $hBrush) _GDIPlus_ImageSaveToFile ($hImage, $sCaptureFilePath) _GDIPlus_PenDispose($hPen) _GDIPlus_BrushDispose($hBrush) _GDIPlus_StringFormatDispose($hFormat) _GDIPlus_FontDispose($hFont) _GDIPlus_FontFamilyDispose($hFamily) _GDIPlus_GraphicsDispose($hGraphic) EndFunc 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
Weiß leider nich genau was da schief läuft.
EDIT:
Hab nochmal etwas dran gebastelt, jetzt funktioniert es wie gewünschtSpoiler anzeigen
C
Alles anzeigen#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 () $hImage = _GDIPlus_ImageLoadFromFile ($sBGFilePath) $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 GDIPlus_Add_TextToImage($hImage, $sTime, $sPosTime, $sSizeTime) GDIPlus_Add_TextToImage($hImage, $sDate, $sPosDate, $sSizeDate) _GDIPlus_ImageSaveToFile ($hImage, $sCaptureFilePath) _ChangeDesktopWallpaper($sCaptureFilePath, 0) FileDelete($sCaptureFilePath) EndFunc ;==>_SetWalpaper Func GDIPlus_Add_TextToImage($hImage, $sText, $sPos, $sSize) ;$sSize kann weg, wenn es "berechnet" wird Local $hGraphic = _GDIPlus_ImageGetGraphicsContext ($hImage) Local $hFamily = _GDIPlus_FontFamilyCreate($sFont) ;~ Local Const $sSize = ;Du musst Size errechnen oder sie der Funktion übergeben, Siehe dazu: https://www.autoitscript.com/forum/topic/182271-solved_gdiplus-how-calculate-font-size-to-fill-a-_gdiplus_rectfcreate/ Local Const $hFont = _GDIPlus_FontCreate($hFamily, $sSize, 0) Local Const $hFormat = _GDIPlus_StringFormatCreate(0x4000) _GDIPlus_StringFormatSetAlign($hFormat, 1) Local Const $hBrush = _GDIPlus_BrushCreateSolid(0xff000000) Local Const $hPen = _GDIPlus_PenCreate(0xC4000000, 1) Local Const $tLayout = _GDIPlus_RectFCreate(200, $sPos) Local Const $aInfo = _GDIPlus_GraphicsMeasureString($hGraphic, $sText, $hFont, $tLayout, $hFormat) _GDIPlus_GraphicsDrawStringEx($hGraphic, $sText, $hFont, $aInfo[0], $hFormat, $hBrush) ;~ _GDIPlus_ImageSaveToFile ($hImage, $sCaptureFilePath) _GDIPlus_PenDispose($hPen) _GDIPlus_BrushDispose($hBrush) _GDIPlus_StringFormatDispose($hFormat) _GDIPlus_FontDispose($hFont) _GDIPlus_FontFamilyDispose($hFamily) _GDIPlus_GraphicsDispose($hGraphic) EndFunc 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
-
Puhh, ok, ich muss zugeben dass ich weniger als die Hälfte von dem verstehe über das Ihr da diskutiert.
Aber sei es drum, ich werde jetzt erstmal versuchen den Code von Moombas zu implementieren und gebe Euch dann nochmal Rückmeldung.
Vielen Dank auf jeden Fall schonmal für die Hilfe -
Guten Morgen allerseits.
Ich habe mir vor einiger Zeit ein Skript zusammen gebastelt, dass die aktuelle Uhrzeit und das Datumzusammen 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:Spoiler anzeigen
C
Alles anzeigen#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
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 -
Hey, das werd ich mir auf jeden Fall mal anschauen.
Hab aber zwischenzeitlich noch weiter gesucht und eine Lösung gefunden, die ohne GUI auskommt.Auf die Lösung gebracht hat mich der User walkillon aus dem englischen Forum (https://www.autoitscript.com/forum/profile/28198-wakillon/).
Das ist der entsprechende Beitrag (https://www.autoitscript.com/forum/topic/13…image-and-save/)
Mein Script sieht jetz so aus
Spoiler anzeigen
C
Alles anzeigen#include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <ScreenCapture.au3> Global $sBGFilePath = @ProgramsDir & "\Clock_Wallpaper\Clock_BG.bmp" Global $sCaptureFilePath = @TempDir & "\TempClockFile.bmp" Global $sTimeCheck _Update() AdlibRegister("_Update", 1000) While 1 ;~ $nMsg = GUIGetMsg() ;~ Switch $nMsg ;~ Case $GUI_EVENT_CLOSE ;~ Exit ;~ EndSwitch WEnd 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 ("Digital-7") ; Set Time $hFont1 = _GDIPlus_FontCreate ($hFamily, 100, 0) $hFormat1 = _GDIPlus_StringFormatCreate (0x4000) _GDIPlus_StringFormatSetAlign ($hFormat1, 1) $hBrush1 = _GDIPlus_BrushCreateSolid (0xff000000) $hPen1 = _GDIPlus_PenCreate (0xC4000000, 1) $tLayout1 = _GDIPlus_RectFCreate (200, 10) $aInfo1 = _GDIPlus_GraphicsMeasureString ($hGraphic, $sTime, $hFont1, $tLayout1, $hFormat1) _GDIPlus_GraphicsDrawStringEx ($hGraphic, $sTime, $hFont1, $aInfo1[0], $hFormat1, $hBrush1) ; Set Date $hFont2 = _GDIPlus_FontCreate ($hFamily, 60, 0) $hFormat2 = _GDIPlus_StringFormatCreate (0x4000) _GDIPlus_StringFormatSetAlign ($hFormat2, 1) $hBrush2 = _GDIPlus_BrushCreateSolid (0xff000000) $hPen2 = _GDIPlus_PenCreate (0xC4000000, 1) $tLayout2 = _GDIPlus_RectFCreate (200, 120) $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 () _ChangeDestopWallpaper($sCaptureFilePath, 0) FileDelete($sCaptureFilePath) EndFunc ;==>_SetWalpaper ;=============================================================================== ; ; Function Name: _ChangeDesktopWallPaper ; Description: Update WallPaper Settings ;Usage: _ChangeDesktopWallPaper(@WindowsDir & '\' & 'zapotec.bmp',1) ; Parameter(s): $bmp - Full Path to BitMap File (*.bmp) ; [$style] - 0 = Centered, 1 = Tiled, 2 = Stretched ; Requirement(s): None. ; Return Value(s): On Success - Returns 0 ; On Failure - -1 ; Author(s): FlyingBoz ;Thanks: Larry - DllCall Example - Tested and Working under XPHome and W2K Pro ; Excalibur - Reawakening my interest in Getting This done. ; ;=============================================================================== Func _ChangeDestopWallpaper($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
Immer noch nicht sehr elegant das ganze, aber für mich selbst reicht das
-
Guten Morgen.
Ich arbeite leider viel zu selten mit Autoit, da ich nur Scripts schreibe, wenn ich welche brauche, deshalb brauche ich bei meinem aktuellen Script einmal Eure Hilfe.
Mein Gedanke war, ich hätte gerne eine Uhr samt Datum gut sichtbar in der Mitte meines Bildschirms.
(Klar, dafür gibts sicher genug Programme, aber ich wollte es eben selbst schreiben)
Hab mir also einen Hintergrund designt, das Script Uhrzeit und Datum als Label drüber legen, das ganze als Screenshot zwischenspeichern und das Bild als Wallpaper nutzen lassen.Klappt auch wunderbar, um das das Fenster von dem der Screenshot gemacht wird nicht immer im Blick zu haben, wollte ich es i.wo außerhalb des Bildschirms platzieren.
Und hier war mein Denkfehler... Außerhalb gibts ja leider nix, wovon man ein Screenshot machen könnte...
Denke mir mal, dass es da bessere Lösungen für mein Anliegen gibt, ich würd aber wenn möglich gerne erstmal bei diesem Ansatz bleiben.
Was ich brauche ist also eine Möglichkeit den Inhalt des Fensterns, bzw. der GUI i.wie als Bild zu speichern.Hier ist das Script das ich bis dahin habe:
Spoiler anzeigen
C
Alles anzeigen#include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <ScreenCapture.au3> Global $sBGFilePath = @ProgramsDir & "\Clock_Wallpaper\Clock_BG.bmp" Global $sCaptureFilePath = @TempDir & "\TempClockFile.bmp" Global $sTimeCheck $hGUI = GUICreate("", 400, 200, -1000, -1, $WS_POPUP, 0x08000000) $idBG = GUICtrlCreatePic($sBGFilePath, 0, 0, 400, 200) $idTime = GUICtrlCreateLabel("", 10, 10, 380, 100, $SS_CENTER) GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT) GUICtrlSetFont(-1, 80, 500, 0, "Digital-7") $idDate = GUICtrlCreateLabel("", 10, 120, 380, 60, $SS_CENTER) GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT) GUICtrlSetFont(-1, 45, 200, 0, "Digital-7") GUISetState(@SW_SHOW) _Update() AdlibRegister("_Update", 1000) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd 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 Func _SetWalpaper() $aHour = StringSplit(@HOUR, "") $aMin = StringSplit(@MIN, "") $aDay = StringSplit("SO.|MO.|DI.|MI.|DO.|FR.|SA.", "|") $sTime = $aHour[1] & " " & $aHour[2] & " : " & $aMin[1] & " " & $aMin[2] & "#" & $aDay[@WDAY] & " " & @MDAY & "." & @MON & "." & @YEAR GUICtrlSetData($idTime, $aHour[1] & " " & $aHour[2] & " : " & $aMin[1] & " " & $aMin[2]) GUICtrlSetData($idDate, $aDay[@WDAY] & " " & @MDAY & "." & @MON & "." & @YEAR) _ScreenCapture_CaptureWnd($sCaptureFilePath, $hGUI) _ChangeDestopWallpaper($sCaptureFilePath, 0) FileDelete($sCaptureFilePath) EndFunc ;=============================================================================== ; ; Function Name: _ChangeDesktopWallPaper ; Description: Update WallPaper Settings ;Usage: _ChangeDesktopWallPaper(@WindowsDir & '\' & 'zapotec.bmp',1) ; Parameter(s): $bmp - Full Path to BitMap File (*.bmp) ; [$style] - 0 = Centered, 1 = Tiled, 2 = Stretched ; Requirement(s): None. ; Return Value(s): On Success - Returns 0 ; On Failure - -1 ; Author(s): FlyingBoz ;Thanks: Larry - DllCall Example - Tested and Working under XPHome and W2K Pro ; Excalibur - Reawakening my interest in Getting This done. ; ;=============================================================================== Func _ChangeDestopWallpaper($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
Ist es alternativ vllt. mit GDI+ möglich Schrift über ein bestehendes BMP zu legen und das ganze wieder als BMP zu speichern?
Dann könnte ich den Blödsinn mit dem Screenshot ganz umgehn -
Sry aber da kommt immer noch zu viel raus
Genau wie bei WinList werden auch hier minimierte, unsichtbare und sonstige Fenster angezeigt, von denen kein Schwein ne Ahnung hat wo sie her kommen.
Liegt das evtl. an Windoof 10?
Vllt. mal den Bildschirm aufn Kopf stellen und schütteln, vllt. falln da nochn paar Fenster raus. -.-
Funktionierts denn bei Euch korrekt?
-
Hab auch den Code aus der Hilfe schon 1:1 kopiert. Genau wie bei deinem Beispiel kommt bei 1 geöffneten, bzw. sichtbaren Fenster 13 raus.
Das is ja das was ich von der Logik her nich versteh....
Scheinbar werden die Minimierten Fenster mit gezählt.
Gezählt werden sollten eben nur jene, die eben offen sind,
die ich mit meinen Augen sehn kann, bzw. auch solche die sind hinter andern Fenstern verstecken.
-
Ich danke Euch allen Hat super funktioniert.
-
Hey, kleines Problem.
Ich brauch nen Codeschnipsel der mir sagt, wie viele offene Fenster gerade zu sehen sind.
Wenn ich also den Rechner und Chrome offen hab, und alle anderen Fenster Minimiert sind, sollte da 2 raus kommen...
Ich verwende:
AutoIt
Alles anzeigen$List = WinList $Count = 0 Local $List = WinList() For $i = 1 To $List[0][0] $getState = WinGetState ($List[$i][1]) If BitAND ($getState, 2) Then $Count = $Count+1 EndIf Next MsgBox (0, "", $Count)
Damit kommen teils Zahlen raus, die ich nich verstehe. Wenn ich nur 2 Fenster sehe, meint das Script es wäre 18 offen u.s.w.
Jemand ne Idee?
-
Gut zu wissen
War noch auf dem Stand dass da ne GUI dabei sein muss, also danke schon mal dafür
Jedoch löst das leider das eigentliche Problem nicht.
Auch wenn ich nur schwebende Buttons hab, müssen die trotzdem permanent im Hintergrund bleiben.
-
Hey. Ich arbeite grad an nem kleinen Projekt für mich persönlich um meinen Desktop etwas zu verschönern.
Dazu hab ich erstmal einige GUIs (werden noch ein paar mehr) die im Endeffekt unsichtbar werden, und auf denen dann Buttons liegen.
Nun soll das ganze aber schön im Hintergrund bleiben, so dass man die Oberfläche eben nur sieht wenn man auf dem Desktop ist.
Hoffe ihr versteht was ich mein, is schon spät ...
Hier das was ich bisher hab:
C
Alles anzeigen#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <Constants.au3> #Include <WinAPI.au3> ;=====> GUI $hGui0 = GUICreate ("A R T I F A C T", 0, 0, 0, 0) $hGui1 = GUICreate ("Button Big 1 L", 296, 296, 204, 202, $WS_POPUP, -1, $hGui0) GUISetState(@SW_SHOW) $hGui2 = GUICreate ("Button Big 2 L", 296, 296, 204, 532, $WS_POPUP, -1, $hGui0) GUISetState(@SW_SHOW) $hGui3 = GUICreate ("Button Big 3 L", 296, 296, 533, 202, $WS_POPUP, -1, $hGui0) GUISetState(@SW_SHOW) $hGui4 = GUICreate ("Trash", 100, 100, 911, 230, $WS_POPUP, -1, $hGui0) GUISetState(@SW_SHOW) $hGui5 = GUICreate ("Button Big 1 R", 296, 296, 1092, 202, $WS_POPUP, -1, $hGui0) GUISetState(@SW_SHOW) $hGui6 = GUICreate ("Button Big 2 R", 296, 296, 1421, 202, $WS_POPUP, -1, $hGui0) GUISetState(@SW_SHOW) $hGui7 = GUICreate ("Button Big 3 R", 296, 296, 1421, 532, $WS_POPUP, -1, $hGui0) GUISetState(@SW_SHOW) $hGui8 = GUICreate ("CRC L", 146, 66, 279, 936, $WS_POPUP, -1, $hGui0) GUISetState(@SW_SHOW) $hGui9 = GUICreate ("CRC L", 146, 66, 1496, 936, $WS_POPUP, -1, $hGui0) GUISetState(@SW_SHOW) $hGui10 = GUICreate ("CRC L", 250, 250, @DesktopWidth/2-125, 775, $WS_POPUP, -1, $hGui0) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd
Ohne eine Funktion die das ganze permanent im Hintergrund hält, brauch ich gar nich erst weiter machen
Leider haben mir die paar Infos die mir Google ausgespuckt hat nich wirklich weiter geholfen, oder ich versteh sie nich... kann auch sein.
Hoffe mir kann da einer helfen
-
-
Guten Morgen,
ich hab folgendes Problem und konnte dazu bei google bisher zu wenig finden.
Ich schau mir gerne mal Filme die am PC laufen am Fernseher an, dazu hab ich mir
einen kleinen Switcher zugelegt. Ich brauch also nur auf den Knopf drücken, dann wird das Signal von der
Graka auf den TV umgeleitet.Soweit ne tolle Sache, jedoch spielen da die Audioeinstellungen manchmal nicht so ganz mit.
Soll heißen, das Standartgerät wird nicht immer auf das entsprechnd gerade angesteuerte Gerät,
also den Fernseher oder das Headset (PC) gesetzt.Jetzt wollte ich mal ein kleinen Script machen, dass erkennt ob gerade der Monitor oder der Fernseher angeschlossen ist
und das Standartgerät entsprechend automatisch setzt, sofern dies nicht von selbst geschieht, so als Backup eben.Dazu fehlen mir folgende Funktionen für AutoIt...
- Erkennen welcher Monitor gerade angeschlossen ist (über den Switch)
- Erkennen welches Gerät als Standartgerät gesetzt ist
- Standartgerät setzenWäre super, wenn mir da jemand weiter helfen könnte.
Derweil durchforste ich mal weiter Onkel Google -
Hi, nur ne kurze Frage:
Ich will, dass der MouseMove mit einer konstanten Geschwindigkeit den Cursor bewegt.Das Prog. ist ganz klein.
Ich brauch es lediglich, um bei Paint.NET ein recht großes Bild
langsam nach unten zu scrollen, da das mit nem prog. besser geht als mit der Hand. (Für ein Video).Achso, hier das script:
[autoit]
[/autoit][autoit][/autoit][autoit]
HotKeySet ("{Numpad1}", "_Go")
HotKeySet ("{Numpad2}", "_Exit")While 1
[/autoit][autoit][/autoit][autoit]WEnd
[/autoit][autoit][/autoit][autoit]Func _Exit ()
[/autoit][autoit][/autoit][autoit]
Exit
EndFuncFunc _Go ()
[/autoit]
MouseMove (1270, 180)
Sleep (100)
MouseDown ("left")
Sleep (100)
MouseMove (1270, 920, 100)
MouseUp ("left")
EndFunc