#NoTrayIcon
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiStatusBar.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GDIPlus.au3>

AutoItSetOption("MustDeclareVars", 1)
AutoItSetOption("GUIOnEventMode", 1)

#Region Variablen
; #####################################################################################
;   ##     ##    ###    ########  ####    ###    ########  ##       ######## ##    ##
;   ##     ##   ## ##   ##     ##  ##    ## ##   ##     ## ##       ##       ###   ##
;   ##     ##  ##   ##  ##     ##  ##   ##   ##  ##     ## ##       ##       ####  ##
;   ##     ## ##     ## ########   ##  ##     ## ########  ##       ######   ## ## ##
;    ##   ##  ######### ##   ##    ##  ######### ##     ## ##       ##       ##  ####
;     ## ##   ##     ## ##    ##   ##  ##     ## ##     ## ##       ##       ##   ###
;      ###    ##     ## ##     ## #### ##     ## ########  ######## ######## ##    ##
;~ ####################################################################################
; Alle Variablen für die GUI
Global $h_FormFotoSortNeu
Global $id_GroupTargetDirectories, $id_ButtonZV1Copy, $id_ButtonZV1Move, $id_InputZV1Path, $id_ButtonZV1SelectPath, $id_ButtonAddZV, $id_ButtonRemoveZV
Global $id_GroupFileFormats, $id_CheckboxFormat_BMP, $id_CheckboxFormat_TIFF, $id_CheckboxFormat_JPEG, $id_CheckboxFormat_PNG, $id_CheckboxFormat_GIF, $id_CheckboxFormat_ICO, $id_CheckboxFormat_EMF, $id_CheckboxFormat_WMF
Global $id_GroupFileExists, $id_RadioOverwrite, $id_RadioAddSuffix, $id_InputSuffix, $id_RadioAskOverwrite, $id_CheckboxOnlyIfDifferent, $id_LabelCountingNumber
Global $id_GroupTools, $id_ButtonTool1, $id_ButtonTool2, $id_ButtonTool3, $id_ButtonTool4, $id_ButtonTool5, $id_ButtonTool6, $id_ButtonTool7, $id_ButtonTool8
Global $id_GroupQuellverzeichnis, $id_InputSourceDirectory, $id_ButtonSelectSourceDirectory, $id_CheckboxScanFolderRecursive
Global $id_Picture, $id_ButtonPicBack100, $id_ButtonPicBack10, $id_ButtonPicBack1, $id_ButtonForward1, $id_ButtonForward10, $id_ButtonForward100, $id_ButtonPicGoToFirst, $id_ButtonGoToLast, $id_InputPicNumber, $id_CheckboxPictureFitSize
Global $id_StatusBar

Global $a_id_TargetDirectories[2][5]	; [0][0] = Anzahl
										; [x][1] = Button kopieren
										; [x][2] = Butten verschieben
										; [x][3] = Input
										; [x][4] = Pfadauswahl
Global $id_ButtonAddTargetDirectory, $id_ButtonRemoveTargetDirectory
Global $i_Distance = 44 ; Abstand zwischen den Zeilen

; Fenstergröße sichern / Variablen für erlaubte Größen
Global $a_FormFotoSortNew_Size
Global $i_FormFotoSortNew_SizeMinWidth, $i_FormFotoSortNew_SizeMinHeight, $i_FormFotoSortNew_SizeMaxWidth, $i_FormFotoSortNew_SizeMaxHeight

; GDIPlus
Global $aGDIPlusDecoders, $a_id_CheckboxFileformat[1]
Global $h_Graphic

Global $i_GuiWidth = 1009
Global $i_GuiHeight = 730

Global $h_Bitmap
Global $h_GraphicBuff
Global $a_h_Brush[4], $i_BgColor = 0
Global $h_Texture

Global $i_PreviewLeft = 5
Global $i_PreviewTop = 88
Global $i_PreviewWidth = 514
Global $i_PreviewHeight = 530


#EndRegion Variablen

