Hi, ich habe mich an einem Image Viewer versucht, bei dem man in Vollbild Bilder aus einem Ordner in zufälliger Reihenfolge ansehen kann. Im Großen und Ganzen funktioniert das auch. Aber es gibt ein paar kleine Probleme:
1. Wenn man das Bild wechselt flackert es kurz schwarz. Ich habe zwei Pic-Controls verwendet, da es vorher viel schlimmer war, aber es ist immernoch nicht ganz toll.
2. Mein Hauptproblem ist, dass wenn man zurück geht (Pfeiltaste links) auf ein Bild welches größer ist als der Bildschirm, wird es aus irgendeinem Grund trotzdem nicht skaliert angezeigt sondern man sieht dann eben nur die Ecke oben links.
Spoiler anzeigen
#include <GUIConstantsEx.au3>
;~ #include <WindowsConstants.au3>
#include <GDIPlus.au3>
#include <Array.au3>
$Dir = "C:\Windows\Web\Wallpaper"
[/autoit] [autoit][/autoit] [autoit]$FileList = _GetFilesFolder_Rekursiv($Dir, "jpg", 0)
Global $DisplayHistory[0]
$HistoryStep = 0
$Form1 = GUICreate("Image Viewer", @DesktopWidth, @DesktopHeight, 0, 0, BitOR(0x01000000, 0x80000000))
GUISetBkColor(0x000000)
Global $Pic[2]
$Pic[0] = GUICtrlCreatePic("",0,0,0,0)
$Pic[1] = GUICtrlCreatePic("",0,0,0,0)
GUICtrlSetState(-1, $GUI_HIDE)
$DebugLabel = GUICtrlCreateLabel("", 0, 0, 500, 500)
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
GUICtrlSetColor(-1, 0xffffff)
$PicCurrent = 0
SetRandomPic()
GUISetState(@SW_SHOW)
HotKeySet("{RIGHT}", "SetRandomPic")
HotKeySet("{LEFT}", "Undo")
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
EndSwitch
WEnd
Func Undo()
$HistoryStep += 1
$Index = UBound($DisplayHistory) - 1 - $HistoryStep
If $Index >= 0 Then
SetPic($DisplayHistory[$Index])
Else
$HistoryStep -= 1
EndIf
EndFunc
Func Redo()
$HistoryStep -= 1
$Index = UBound($DisplayHistory) - 1 - $HistoryStep
SetPic($DisplayHistory[$Index])
EndFunc
Func SetRandomPic()
If $HistoryStep > 0 Then
Redo()
Return
EndIf
Do
$File = $FileList[Random(1, $FileList[0], 1)]
Until _ArraySearch($DisplayHistory, $File) = -1
If UBound($DisplayHistory) >= $FileList[0] - 1 Then ReDim $DisplayHistory[0]
If $FileList[0] > 1 Then _ArrayAdd($DisplayHistory, $File)
SetPic($File)
EndFunc
Func SetPic($Path)
_GDIPlus_Startup()
$Image = _GDIPlus_BitmapCreateFromFile($Path)
$Width = _GDIPlus_ImageGetWidth($Image)
$Height = _GDIPlus_ImageGetHeight($Image)
_GDIPlus_BitmapDispose($Image)
_GDIPlus_Shutdown()
$Scaling = 1
If $Width > @DesktopWidth Then
$Scaling = @DesktopWidth / $Width
EndIf
If $Height * $Scaling > @DesktopHeight Then
$Scaling = @DesktopHeight / $Height
EndIf
$PicCurrentNew = 1
If $PicCurrent = 1 Then $PicCurrentNew = 0
GUICtrlSetPos($Pic[$PicCurrentNew], (@DesktopWidth - Floor($Width * $Scaling)) / 2, (@DesktopHeight - Floor($Height * $Scaling)) / 2, Floor($Width * $Scaling), Floor($Height * $Scaling))
GUICtrlSetImage($Pic[$PicCurrentNew], $Path)
GUICtrlSetState($Pic[$PicCurrentNew], $GUI_SHOW)
GUICtrlSetState($Pic[$PicCurrent], $GUI_HIDE)
GUICtrlSetImage($Pic[$PicCurrent], "")
$PicCurrent = $PicCurrentNew
GUICtrlSetData($DebugLabel, "X: " & (@DesktopWidth - Floor($Width * $Scaling)) / 2 & @CRLF & "Y: " & (@DesktopHeight - Floor($Height * $Scaling)) / 2 & @CRLF & "Width: " & Floor($Width * $Scaling) & @CRLF & "Height: " & Floor($Height * $Scaling))
;~ MsgBox(0,"", (@DesktopWidth - Floor($Width * $Scaling)) / 2 & @CRLF & (@DesktopHeight - Floor($Height * $Scaling)) / 2 & @CRLF & Floor($Width * $Scaling) & @CRLF & Floor($Height * $Scaling))
EndFunc
;--------
;==================================================================================================
; Function Name: _GetFilesFolder_Rekursiv($sPath [, $sExt='*' [, $iDir=-1 [, $iRetType=0 ,[$sDelim='0']]]])
; Description: Rekursive Auflistung von Dateien und/oder Ordnern
; Parameter(s): $sPath der Basispfad für die Auflistung ('.' -aktueller Pfad, '..' -Parentpfad)
; $sExt Erweiterung für Dateiauswahl '*' oder -1 für alle (Standard)
; $iDir -1 Dateien+Ordner(Standard), 0 nur Dateien, 1 nur Ordner
; optional: $iRetType 0 gibt Array, 1 gibt String zurück
; optional: $sDelim legt Trennzeichen für Stringrückgabe fest
; 0 -@CRLF (Standard) 1 -@CR 2 -@LF 3 -';' 4 -'|'
; Return Value(s): Array (Standard) od. String mit den gefundenen Pfaden der Dateien und/oder Ordner
; Array[0] enthält die Anzahl der gefundenen Dateien/Ordner
; Author(s): BugFix ([email='bugfix@autoit.de'][/email])
;==================================================================================================
Func _GetFilesFolder_Rekursiv($sPath, $sExt='*', $iDir=-1, $iRetType=0, $sDelim='0')
Global $oFSO = ObjCreate('Scripting.FileSystemObject')
Global $strFiles = ''
Switch $sDelim
Case '1'
$sDelim = @CR
Case '2'
$sDelim = @LF
Case '3'
$sDelim = ';'
Case '4'
$sDelim = '|'
Case Else
$sDelim = @CRLF
EndSwitch
If ($iRetType < 0) Or ($iRetType > 1) Then $iRetType = 0
If $sExt = -1 Then $sExt = '*'
If ($iDir < -1) Or ($iDir > 1) Then $iDir = -1
_ShowSubFolders($oFSO.GetFolder($sPath),$sExt,$iDir,$sDelim)
If $iRetType = 0 Then
Local $aOut
$aOut = StringSplit(StringTrimRight($strFiles, StringLen($sDelim)), $sDelim, 1)
If $aOut[1] = '' Then
ReDim $aOut[1]
$aOut[0] = 0
EndIf
Return $aOut
Else
Return StringTrimRight($strFiles, StringLen($sDelim))
EndIf
EndFunc
Func _ShowSubFolders($Folder, $Ext='*', $Dir=-1, $Delim=@CRLF)
If Not IsDeclared("strFiles") Then Global $strFiles = ''
If ($Dir = -1) Or ($Dir = 0) Then
For $file In $Folder.Files
If $Ext <> '*' Then
If StringRight($file.Name, StringLen($Ext)) = $Ext Then _
$strFiles &= $file.Path & $Delim
Else
$strFiles &= $file.Path & $Delim
EndIf
Next
EndIf
For $Subfolder In $Folder.SubFolders
If ($Dir = -1) Or ($Dir = 1) Then $strFiles &= $Subfolder.Path & '\' & $Delim
_ShowSubFolders($Subfolder, $Ext, $Dir, $Delim)
Next
EndFunc