
; ===============================================================
; == Registrieren im Kontextmenü des Explorers für alle Dateien
; == Schlüssel:		HKEY_CLASSES_ROOT\*\shell\CMD
; == Wert:			(Standard) = "Name_des_Menüeintrages"
; == Schlüssel:		HKEY_CLASSES_ROOT\*\shell\CMD\COMMAND
; == Wert:			(Standard) = "Pfad_zum_kompilierten_Skript"
; ===============================================================

#Region - TimeStamp
; 2011-09-11 13:37:20   v 1.0
#EndRegion - TimeStamp
#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>
#Include <Misc.au3>

 _Singleton(@ScriptName) ; == sonst erfolgt Skriptaufruf für jede markierte Datei

Opt('GUIOnEventMode', 1)
Local $aDeskSize[2] = [@DesktopWidth,@DesktopHeight]
Local $aMPos = MouseGetPos()
Local $x = $aMPos[0], $y = $aMPos[1]
Local $iWGUI = 120, $iHGUI = 85
If $x + $iWGUI > $aDeskSize[0] Then
	$x = $aDeskSize[0] - $iWGUI
EndIf
If $y + $iHGUI > $aDeskSize[1] Then
	$y = $aDeskSize[1] - $iHGUI
EndIf
Local $GUI = GUICreate('', $iWGUI, $iHGUI, $x, $y, BitOR($WS_POPUP,$WS_BORDER))
GUISetOnEvent($GUI_EVENT_CLOSE, '_close')
Local $cLV = GuiCtrlCreateListView('LV', 0, 0, $iWGUI, $iHGUI, BitOR($LVS_NOCOLUMNHEADER,$LVS_SINGLESEL), BitOR($LVS_EX_GRIDLINES,$LVS_EX_FULLROWSELECT))
_GUICtrlListView_SetColumnWidth(GUICtrlGetHandle($cLV), 0, $LVSCW_AUTOSIZE_USEHEADER)
Local $cFull = GUICtrlCreateListViewItem('kpl. Dateipfade', $cLV)
GUICtrlSetOnEvent(-1, '_OnClick')
Local $cFile = GUICtrlCreateListViewItem('Dateinamen', $cLV)
GUICtrlSetOnEvent(-1, '_OnClick')
Local $cPath = GUICtrlCreateListViewItem('Pfadname', $cLV)
GUICtrlSetOnEvent(-1, '_OnClick')
Local $cSize = GUICtrlCreateListViewItem('Dateigrößen', $cLV)
GUICtrlSetOnEvent(-1, '_OnClick')

; == Markierte Datei(en) auslesen
Global $aSelected = _ActiveExplorer_GetFilesSelected()
Switch $aSelected[0]
	Case 0
		Exit MsgBox(0, 'Achtung', 'Keine Datei ausgewählt im Ordner' & @CRLF & $aSelected[1])
	Case 1
		GUICtrlSetData($cFull, 'kpl. Dateipfad')
		GUICtrlSetData($cFile, 'Dateiname')
		GUICtrlSetData($cSize, 'Dateigröße')
EndSwitch

GUISetState()

While 1
	Sleep(50)
WEnd

Func _close()
	Exit
EndFunc

Func _OnClick()
	Local $sRet = ''
	Switch @GUI_CtrlId
		Case $cFull
			For $i = 2 To $aSelected[0]+1
				$sRet &= $aSelected[1] & '\' & $aSelected[$i] & @CRLF
			Next
		Case $cFile
			For $i = 2 To $aSelected[0]+1
				$sRet &= $aSelected[$i] & @CRLF
			Next
		Case $cPath
			$sRet = $aSelected[1]
		Case $cSize
			For $i = 2 To $aSelected[0]+1
				Local $iSize = FileGetSize($aSelected[1] & '\' & $aSelected[$i])
				$sRet &= $aSelected[$i] & @TAB & $iSize & @CRLF
			Next
	EndSwitch
	ClipPut($sRet)
	_close()
EndFunc

;===============================================================================
; Function Name....: _ActiveExplorer_GetFilesSelected
; Description......: Erstellt ein Array mit
;                    - Anzahl der markierten Dateien
;                    - dem Pfad des aktiven Explorerfensters und
;                    - dem/den Pfad/en der markiert/en Datei/en
; Parameter(s).....: keine
; Requirement(s)...: offenes Explorerfenster
; Return Value(s)..: Array mit den Daten, $a[0] = Anzahl, $a[1] = Ordnerpfad, $a[2..] = Dateiname
; Author(s)........: BugFix ( bugfix@autoit.de )
;===============================================================================
Func _ActiveExplorer_GetFilesSelected()
	Local $oShell = ObjCreate("Shell.Application")
	Local $oExplorer, $sPath, $oFolderView, $iCount, $n = 2
	For $i = 0 To $oShell.Windows.Count - 1
		$oExplorer = $oShell.Windows($i)
		$sPath = StringReplace(StringReplace(StringTrimLeft($oExplorer.LocationURL, 8), '%20', ' '), '/', '\')
		If WinGetTitle('[ACTIVE]') = $sPath Then ExitLoop
	Next
	$oFolderView = $oExplorer.Document.SelectedItems()
	$iCount = $oFolderView.Count
	Local $aOut[$iCount +2]
	$aOut[0] = $iCount
	$aOut[1] = $sPath
	If $iCount = 0 Then
		ReDim $aOut[3]
		$aOut[2] = 'NO FILE SELECT'
	Else
		For $oFolderItem In $oFolderView
			$aOut[$n] = $oFolderItem.Name
			$n += 1
		Next
	EndIf
	Return $aOut
EndFunc  ; ==>_ActiveExplorer_GetFilesSelected