#Region Funktionen
; ###############################################################################################################################################################################################
;   ######## ##     ## ##    ## ##    ## ######## ####  #######  ##    ## ######## ##    ##
;   ##       ##     ## ###   ## ##   ##     ##     ##  ##     ## ###   ## ##       ###   ##
;   ##       ##     ## ####  ## ##  ##      ##     ##  ##     ## ####  ## ##       ####  ##
;   ######   ##     ## ## ## ## #####       ##     ##  ##     ## ## ## ## ######   ## ## ##
;   ##       ##     ## ##  #### ##  ##      ##     ##  ##     ## ##  #### ##       ##  ####
;   ##       ##     ## ##   ### ##   ##     ##     ##  ##     ## ##   ### ##       ##   ###
;   ##        #######  ##    ## ##    ##    ##    ####  #######  ##    ## ######## ##    ##
; ###############################################################################################################################################################################################
;~       ____ _               _    _               _____ _ _       __                            _
;~      / ___| |__   ___  ___| | _| |__   _____  _|  ___(_) | ___ / _| ___  _ __ _ __ ___   __ _| |_
;~     | |   | '_ \ / _ \/ __| |/ / '_ \ / _ \ \/ / |_  | | |/ _ \ |_ / _ \| '__| '_ ` _ \ / _` | __|
;~     | |___| | | |  __/ (__|   <| |_) | (_) >  <|  _| | | |  __/  _| (_) | |  | | | | | | (_| | |_
;~  ____\____|_| |_|\___|\___|_|\_\_.__/ \___/_/\_\_|   |_|_|\___|_|  \___/|_|  |_| |_| |_|\__,_|\__|
;~ |_____|
Func _CheckboxFileformat()
	; Prüfen ob der Haken bei "Alle" gesetzt oder entfernt wurde
	If @GUI_CtrlId = $a_id_CheckboxFileformat[0] Then
		; laut Hilfe darf man den Wert bei Checkboxen direkt nutzen!
		Local $i_CheckedOrNot = GUICtrlRead($a_id_CheckboxFileformat[0])
		For $i = 1 To (UBound($a_id_CheckboxFileformat) - 1) Step 1
			GUICtrlSetState($a_id_CheckboxFileformat[$i], $i_CheckedOrNot)
		Next
		; Was wird da gemacht? Wir setzen einfach alle Checkboxen auf den gleichen Wert wie den von $a_id_CheckboxFileformat[0]
		; Ist die angehakt so wird der Haken überall gesetzt, wird er entfernt wird er wieder überall gelöscht
	Else
		; Ok, es war eine der anderen Checkboxen. Wenn auch nur eine von denen nicht aktiviert ist muss der haken bei alle wieder raus
		; sind alle gesetzt soll der Haken aber rein. Wir setzen ihn erst rein und schauen dann ob er raus muss
		GUICtrlSetState($a_id_CheckboxFileformat[0], $GUI_CHECKED)
		For $i = 1 To (UBound($a_id_CheckboxFileformat) - 1) Step 1
			If GUICtrlRead($a_id_CheckboxFileformat[$i]) = $GUI_UNCHECKED Then
				GUICtrlSetState($a_id_CheckboxFileformat[0], $GUI_UNCHECKED)
				ExitLoop
			EndIf
		Next
	EndIf
EndFunc

; ###############################################################################################################################################################################################
;~       ____                _       ____       _   _                _____         _
;~      / ___|_ __ ___  __ _| |_ ___|  _ \ __ _| |_| |_ ___ _ __ _ _|_   _|____  _| |_ _   _ _ __ ___
;~     | |   | '__/ _ \/ _` | __/ _ \ |_) / _` | __| __/ _ \ '__| '_ \| |/ _ \ \/ / __| | | | '__/ _ \
;~     | |___| | |  __/ (_| | ||  __/  __/ (_| | |_| ||  __/ |  | | | | |  __/>  <| |_| |_| | | |  __/
;~  ____\____|_|  \___|\__,_|\__\___|_|   \__,_|\__|\__\___|_|  |_| |_|_|\___/_/\_\\__|\__,_|_|  \___|
;~ |_____|
Func _CreatePatternTexture($iLeft, $iTop, $iWidth, $iHeight) ; Danke an UEZ (www.autoit.de)
	Local $iStep = 8
	Local $aResult = DllCall($__g_hGDIPDll, "uint", "GdipCreateBitmapFromScan0", "int", 2 * $iStep, "int", 2 * $iStep, "int", 0, "int", $GDIP_PXF32ARGB, "ptr", 0, "int*", 0)
	Local $hPatternBitmap = $aResult[6]
	Local $hCtxt = _GDIPlus_ImageGetGraphicsContext($hPatternBitmap)
	_GDIPlus_GraphicsFillRect($hCtxt, 0, 0, $iStep, $iStep, $a_h_Brush[0])
	_GDIPlus_GraphicsFillRect($hCtxt, $iStep, 0, $iStep, $iStep, $a_h_Brush[1])
	_GDIPlus_GraphicsFillRect($hCtxt, 0, $iStep, $iStep, $iStep, $a_h_Brush[1])
	_GDIPlus_GraphicsFillRect($hCtxt, $iStep, $iStep, $iStep, $iStep, $a_h_Brush[0])
	$aResult = DllCall($__g_hGDIPDll, "uint", "GdipCreateTexture", "handle", $hPatternBitmap, "int", 0, "int*", 0)
	Local $hTexture = $aResult[3]
	_GDIPlus_GraphicsFillRect($h_GraphicBuff, $iLeft, $iTop, $iWidth, $iHeight, $hTexture)
	_GDIPlus_GraphicsDispose($hCtxt)
	_GDIPlus_BitmapDispose($hPatternBitmap)
	Return $hTexture
EndFunc   ;==>_CreatePatternTexture

; ###############################################################################################################################################################################################
Func _DrawBgColor($iLeft, $iTop, $iWidth, $iHeight)
	Switch $i_BgColor
		Case 0
			_GDIPlus_GraphicsFillRect($h_GraphicBuff, $iLeft, $iTop, $iWidth, $iHeight, $h_Texture)
		Case 1
			_GDIPlus_GraphicsFillRect($h_GraphicBuff, $iLeft, $iTop, $iWidth, $iHeight, $a_h_Brush[3])
		Case 2
			_GDIPlus_GraphicsFillRect($h_GraphicBuff, $iLeft, $iTop, $iWidth, $iHeight, $a_h_Brush[2])
	EndSwitch
EndFunc   ;==>_DrawBgColor
; ###############################################################################################################################################################################################
;~       _____     _     _               _       _     _
;~      |  ___|__ | | __| | ___ _ __    / \   __| | __| |
;~      | |_ / _ \| |/ _` |/ _ \ '__|  / _ \ / _` |/ _` |
;~      |  _| (_) | | (_| |  __/ |    / ___ \ (_| | (_| |
;~  ____|_|  \___/|_|\__,_|\___|_|___/_/   \_\__,_|\__,_|
;~ |_____|                      |_____|
Func _Folder_Add()
	; Es wurde auf das + geklickt und der Anwender will eine Zeile mehr bekommen
	; Abstand zwischen den Zeilen festlegen
;~ 	Local $i_Distance = 32


	; Wie groß ist die Group überhaupt ?
	Local $a_GroupSize = ControlGetPos($h_FormFotoSortNeu, "", $id_GroupTargetDirectories)
	; Platzbedarf: Pro Zeile $i_Distance Abstand mal die Anzahl der Zeilen

	If (($a_id_TargetDirectories[0][0] + 1) * $i_Distance) >= ($a_GroupSize[3] - $i_Distance) Then
		MsgBox(64, "Zuviele Zielverzeichnisse", "Group Höhe: " & $a_GroupSize[3] & @CRLF & "Platzbedarf: " & ($a_id_TargetDirectories[0][0] + 1) & " * " & $i_Distance & " = " & (($a_id_TargetDirectories[0][0] + 1) * $i_Distance) )
		Return 1
	EndIf
	; Array mit den Controls um 1 vergrößern
	$a_id_TargetDirectories[0][0] = $a_id_TargetDirectories[0][0] + 1
	ReDim $a_id_TargetDirectories[ $a_id_TargetDirectories[0][0] + 1 ][5]

	; Platz schaffen, die Buttons mit + und - eine Zeile tiefer setzen
	Local $a_ControlPos = ControlGetPos($h_FormFotoSortNeu, "", $a_id_TargetDirectories[ $a_id_TargetDirectories[0][0] ][1])
	GUICtrlSetPos($id_ButtonAddTargetDirectory, $a_ControlPos[0], 232 + (($a_id_TargetDirectories[0][0] - 1) * $i_Distance))
	GUICtrlSetPos($id_ButtonRemoveTargetDirectory, $a_ControlPos[0] + 32, 232 + (($a_id_TargetDirectories[0][0] - 1) * $i_Distance))

	; Und die neuen Buttons und Input bauen:
	; Die Position der Zeile darüber holen (Button kopieren)
	$a_ControlPos = ControlGetPos($h_FormFotoSortNeu, "", $a_id_TargetDirectories[ $a_id_TargetDirectories[0][0] - 1 ][1])

	; Den Button für kopieren
	$a_id_TargetDirectories[ $a_id_TargetDirectories[0][0] ][1] = GUICtrlCreateButton($a_id_TargetDirectories[0][0], $a_ControlPos[0], 200 + (($a_id_TargetDirectories[0][0] - 1) * $i_Distance), 33, 25)
	GUICtrlSetOnEvent($a_id_TargetDirectories[ $a_id_TargetDirectories[0][0] ][1], "_Picture_Copy")
	; Diesen und die nachfolgenden Buttons heften wir Rechts und oben an, Größe ist fix
	GUICtrlSetResizing($a_id_TargetDirectories[ $a_id_TargetDirectories[0][0] ][1], $GUI_DOCKRIGHT+$GUI_DOCKTOP+$GUI_DOCKWIDTH+$GUI_DOCKHEIGHT)
	GUICtrlSetTip($a_id_TargetDirectories[ $a_id_TargetDirectories[0][0] ][1], "Datei kopieren")

	; Den Button für verschieben
	$a_id_TargetDirectories[ $a_id_TargetDirectories[0][0] ][2] = GUICtrlCreateButton("»", $a_ControlPos[0] + 32, 200 + (($a_id_TargetDirectories[0][0] - 1) * $i_Distance), 33, 25)
	GUICtrlSetOnEvent($a_id_TargetDirectories[ $a_id_TargetDirectories[0][0] ][2], "_Picture_Move")
	GUICtrlSetResizing($a_id_TargetDirectories[ $a_id_TargetDirectories[0][0] ][2], $GUI_DOCKRIGHT+$GUI_DOCKTOP+$GUI_DOCKWIDTH+$GUI_DOCKHEIGHT)
	GUICtrlSetTip($a_id_TargetDirectories[ $a_id_TargetDirectories[0][0] ][2], "Datei verschieben")

	; Das Input mit dem Pfad
	$a_id_TargetDirectories[ $a_id_TargetDirectories[0][0] ][3] = GUICtrlCreateInput("", $a_ControlPos[0] + 67, 200 + (($a_id_TargetDirectories[0][0] - 1) * $i_Distance), 354, 25, BitOR($ES_READONLY,$ES_LEFT, $ES_AUTOHSCROLL), BitOR($WS_EX_CLIENTEDGE, $WS_EX_ACCEPTFILES))
	GUICtrlSetFont($a_id_TargetDirectories[ $a_id_TargetDirectories[0][0] ][3], 11, 400, 0, "Arial")
	GUICtrlSetBkColor($a_id_TargetDirectories[ $a_id_TargetDirectories[0][0] ][3], 0xFFFFE1)
	GUICtrlSetResizing($a_id_TargetDirectories[ $a_id_TargetDirectories[0][0] ][3], $GUI_DOCKRIGHT+$GUI_DOCKTOP+$GUI_DOCKWIDTH+$GUI_DOCKHEIGHT)
	; Damit das Feld Drag'n Drop annimmt (muss zusätzlich zum Extended-Style gesetzt werden)
	GUICtrlSetState($a_id_TargetDirectories[ $a_id_TargetDirectories[0][0] ][3], $GUI_DROPACCEPTED)

	; Und noch der Button für die Pfadauswahl
	$a_id_TargetDirectories[ $a_id_TargetDirectories[0][0] ][4] = GUICtrlCreateButton("...", $a_ControlPos[0] + 424, 200 + (($a_id_TargetDirectories[0][0] - 1) * $i_Distance), 33, 25)
	GUICtrlSetOnEvent($a_id_TargetDirectories[ $a_id_TargetDirectories[0][0] ][4], "_Folder_Select")
	GUICtrlSetResizing($a_id_TargetDirectories[ $a_id_TargetDirectories[0][0] ][4], $GUI_DOCKRIGHT+$GUI_DOCKTOP+$GUI_DOCKWIDTH+$GUI_DOCKHEIGHT)
	GUICtrlSetTip($a_id_TargetDirectories[ $a_id_TargetDirectories[0][0] ][4], "Pfad wählen")

	; Ggf den + Button deaktivieren:
	Local $a_GroupSize = ControlGetPos($h_FormFotoSortNeu, "", $id_GroupTargetDirectories)
	If (($a_id_TargetDirectories[0][0] + 1) * $i_Distance) >= ($a_GroupSize[3] - $i_Distance) Then
		GUICtrlSetState($id_ButtonAddTargetDirectory, $GUI_DISABLE)
	Else
		GUICtrlSetState($id_ButtonAddTargetDirectory, $GUI_ENABLE)
	EndIf

	; Den - Button aktivieren:
	GUICtrlSetState($id_ButtonRemoveTargetDirectory, $GUI_ENABLE)

	; Titel der Group anpassen
	GUICtrlSetData($id_GroupTargetDirectories, " Zielverzeichnisse (1.." & $a_id_TargetDirectories[0][0] & "): ")
EndFunc
; ###############################################################################################################################################################################################
;~       _____     _     _            ____
;~      |  ___|__ | | __| | ___ _ __ |  _ \ ___ _ __ ___   _____   _____
;~      | |_ / _ \| |/ _` |/ _ \ '__|| |_) / _ \ '_ ` _ \ / _ \ \ / / _ \
;~      |  _| (_) | | (_| |  __/ |   |  _ <  __/ | | | | | (_) \ V /  __/
;~  ____|_|  \___/|_|\__,_|\___|_|___|_| \_\___|_| |_| |_|\___/ \_/ \___|
;~ |_____|                      |_____|
Func _Folder_Remove()
	; Und wieder weg mit den Zeilen
	; Falls es die letzte Zeile ist gleich wieder raus
	If $a_id_TargetDirectories[0][0] = 1 Then
		GUICtrlSetState($id_ButtonRemoveTargetDirectory, $GUI_DISABLE)
		Return 1
	EndIf

	; Und löschen
	For $i = 1 To 4 Step 1
		GUICtrlDelete($a_id_TargetDirectories[ $a_id_TargetDirectories[0][0] ][$i])
		$a_id_TargetDirectories[ $a_id_TargetDirectories[0][0] ][$i] = ""
	Next
	; Array wieder verkleinern
	$a_id_TargetDirectories[0][0] = $a_id_TargetDirectories[0][0] - 1
	ReDim $a_id_TargetDirectories[ $a_id_TargetDirectories[0][0] + 1 ][5]

	; Die + und - Schaltfläche wieder hochrücken:
	Local $a_ControlPos = ControlGetPos($h_FormFotoSortNeu, "", $a_id_TargetDirectories[ $a_id_TargetDirectories[0][0] ][1])
	GUICtrlSetPos($id_ButtonAddTargetDirectory, $a_ControlPos[0], 232 + (($a_id_TargetDirectories[0][0] - 1) * $i_Distance))
	GUICtrlSetPos($id_ButtonRemoveTargetDirectory, $a_ControlPos[0] + 32, 232 + (($a_id_TargetDirectories[0][0] - 1) * $i_Distance))

	; Sind wir nun die letzte Zeile?
	If $a_id_TargetDirectories[0][0] = 1 Then
		GUICtrlSetState($id_ButtonRemoveTargetDirectory, $GUI_DISABLE)
		Return 1
	EndIf

	; Ggf den + Button wieder aktivieren:
	Local $a_GroupSize = ControlGetPos($h_FormFotoSortNeu, "", $id_GroupTargetDirectories)
	If (($a_id_TargetDirectories[0][0] + 1) * $i_Distance) >= ($a_GroupSize[3] - $i_Distance) Then
		GUICtrlSetState($id_ButtonAddTargetDirectory, $GUI_DISABLE)
	Else
		GUICtrlSetState($id_ButtonAddTargetDirectory, $GUI_ENABLE)
	EndIf


	; Titel der Group anpassen
	GUICtrlSetData($id_GroupTargetDirectories, " Zielverzeichnisse (1.." & $a_id_TargetDirectories[0][0] & "): ")

EndFunc
; ###############################################################################################################################################################################################
;~       _____     _     _            ____       _           _
;~      |  ___|__ | | __| | ___ _ __ / ___|  ___| | ___  ___| |_
;~      | |_ / _ \| |/ _` |/ _ \ '__|\___ \ / _ \ |/ _ \/ __| __|
;~      |  _| (_) | | (_| |  __/ |    ___) |  __/ |  __/ (__| |_
;~  ____|_|  \___/|_|\__,_|\___|_|___|____/ \___|_|\___|\___|\__|
;~ |_____|                      |_____|
Func _Folder_Select()
	Switch @GUI_CtrlId
		Case $id_ButtonSelectSourceDirectory
			MsgBox(0, "", "Quellverzeichnis auswählen")
		Case Else
			MsgBox(0, "", "Zeilverzeichnis auswählen")
	EndSwitch
EndFunc
; ###############################################################################################################################################################################################
;~       ____  _      _                      ____
;~      |  _ \(_) ___| |_ _   _ _ __ ___    / ___|___  _ __  _   _
;~      | |_) | |/ __| __| | | | '__/ _ \  | |   / _ \| '_ \| | | |
;~      |  __/| | (__| |_| |_| | | |  __/  | |__| (_) | |_) | |_| |
;~  ____|_|   |_|\___|\__|\__,_|_|  \___|___\____\___/| .__/ \__, |
;~ |_____|                             |_____|        |_|    |___/
Func _Picture_Copy()
	MsgBox(64, "Picture", "Copy!")
EndFunc
; ###############################################################################################################################################################################################
;~       ____  _      _                      __  __
;~      |  _ \(_) ___| |_ _   _ _ __ ___    |  \/  | _____   _____
;~      | |_) | |/ __| __| | | | '__/ _ \   | |\/| |/ _ \ \ / / _ \
;~      |  __/| | (__| |_| |_| | | |  __/   | |  | | (_) \ V /  __/
;~  ____|_|   |_|\___|\__|\__,_|_|  \___|___|_|  |_|\___/ \_/ \___|
;~ |_____|                             |_____|
Func _Picture_Move()
	MsgBox(64, "Picture", "Move!")
EndFunc

; ###############################################################################################################################################################################################
Func _Preview_Resize()
	Local $a_NewFormSize = WinGetPos($h_FormFotoSortNeu)
	Local $i_PlusX = $a_NewFormSize[2] - $a_FormFotoSortNew_Size[2]
	Local $i_PlusY = $a_NewFormSize[3] - $a_FormFotoSortNew_Size[3]
	GUICtrlSetData($id_InputPicNumber, "$i_PlusX: " & $i_PlusX & " / $i_PlusY: " & $i_PlusY)
;~ 	_GDIPlus_BitmapDispose($h_Bitmap)
;~ 	_GDIPlus_GraphicsDispose($h_Graphic)

;~ 	$h_Graphic = _GDIPlus_GraphicsCreateFromHWND($h_FormFotoSortNeu)
;~ 	_GDIPlus_GraphicsSetSmoothingMode($h_Graphic, 2)
;~ 	$h_Bitmap = _GDIPlus_BitmapCreateFromGraphics($i_GuiWidth, $i_GuiHeight + $i_PlusX, $h_Graphic + $i_PlusY)
;~ 	$h_GraphicBuff = _GDIPlus_ImageGetGraphicsContext($h_Bitmap)


	$h_Texture = _CreatePatternTexture($i_PreviewLeft, $i_PreviewTop, $i_PreviewWidth + $i_PlusX, $i_PreviewHeight + $i_PlusY)
	_GDIPlus_GraphicsDrawRect($h_GraphicBuff, $i_PreviewLeft - 2, $i_PreviewTop - 2, $i_PreviewWidth + 3 + $i_PlusX, $i_PreviewHeight + 3 + $i_PlusY)
	_GDIPlus_GraphicsDrawRect($h_GraphicBuff, $i_PreviewLeft - 1, $i_PreviewTop - 1, $i_PreviewWidth + 1 + $i_PlusX, $i_PreviewHeight + 1 + $i_PlusY)
	_DrawBgColor($i_PreviewLeft, $i_PreviewTop, $i_PreviewWidth + $i_PlusX, $i_PreviewHeight + $i_PlusY)
	_GDIPlus_GraphicsDrawImage($h_Graphic, $h_Bitmap, 0, 0)
EndFunc
; ###############################################################################################################################################################################################
;~  _     _     _____                    _____     _       ____             _   _   _             ____ _
;~ (_) __| |   |  ___|__  _ __ _ __ ___ |  ___|__ | |_ ___/ ___|  ___  _ __| |_| \ | | ___ _   _ / ___| | ___  ___  ___
;~ | |/ _` |   | |_ / _ \| '__| '_ ` _ \| |_ / _ \| __/ _ \___ \ / _ \| '__| __|  \| |/ _ \ | | | |   | |/ _ \/ __|/ _ \
;~ | | (_| |   |  _| (_) | |  | | | | | |  _| (_) | || (_) |__) | (_) | |  | |_| |\  |  __/ |_| | |___| | (_) \__ \  __/
;~ |_|\__,_|___|_|  \___/|_|  |_| |_| |_|_|  \___/ \__\___/____/ \___/|_|   \__|_| \_|\___|\__,_|\____|_|\___/|___/\___|
;~        |_____|
; Wird aufgerufen wenn jemand auf das rote X oben rechts klickt oder ESC drückt (siehe in der Hilfe beim Befehl AutoItSetOption("GUICloseOnESC"))
Func id_FormFotoSortNeuClose()
	If $h_Texture <> 0 Then _GDIPlus_BrushDispose($h_Texture)
;~ 	If $hPreviewBitmap <> 0 Then _GDIPlus_BitmapDispose($hPreviewBitmap)
	If $h_Bitmap <> 0 Then _GDIPlus_BitmapDispose($h_Bitmap)
	If $h_GraphicBuff <> 0 Then _GDIPlus_BitmapDispose($h_GraphicBuff)
	If $h_Graphic <> 0 Then _GDIPlus_GraphicsDispose($h_Graphic)
	_GDIPlus_Shutdown()

	Exit
EndFunc
; ###############################################################################################################################################################################################
;~  _     _     _____                    _____     _       ____             _   _   _            ____           _
;~ (_) __| |   |  ___|__  _ __ _ __ ___ |  ___|__ | |_ ___/ ___|  ___  _ __| |_| \ | | ___ _   _|  _ \ ___  ___| |_ ___  _ __ ___
;~ | |/ _` |   | |_ / _ \| '__| '_ ` _ \| |_ / _ \| __/ _ \___ \ / _ \| '__| __|  \| |/ _ \ | | | |_) / _ \/ __| __/ _ \| '__/ _ \
;~ | | (_| |   |  _| (_) | |  | | | | | |  _| (_) | || (_) |__) | (_) | |  | |_| |\  |  __/ |_| |  _ <  __/\__ \ || (_) | | |  __/
;~ |_|\__,_|___|_|  \___/|_|  |_| |_| |_|_|  \___/ \__\___/____/ \___/|_|   \__|_| \_|\___|\__,_|_| \_\___||___/\__\___/|_|  \___|
;~        |_____|
; Wird aufgerufen wenn die GUI nach dem minimieren wieder sichtbar gemacht wird.
Func id_FormFotoSortNeuRestore()

EndFunc
; ###############################################################################################################################################################################################
;~     _____           _
;~    |_   _|__   ___ | |___
;~      | |/ _ \ / _ \| / __|
;~      | | (_) | (_) | \__ \
;~  ____|_|\___/ \___/|_|___/
;~ |_____|
Func _Tools()
	MsgBox(64, "Tools", "Tools gestartet")
EndFunc
; ###############################################################################################################################################################################################
;~   ____ _   _ ___     _______     _______ _   _ _____   ____  ____   ___  ____  ____  _____ ____
;~  / ___| | | |_ _|   | ____\ \   / / ____| \ | |_   _| |  _ \|  _ \ / _ \|  _ \|  _ \| ____|  _ \
;~ | |  _| | | || |    |  _|  \ \ / /|  _| |  \| | | |   | | | | |_) | | | | |_) | |_) |  _| | | | |
;~ | |_| | |_| || |    | |___  \ V / | |___| |\  | | |   | |_| |  _ <| |_| |  __/|  __/| |___| |_| |
;~  \____|\___/|___|___|_____|  \_/  |_____|_| \_| |_|___|____/|_| \_\\___/|_|   |_|   |_____|____/
;~                |_____|                           |_____|
Func GUI_EVENT_DROPPED()
	MsgBox(0, "Datei:", "Id des Controls: " & @GUI_DragId & @CRLF & "Dateiname: " & @GUI_DragFile)
EndFunc
; ###############################################################################################################################################################################################
;~ __        ____  __     ____ _____ _____ __  __ ___ _   _ __  __    _    __  _____ _   _ _____ ___
;~ \ \      / /  \/  |   / ___| ____|_   _|  \/  |_ _| \ | |  \/  |  / \   \ \/ /_ _| \ | |  ___/ _ \
;~  \ \ /\ / /| |\/| |  | |  _|  _|   | | | |\/| || ||  \| | |\/| | / _ \   \  / | ||  \| | |_ | | | |
;~   \ V  V / | |  | |  | |_| | |___  | | | |  | || || |\  | |  | |/ ___ \  /  \ | || |\  |  _|| |_| |
;~    \_/\_/  |_|  |_|___\____|_____| |_| |_|  |_|___|_| \_|_|  |_/_/   \_\/_/\_\___|_| \_|_|   \___/
;~                  |_____|
; Dient dazu eine minimale und maximale Größe der GUI durchzusetzen.
; gefunden unter: https://www.autoitscript.com/forum/topic/124195-gui-minimum-size/
Func WM_GETMINMAXINFO($hwnd, $Msg, $wParam, $lParam)
    Local $tagMaxinfo = DllStructCreate("int;int;int;int;int;int;int;int;int;int", $lParam)
    DllStructSetData($tagMaxinfo, 7, $i_FormFotoSortNew_SizeMinWidth) ; min X
    DllStructSetData($tagMaxinfo, 8, $i_FormFotoSortNew_SizeMinHeight) ; min Y
    DllStructSetData($tagMaxinfo, 9, $i_FormFotoSortNew_SizeMaxWidth ); max X
    DllStructSetData($tagMaxinfo, 10, $i_FormFotoSortNew_SizeMaxHeight ) ; max Y
	_Preview_Resize()
    Return 0
EndFunc   ;==>WM_GETMINMAXINFO
; ###############################################################################################################################################################################################
;~ __        ____  __     ____   _    ___ _   _ _____
;~ \ \      / /  \/  |   |  _ \ / \  |_ _| \ | |_   _|
;~  \ \ /\ / /| |\/| |   | |_) / _ \  | ||  \| | | |
;~   \ V  V / | |  | |   |  __/ ___ \ | || |\  | | |
;~    \_/\_/  |_|  |_|___|_| /_/   \_\___|_| \_| |_|
;~                  |_____|
Func WM_PAINT($hWnd, $Msg, $wParam, $lParam)
	_WinAPI_RedrawWindow($h_FormFotoSortNeu, 0, 0, $RDW_UPDATENOW)
	_GDIPlus_GraphicsDrawImage($h_Graphic, $h_Bitmap, 0, 0)
	_WinAPI_RedrawWindow($h_FormFotoSortNeu, 0, 0, $RDW_VALIDATE)
	Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_PAINT
; ###############################################################################################################################################################################################
;~ __        ____  __     ____ ___ __________
;~ \ \      / /  \/  |   / ___|_ _|__  / ____|
;~  \ \ /\ / /| |\/| |   \___ \| |  / /|  _|
;~   \ V  V / | |  | |    ___) | | / /_| |___
;~    \_/\_/  |_|  |_|___|____/___/____|_____|
;~                  |_____|
; Dient im Moment nur dazu die StatusBar unten nach einer Größenänderung wieder anzupassen
Func WM_SIZE($hWnd, $iMsg, $iwParam, $ilParam)
    _GUICtrlStatusBar_Resize($id_StatusBar)

	; Ggf den + Button deaktivieren:
	Local $a_GroupSize = ControlGetPos($h_FormFotoSortNeu, "", $id_GroupTargetDirectories)
	If (($a_id_TargetDirectories[0][0] + 1) * $i_Distance) >= ($a_GroupSize[3] - $i_Distance) Then
		GUICtrlSetState($id_ButtonAddTargetDirectory, $GUI_DISABLE)
	Else
		GUICtrlSetState($id_ButtonAddTargetDirectory, $GUI_ENABLE)
	EndIf
	If (($a_id_TargetDirectories[0][0] + 1) * $i_Distance) >= $a_GroupSize[3] Then
		_Folder_Remove()
	EndIf
    Return $GUI_RUNDEFMSG
EndFunc   ;==>MY_WM_SIZE
;~ ###############################################################################################################################################################################################
#EndRegion Funktionen


#Region GUI-FormFotoSortNeu
; ###############################################################################################################################################################################################
;    ######   ##     ## ####
;   ##    ##  ##     ##  ##
;   ##        ##     ##  ##
;   ##   #### ##     ##  ##
;   ##    ##  ##     ##  ##
;   ##    ##  ##     ##  ##
;    ######    #######  ####
; ###############################################################################################################################################################################################

; Das Fenster an sich erstellen. Die Größenwerte 1009 und 730 ist die nutzbare Innenfläche ohne Ränder und Titelleiste (deren Größe von der Windowsversion abhängt)
; Als Styles wurden folgende gewählt:
; $GUI_SS_DEFAULT_GUI: 	beinhaltet die Styles $WS_MINIMIZEBOX, $WS_CAPTION, $WS_POPUP und $WS_SYSMENU
; $WS_MINIMIZEBOX    : Fenster hat eine Minimieren-Schaltfläche
; $WS_CAPTION        : Es gibt eine Titelzeile oben (Steht oft der Programmname drin)
; $WS_POPUP          : Macht ein Popup-Fenster (keine Ahnung wazu das hier drin ist)
; $WS_SYSMENU        : Erlaubt das Menü das kommt wenn man oben links auf das Programsymbol in der Titelleiste klickt
; $WS_MAXIMIZEBOX    : Fenster hat eine Maximieren-Schaltfläche
; $WS_SIZEBOX        : Fenster hat einen Rahmen zur Größenänderung
; $WS_TABSTOP        : Die Controls im Fenster können per Tabulator-Taste durchgeschaltet werden
; Als Extended Styles wurden folgende gewählt:
; $WS_EX_ACCEPTFILES : Man darf Dateien auf Edit-Controls ziehen, die bekommen dann den Dateinamen
$h_FormFotoSortNeu = GUICreate("FotoSortNeu", 1009, 730, -1, -1, BitOR($GUI_SS_DEFAULT_GUI,$WS_MAXIMIZEBOX,$WS_SIZEBOX,$WS_TABSTOP), $WS_EX_ACCEPTFILES)
; Schriftart setzen - diese wird von allen Controls verwendet sofern nicht etwas anderes an diesen angegeben werden
GUISetFont(10, 400, 0, "Verdana")
GUISetBkColor(0xC8C8C8)
GUISetOnEvent($GUI_EVENT_CLOSE, "id_FormFotoSortNeuClose")
GUISetOnEvent($GUI_EVENT_RESTORE, "id_FormFotoSortNeuRestore")


; Die Statusbar unten erstellen
$id_StatusBar = _GUICtrlStatusBar_Create($h_FormFotoSortNeu, -1, "", BitOR($WS_VISIBLE,$WS_CHILD,$WS_BORDER))
; Die Größe der 3 Abschnitte, -1 = bis zum Ende
Local $id_StatusBar_PartsWidth[3] = [500, 800, -1]
_GUICtrlStatusBar_SetParts($id_StatusBar, $id_StatusBar_PartsWidth)
;Anfangstext in die einzelnen Abschnitte der Statusbar setzen
_GUICtrlStatusBar_SetText($id_StatusBar, "Status", 0)
_GUICtrlStatusBar_SetText($id_StatusBar, "Bild 0 von 0", 1)
_GUICtrlStatusBar_SetText($id_StatusBar, "Bildinfos", 2)
_GUICtrlStatusBar_SetMinHeight($id_StatusBar, 22)

; Die Gruppen oben links mit dem Pfad zum aktuellen Ordner erstellen
$id_GroupQuellverzeichnis = GUICtrlCreateGroup(" Quellverzeichnis: ", 5, 8, 514, 68)
; Die Gruppe - und alle Controls in dieser - heften wir an den linken + oberen + rechten Rand - damit die bei Größenänderungen oben bleibt, sich aber in die Breite zieht. Die Höhe ist gesperrt
GUICtrlSetResizing($id_GroupQuellverzeichnis, $GUI_DOCKLEFT+$GUI_DOCKRIGHT+$GUI_DOCKTOP+$GUI_DOCKHEIGHT)
; Das Input-Feld, ist Readonly, aktzeptiert Drag'n Drop
$id_InputSourceDirectory = GUICtrlCreateInput("", 13, 28, 462, 25, BitOR($ES_READONLY,$ES_LEFT, $ES_AUTOHSCROLL), BitOR($WS_EX_CLIENTEDGE, $WS_EX_ACCEPTFILES))
GUICtrlSetFont($id_InputSourceDirectory, 11, 400, 0, "Arial")
GUICtrlSetBkColor($id_InputSourceDirectory, 0xFFFFE1)
; Das Edit heften wir links, rechts und oben fest - damit es sich nicht in der Höhe ändert aber in die Breite geht. Höhe ist wieder gesperrt
GUICtrlSetResizing($id_InputSourceDirectory, $GUI_DOCKLEFT+$GUI_DOCKRIGHT+$GUI_DOCKTOP+$GUI_DOCKHEIGHT)
; Damit das Feld Drag'n Drop annimmt (muss zusätzlich zum Extended-Style gesetzt werden)
GUICtrlSetState($id_InputSourceDirectory, $GUI_DROPACCEPTED)
; Der Button für die Auswahl der Datei
$id_ButtonSelectSourceDirectory = GUICtrlCreateButton("...", 477, 28, 33, 25)
; Den heften wir nur oben und rechts an - damit der mit nach rechts wandert wenn wir die GUI vergößern. Höhe und Breite ist gesperrt
GUICtrlSetResizing($id_ButtonSelectSourceDirectory, $GUI_DOCKRIGHT+$GUI_DOCKTOP+$GUI_DOCKWIDTH+$GUI_DOCKHEIGHT)
GUICtrlSetOnEvent($id_ButtonSelectSourceDirectory, "_Folder_Select")
; Und noch die Checkbox für die rekursive Suche
$id_CheckboxScanFolderRecursive = GUICtrlCreateCheckbox("inklusive Unterordner (Rekursiv)", 13, 56, 225, 17)
; Die heften wir oben und links an - so bleibt die einfach auf der Stelle stehen, Höhe und Breite gesperrt
GUICtrlSetResizing($id_CheckboxScanFolderRecursive, $GUI_DOCKLEFT+$GUI_DOCKTOP+$GUI_DOCKWIDTH+$GUI_DOCKHEIGHT)
; Gruppe ist fertig, also schließen
GUICtrlCreateGroup("", -99, -99, 1, 1)

; Nun die verfügbaren Bildformate. Wie bei Oscar keine feste Liste sondern alles das was GDIPlus so kann.
$id_GroupFileFormats = GUICtrlCreateGroup(" Dateiformate: ", 528, 8, 473, 68)
; Die Group ist fest in der Größe und oben sowie rechts angeheftet
GUICtrlSetResizing($id_GroupFileFormats, $GUI_DOCKRIGHT+$GUI_DOCKTOP+$GUI_DOCKWIDTH+$GUI_DOCKHEIGHT)
; Um GDIPlus nutzen zu können müssen wir es starten:
_GDIPlus_Startup()
; und die verfügbaren Decoders abfragen. Hinweis: Den für GIF werden wir später nicht nutzen sondern einen anderen der mit animierten GIF umgehen kann.
$aGDIPlusDecoders = _GDIPlus_Decoders()
; $aGDIPlusDecoders sieht jetzt - gekürzt - wie folgt aus:
; $aGDIPlusDecoders[0][0] = Anzahl der verfügbaren Decoders
; $aGDIPlusDecoders[x][5] = Der Name des Dateiformates, z.B. BMP
; Die ControlIds der ganzen Checkboxen packen wir in ein Array. Das ist um 1 größer als nötig - wir packen noch eine Option "Alle" dazu.
; Oscar hat das als Popup/Rechtsklick Menü gemacht. Das hatte ich erst gefunden als ich es im Quellcode gesehen hatte.
ReDim $a_id_CheckboxFileformat[ $aGDIPlusDecoders[0][0] + 1 ]
; Die erste Checkbox mit "Alle" kommte oben links in die Group. Alle sind 65 lang und 17 hoch
$a_id_CheckboxFileformat[0] = GUICtrlCreateCheckbox("Alle", 536, 28, 65, 17)
GUICtrlSetOnEvent($a_id_CheckboxFileformat[0], "_CheckboxFileformat")
GUICtrlSetResizing($a_id_CheckboxFileformat[0], $GUI_DOCKRIGHT+$GUI_DOCKTOP+$GUI_DOCKWIDTH+$GUI_DOCKHEIGHT)
; Die erste Reihe kommt auf 28, die zweite Reihe auf 52
; Abstand Horizontal sind 72
For $i = 1 To $aGDIPlusDecoders[0][0] Step 1
	; So die Formel habe ich mir bei Oscar abgeschaut - und musste erst einmal überlegen was er da macht
	$a_id_CheckboxFileformat[$i] = GUICtrlCreateCheckbox($aGDIPlusDecoders[$i][5], 614 + Mod($i - 1, 5) * 78, 28 + Int(($i - 1) / 5) * 24, 65, 17)
	; X: 	614 + Mod($i - 1, 5) * 72
	; 614 Pixel von links fangen wir an, dazu addieren wir das Ergebnis der rechten Berechnung (Punkt vor Strichrechnung!)
	; Mod($i - 1, 5) ergibt - bei $i 1 bis 8 - die Zahlenfolge 0 1 2 3 4 0 1 2
	; Und den Wert Multiplizieren wir immer mit 72, dem gewünschten Abstand der Spalten
	; Y: 	28 + Int(($i - 1) / 5) * 24
	; 28 Pixel von oben ist die erste Reihe
	; ($i - 1) / 5 liefert und die Zahlenfolge 0 0.2 0.4 0.8 1 1.2 1.4 usw.
	; Durch Int() bekommen wir nur den Teil vor dem . (ohne Runden) also 0 0 0 0 1 1 1, also 4 mal 0 und dann 1 (und 2, 3 je nach Größe von $i)
	; Und das dann mal 24, denn bei 28 + 24 = 52 soll die 2 Zeile hin

	; Die Checkboxen haben alle eine feste Größe und werden oben und rechts angeheftet
	GUICtrlSetResizing($a_id_CheckboxFileformat[$i], $GUI_DOCKRIGHT+$GUI_DOCKTOP+$GUI_DOCKWIDTH+$GUI_DOCKHEIGHT)
	; Und noch die Funktion die aufgerufen werden soll wenn sich ein Wert ändert:
	GUICtrlSetOnEvent($a_id_CheckboxFileformat[$i], "_CheckboxFileformat")
	; und der Tooltip
	GUICtrlSetTip($a_id_CheckboxFileformat[$i], "Alle Dateien mit Dateiendung: " & StringLower($aGDIPlusDecoders[$i][6]))

Next
; Und die Gruppe ist komplett, also zumachen
GUICtrlCreateGroup("", -99, -99, 1, 1)


; Die Gruppe mit den Zielverzeichnissen. Ein Grund warum ich dieses Programm neu geschrieben habe. Ich brauchte mehr davon und der Platz des Bildschirmes sollte besser ausgenutzt werden
; Die Anzahl der Zielverzeichniss ist dynamisch
; Group anlegen
$id_GroupTargetDirectories = GUICtrlCreateGroup(" Zielverzeichnisse (1..1): ", 528, 176, 473, 441)
; Die Group rechts, oben und unten angeheftet. Die Breite ist fix, die Höhe nicht. Dadurch wird die Gruppe - als einzige - größer wenn das fenster vergrößert wird
GUICtrlSetResizing($id_GroupTargetDirectories, $GUI_DOCKRIGHT+$GUI_DOCKTOP+$GUI_DOCKBOTTOM+$GUI_DOCKWIDTH)


; So, nun brauchen wir pro Zielverzeichnis: 1x Button kopieren, 1x Button verschieben, 1x Input mit dem Pfad, 1x Input zur Pfadauswahl
; das machen wir natürlich mit einem Array das wie folgt aussieht:
; $a_id_TargetDirectories[2][5]	; [0][0] = Anzahl
								; [x][1] = Button kopieren
								; [x][2] = Butten verschieben
								; [x][3] = Input
								; [x][4] = Pfadauswahl
; Eine Zeile gibt es immer!
$a_id_TargetDirectories[0][0] = 1

; Den Button für kopieren
$a_id_TargetDirectories[1][1] = GUICtrlCreateButton("1", 536, 200, 33, 25)
GUICtrlSetOnEvent($a_id_TargetDirectories[1][1], "_Picture_Copy")
; Diesen und die nachfolgenden Buttons heften wir Rechts und oben an, Größe ist fix
GUICtrlSetResizing($a_id_TargetDirectories[1][1], $GUI_DOCKRIGHT+$GUI_DOCKTOP+$GUI_DOCKWIDTH+$GUI_DOCKHEIGHT)
GUICtrlSetTip($a_id_TargetDirectories[1][1], "Datei kopieren")

; Den Button für verschieben
$a_id_TargetDirectories[1][2] = GUICtrlCreateButton("»", 568, 200, 33, 25)
GUICtrlSetOnEvent($a_id_TargetDirectories[1][2], "_Picture_Move")
GUICtrlSetResizing($a_id_TargetDirectories[1][2], $GUI_DOCKRIGHT+$GUI_DOCKTOP+$GUI_DOCKWIDTH+$GUI_DOCKHEIGHT)
GUICtrlSetTip($a_id_TargetDirectories[1][2], "Datei verschieben")

; Das Input mit dem Pfad
$a_id_TargetDirectories[1][3] = GUICtrlCreateInput("", 603, 200, 354, 25, BitOR($ES_READONLY,$ES_LEFT, $ES_AUTOHSCROLL), BitOR($WS_EX_CLIENTEDGE, $WS_EX_ACCEPTFILES))
GUICtrlSetFont($a_id_TargetDirectories[1][3], 11, 400, 0, "Arial")
GUICtrlSetBkColor($a_id_TargetDirectories[1][3], 0xFFFFE1)
GUICtrlSetResizing($a_id_TargetDirectories[1][3], $GUI_DOCKRIGHT+$GUI_DOCKTOP+$GUI_DOCKWIDTH+$GUI_DOCKHEIGHT)
; Damit das Feld Drag'n Drop annimmt (muss zusätzlich zum Extended-Style gesetzt werden)
GUICtrlSetState($a_id_TargetDirectories[1][3], $GUI_DROPACCEPTED)

; Und noch der Button für die Pfadauswahl
$a_id_TargetDirectories[1][4] = GUICtrlCreateButton("...", 960, 200, 33, 25)
GUICtrlSetOnEvent($a_id_TargetDirectories[1][4], "_Folder_Select")
GUICtrlSetResizing($a_id_TargetDirectories[1][4], $GUI_DOCKRIGHT+$GUI_DOCKTOP+$GUI_DOCKWIDTH+$GUI_DOCKHEIGHT)
GUICtrlSetTip($a_id_TargetDirectories[1][4], "Pfad wählen")

; Unterhalb der Zeile kommen noch 2 Buttons für das Hinzufügen und Entfernen weiterer Zeilen hinzu
$id_ButtonAddTargetDirectory = GUICtrlCreateButton("+", 536, 232, 33, 25)
GUICtrlSetOnEvent($id_ButtonAddTargetDirectory, "_Folder_Add")
GUICtrlSetResizing($id_ButtonAddTargetDirectory, $GUI_DOCKRIGHT+$GUI_DOCKTOP+$GUI_DOCKWIDTH+$GUI_DOCKHEIGHT)
GUICtrlSetTip($id_ButtonAddTargetDirectory, "Einen Pfad hinzufügen")
$id_ButtonRemoveTargetDirectory = GUICtrlCreateButton("-", 568, 232, 33, 25)
GUICtrlSetOnEvent($id_ButtonRemoveTargetDirectory, "_Folder_Remove")
GUICtrlSetResizing($id_ButtonRemoveTargetDirectory, $GUI_DOCKRIGHT+$GUI_DOCKTOP+$GUI_DOCKWIDTH+$GUI_DOCKHEIGHT)
GUICtrlSetTip($id_ButtonRemoveTargetDirectory, "Den vorstehenden Pfad entfernen")
; - wird deaktiviert, haben im Moment ja nur eine Zeile
GUICtrlSetState($id_ButtonRemoveTargetDirectory, $GUI_DISABLE)

; Und auch diese Gruppe ist fertig
GUICtrlCreateGroup("", -99, -99, 1, 1)


; Die Gruppe mit den Optionen für doppelte / schon vorhandene Dateien
$id_GroupFileExists = GUICtrlCreateGroup(" Datei bereits vorhanden ", 528, 80, 473, 90)
GUICtrlSetResizing($id_GroupFileExists, $GUI_DOCKRIGHT+$GUI_DOCKTOP+$GUI_DOCKWIDTH+$GUI_DOCKHEIGHT)
$id_RadioOverwrite = GUICtrlCreateRadio("vorhandene Datei überschreiben", 536, 100, 241, 17)
GUICtrlSetResizing($id_RadioOverwrite, $GUI_DOCKRIGHT+$GUI_DOCKTOP+$GUI_DOCKWIDTH+$GUI_DOCKHEIGHT)
$id_RadioAddSuffix = GUICtrlCreateRadio("Suffix anhängen:", 536, 124, 137, 17)
GUICtrlSetState($id_RadioAddSuffix, $GUI_CHECKED)
GUICtrlSetResizing($id_RadioAddSuffix, $GUI_DOCKRIGHT+$GUI_DOCKTOP+$GUI_DOCKWIDTH+$GUI_DOCKHEIGHT)
$id_InputSuffix = GUICtrlCreateInput("_####", 674, 120, 89, 25, BitOR($GUI_SS_DEFAULT_INPUT,$ES_CENTER))
GUICtrlSetFont($id_InputSuffix, 11, 400, 0, "Arial")
GUICtrlSetResizing($id_InputSuffix, $GUI_DOCKRIGHT+$GUI_DOCKTOP+$GUI_DOCKWIDTH+$GUI_DOCKHEIGHT)
$id_RadioAskOverwrite = GUICtrlCreateRadio("Nachfragen", 536, 148, 241, 17)
GUICtrlSetResizing($id_RadioAskOverwrite, $GUI_DOCKRIGHT+$GUI_DOCKTOP+$GUI_DOCKWIDTH+$GUI_DOCKHEIGHT)
$id_CheckboxOnlyIfDifferent = GUICtrlCreateCheckbox("Nur wenn nicht identisch", 784, 100, 209, 17)
GUICtrlSetState($id_CheckboxOnlyIfDifferent, $GUI_CHECKED)
GUICtrlSetResizing($id_CheckboxOnlyIfDifferent, $GUI_DOCKRIGHT+$GUI_DOCKTOP+$GUI_DOCKWIDTH+$GUI_DOCKHEIGHT)
$id_LabelCountingNumber = GUICtrlCreateLabel("# = laufende Nummer", 784, 124, 146, 20)
GUICtrlSetResizing($id_LabelCountingNumber, $GUI_DOCKRIGHT+$GUI_DOCKTOP+$GUI_DOCKWIDTH+$GUI_DOCKHEIGHT)
GUICtrlCreateGroup("", -99, -99, 1, 1)


Global $a_id_Tools[8][2] = [ [ "DEL", 0 ], [ "ROT", 0 ], [ "FOLD", 0 ], [ "D", 0 ], [ "E", 0 ], [ "F", 0 ], [ "G", 0 ], [ "BKG", 0 ] ]

; Die Gruppe mit den Werkzeugen
$id_GroupTools = GUICtrlCreateGroup(" Werkzeuge ", 528, 624, 473, 76)
GUICtrlSetResizing($id_GroupTools, $GUI_DOCKRIGHT+$GUI_DOCKBOTTOM+$GUI_DOCKWIDTH+$GUI_DOCKHEIGHT)
; Und die Buttons selbst - sind noch ein paar zuviel in Reserve
For $i = 0 To (UBound($a_id_Tools) - 1) Step 1
	$a_id_Tools[$i][1] = GUICtrlCreateButton($a_id_Tools[$i][0], 536 + ($i * 58), 644, 48, 48)
	GUICtrlSetResizing($a_id_Tools[$i][1], $GUI_DOCKRIGHT+$GUI_DOCKBOTTOM+$GUI_DOCKWIDTH+$GUI_DOCKHEIGHT)
	GUICtrlSetOnEvent($a_id_Tools[$i][1], "_Tools")
Next
; Und die Gruppe ist fertig
GUICtrlCreateGroup("", -99, -99, 1, 1)

; Die Schaltflächen für vor / zurück etc. + das Input
$id_ButtonPicGoToFirst = GUICtrlCreateButton("Start", 5, 640, 50, 25)
GUICtrlSetResizing($id_ButtonPicGoToFirst, $GUI_DOCKLEFT+$GUI_DOCKBOTTOM+$GUI_DOCKWIDTH+$GUI_DOCKHEIGHT)
$id_ButtonPicBack100 = GUICtrlCreateButton("-100", 60, 640, 50, 25)
GUICtrlSetResizing($id_ButtonPicBack100, $GUI_DOCKLEFT+$GUI_DOCKBOTTOM+$GUI_DOCKWIDTH+$GUI_DOCKHEIGHT)
$id_ButtonPicBack10 = GUICtrlCreateButton("-10", 115, 640, 50, 25)
GUICtrlSetResizing($id_ButtonPicBack10, $GUI_DOCKLEFT+$GUI_DOCKBOTTOM+$GUI_DOCKWIDTH+$GUI_DOCKHEIGHT)
$id_ButtonPicBack1 = GUICtrlCreateButton("<", 170, 640, 50, 25)
GUICtrlSetResizing($id_ButtonPicBack1, $GUI_DOCKLEFT+$GUI_DOCKBOTTOM+$GUI_DOCKWIDTH+$GUI_DOCKHEIGHT)
$id_InputPicNumber = GUICtrlCreateInput("9999", 225, 640, 75, 25, BitOR($GUI_SS_DEFAULT_INPUT,$ES_CENTER))
GUICtrlSetFont($id_InputPicNumber, 11, 400, 0, "Arial")
GUICtrlSetResizing($id_InputPicNumber, $GUI_DOCKLEFT+$GUI_DOCKRIGHT+$GUI_DOCKBOTTOM+$GUI_DOCKHEIGHT)
$id_ButtonForward1 = GUICtrlCreateButton(">", 305, 640, 50, 25)
GUICtrlSetResizing($id_ButtonForward1, $GUI_DOCKRIGHT+$GUI_DOCKBOTTOM+$GUI_DOCKWIDTH+$GUI_DOCKHEIGHT)
$id_ButtonForward10 = GUICtrlCreateButton("+10", 360, 640, 50, 25)
GUICtrlSetResizing($id_ButtonForward10, $GUI_DOCKRIGHT+$GUI_DOCKBOTTOM+$GUI_DOCKWIDTH+$GUI_DOCKHEIGHT)
$id_ButtonForward100 = GUICtrlCreateButton("+100", 415, 640, 50, 25)
GUICtrlSetResizing($id_ButtonForward100, $GUI_DOCKRIGHT+$GUI_DOCKBOTTOM+$GUI_DOCKWIDTH+$GUI_DOCKHEIGHT)
$id_ButtonGoToLast = GUICtrlCreateButton("Ende", 470, 640, 50, 25)
GUICtrlSetResizing($id_ButtonGoToLast, $GUI_DOCKRIGHT+$GUI_DOCKBOTTOM+$GUI_DOCKWIDTH+$GUI_DOCKHEIGHT)
$id_CheckboxPictureFitSize = GUICtrlCreateCheckbox("Größe anpassen", 5, 685, 137, 17)
GUICtrlSetState($id_CheckboxPictureFitSize, $GUI_CHECKED)
GUICtrlSetResizing($id_CheckboxPictureFitSize, $GUI_DOCKLEFT+$GUI_DOCKBOTTOM+$GUI_DOCKWIDTH+$GUI_DOCKHEIGHT)


GUISetState(@SW_SHOW, $h_FormFotoSortNeu)
; Platzhalter für die Vorschaugrafik
;~ $id_Picture = GUICtrlCreatePic( @ScriptDir & "\Test.jpg", 5, 88, 514, 530)
;~ GUICtrlSetResizing($id_Picture, $GUI_DOCKLEFT+$GUI_DOCKRIGHT+$GUI_DOCKTOP+$GUI_DOCKBOTTOM)

; Die Vorschau-Grafik. Stammt nahezu 1:1 aus Oscars Original
$a_FormFotoSortNew_Size = WinGetPos($h_FormFotoSortNeu)
WinMove($h_FormFotoSortNeu, "", 0, 0, @DesktopWidth, @DesktopHeight)
$h_Graphic = _GDIPlus_GraphicsCreateFromHWND($h_FormFotoSortNeu)
WinMove($h_FormFotoSortNeu, "", $a_FormFotoSortNew_Size[0], $a_FormFotoSortNew_Size[1], $a_FormFotoSortNew_Size[2], $a_FormFotoSortNew_Size[3])
_GDIPlus_GraphicsSetSmoothingMode($h_Graphic, 2)

$h_Bitmap = _GDIPlus_BitmapCreateFromGraphics($i_GuiWidth, $i_GuiHeight, $h_Graphic)
;~ $h_Bitmap = _GDIPlus_BitmapCreateFromGraphics(@DesktopWidth, @DesktopHeight, $h_Graphic)
$h_GraphicBuff = _GDIPlus_ImageGetGraphicsContext($h_Bitmap)
$i_BgColor = 0

$a_h_Brush[0] = _GDIPlus_BrushCreateSolid(0xFFECECEC)
$a_h_Brush[1] = _GDIPlus_BrushCreateSolid(0xFFDFDFDF)
$a_h_Brush[2] = _GDIPlus_BrushCreateSolid(0xFF000000)
$a_h_Brush[3] = _GDIPlus_BrushCreateSolid(0xFFFFFFFF)
$h_Texture = _CreatePatternTexture($i_PreviewLeft, $i_PreviewTop, $i_PreviewWidth, $i_PreviewHeight)

_GDIPlus_GraphicsDrawRect($h_GraphicBuff, $i_PreviewLeft - 2, $i_PreviewTop - 2, $i_PreviewWidth + 3, $i_PreviewHeight + 3)
_GDIPlus_GraphicsDrawRect($h_GraphicBuff, $i_PreviewLeft - 1, $i_PreviewTop - 1, $i_PreviewWidth + 1, $i_PreviewHeight + 1)
_DrawBgColor($i_PreviewLeft, $i_PreviewTop, $i_PreviewWidth, $i_PreviewHeight)
_GDIPlus_GraphicsDrawImage($h_Graphic, $h_Bitmap, 0, 0)
WinMove($h_FormFotoSortNeu, "", $a_FormFotoSortNew_Size[0], $a_FormFotoSortNew_Size[1], $a_FormFotoSortNew_Size[2], $a_FormFotoSortNew_Size[3])

; Kümmert sich um das Zeichnen/Refresh der Vorschau
GUIRegisterMsg($WM_PAINT, 'WM_PAINT')









#EndRegion GUI-FormFotoSortNeu


#Region Startup
; ###############################################################################################################################################################################################
;    ######  ########    ###    ########  ######## ##     ## ########
;   ##    ##    ##      ## ##   ##     ##    ##    ##     ## ##     ##
;   ##          ##     ##   ##  ##     ##    ##    ##     ## ##     ##
;    ######     ##    ##     ## ########     ##    ##     ## ########
;         ##    ##    ######### ##   ##      ##    ##     ## ##
;   ##    ##    ##    ##     ## ##    ##     ##    ##     ## ##
;    ######     ##    ##     ## ##     ##    ##     #######  ##
; ###############################################################################################################################################################################################


; Die Statusbar ist nicht wie die anderen Controls an den Rändern "angeklebt".
; Wir müssen nach jeder Größenanderung eine Funktion aufrufen welche die Statusbar wieder anpasst
GUIRegisterMsg($WM_SIZE, "WM_SIZE")


; Die GUI soll einen minimale Größe von 1024 x 768 nicht unterschreiten.
; Die Lösung:
; 1. Wir holen uns die Anfangsgröße (sollte 1024 x 768 sein, Bei GUICreate steht die Größe der inneren Nutzfläche)
$a_FormFotoSortNew_Size = WinGetPos($h_FormFotoSortNeu)
; 2. Wir setzen die erlaubten minimal und maximal Werte
$i_FormFotoSortNew_SizeMinWidth = $a_FormFotoSortNew_Size[2]
$i_FormFotoSortNew_SizeMinHeight = $a_FormFotoSortNew_Size[3]
; Als maximale Werte nehmen wir die des Desktops
$i_FormFotoSortNew_SizeMaxWidth = @DesktopWidth
$i_FormFotoSortNew_SizeMaxHeight = @DesktopHeight
; 3. Wir registrieren eine Funktion welche dafür sorgt das die Grenzwerte eingehalten werden, diese wird von Windows/AutoIt automatisch aufgerufen
GUIRegisterMsg($WM_GETMINMAXINFO, "WM_GETMINMAXINFO")


; Funktion Registrieren die reagiert wenn per Drag'n Drop eine Datei auf die GUI gezogen wird
GUISetOnEvent($GUI_EVENT_DROPPED, "GUI_EVENT_DROPPED", $h_FormFotoSortNeu)
#EndRegion Startup
#Region Main
; ###############################################################################################################################################################################################
;   ##     ##    ###    ##     ## ########  ########  ######   ######  ##     ## ##       ######## #### ######## ########
;   ##     ##   ## ##   ##     ## ##     ##    ##    ##    ## ##    ## ##     ## ##       ##        ##  ##       ##
;   ##     ##  ##   ##  ##     ## ##     ##    ##    ##       ##       ##     ## ##       ##        ##  ##       ##
;   ######### ##     ## ##     ## ########     ##     ######  ##       ######### ##       ######    ##  ######   ######
;   ##     ## ######### ##     ## ##           ##          ## ##       ##     ## ##       ##        ##  ##       ##
;   ##     ## ##     ## ##     ## ##           ##    ##    ## ##    ## ##     ## ##       ##        ##  ##       ##
;   ##     ## ##     ##  #######  ##           ##     ######   ######  ##     ## ######## ######## #### ##       ########
; ###############################################################################################################################################################################################
While 1
	Sleep(100)
WEnd
#EndRegion Main