Hallochen allerseits, ist es möglich den Pfad einer bereits im Windowsexplorer markierten Datei in einer Variablen zu speichern? Also ohne "FileOpenDialog" zu verwenden?
Danke
Stefan
Hallochen allerseits, ist es möglich den Pfad einer bereits im Windowsexplorer markierten Datei in einer Variablen zu speichern? Also ohne "FileOpenDialog" zu verwenden?
Danke
Stefan
Habe ich vor langer Zeit mal erstellt:
;===============================================================================
; Function Name....: _ActiveExplorer_GetSelected
; Description......: Erstellt ein Array mit
; - Anzahl der markierten Dateien/Ordner
; - dem Pfad des aktiven Explorerfensters und
; - dem/den Pfad/en der markiert/en Datei/en /Ordner
; Parameter(s).....: keine
; Requirement(s)...: offenes Explorerfenster
; Return Value(s)..: Array mit den Daten, $a[0] = Anzahl, $a[1] = Ordnerpfad, $a[2..] = Datei/Ordnername
; .................: ACHTUNG! Letzter Index somit $a[0]+1 !!
; Author(s)........: BugFix ( bugfix@autoit.de )
;===============================================================================
;===============================================================================
; Function Name....: _ActiveExplorer_GetSelected
; Description......: Creates an array with
; - Count of selected files/folder
; - Path of active Explorer window and
; - the path/es of selected file/s /folder
; Requirement(s)...: Opened Explorer window
; Return Value(s)..: Array with data, $a[0] = Count, $a[1] = Folderpath, $a[2..] = File/Foldername
; .................: ATTENTION! Last index $a[0]+1 !!
; Author(s)........: BugFix ( AutoIt@bug-fix.info )
;===============================================================================
Func _ActiveExplorer_GetSelected()
Local $oShell = ObjCreate("Shell.Application")
Local $oExplorer, $sPath, $oFolderView, $iCount = 0, $sSelectedFiles = '', $n = 2
Local $oShellWindows = $oShell.Windows
For $i = 0 To $oShellWindows.Count -1
$oExplorer = $oShellWindows($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
Return ''
Else
For $oFolderItem In $oFolderView
$aOut[$n] = $oFolderItem.Name
$n += 1
Next
Return $aOut
EndIf
EndFunc ; ==>_ActiveExplorer_GetSelected
Alles anzeigen
Danke, schau ich morgen an...
Stefan
Danke, schau ich morgen an...
Stefan
Bitte beachten:
Diese Funktion setzt voraus, dass der Datei Explorer im Moment der Abfrage das aktive Fenster ist. Den Aufruf müsstest Du dann z. B. auf einen Hotkey legen in einem AutoIt Skript, das im Hintergrund dümpelt.
...und ich bin begeistert.... in D-Opus ->neue Symbolleiste einfügen ->Schalter anlegen -> mit *.exe verknüpfen -> fertig und läuft
ein schönes Wochenende
Stefan
Bitte beachten:
Diese Funktion setzt voraus, dass der Datei Explorer im Moment der Abfrage das aktive Fenster ist. Den Aufruf müsstest Du dann z. B. auf einen Hotkey legen in einem AutoIt Skript, das im Hintergrund dümpelt.
Hier mal noch eine Version, in der der Datei-Explorer nicht aktiv sein muss! Es wird das topmost Explorerfenster verwendet:
EDIT: Eine Besonderheit von Windows muss man aber selbst beachten. Hat man im Explorerfenster im Tree einen Bibliotheksnamen ausgewählt, liefert Windows nicht den Speicherpfad, da es sich hier um eine Verlinkung handelt. Man bekommt stattdessen einen Leerstring. Hat man die Standardoption mit Ordneranzeige gewählt, erhält man dann einen Backslash und Dateinamen. Wählt man jedoch im Tree den unterhalb des Bibliotheksnamens stehenden Ordner, läuft alles wie gewollt.
; #FUNCTION# ====================================================================================================================
; Name ..........: _GetSelectionFromTopMostExplorer
; Description ...: Gets an array with selected files from the top most explorer window
; Syntax ........: _GetSelectionFromTopMostExplorer([$_bDir = True])
; Parameters ....: $_bDir - [optional] Returns the full path (Default 'True'). With 'False' will only the filename returned.
; Return values .: Array with selected files. Counter at $ar[0]
; Requires.......: _GetTopmostHwndFromProcess()
; Author ........: BugFix
; ===============================================================================================================================
Func _GetSelectionFromTopMostExplorer($_bDir=True)
Local $oShell = ObjCreate("Shell.Application")
Local $oIE, $sPath = '', $oShellWindows = $oShell.Windows
Local $oDoc, $bIE = False, $oFV
For $i = 0 To $oShellWindows.Count -1 ; all opened explorer and internet explorer windows
$oIE = $oShellWindows($i)
$oDoc = $oIE.Document
If _GetTopmostHwndFromProcess('explorer.exe', 'CabinetWClass') = $oIE.Hwnd Then
If StringRegExp(ObjName($oDoc), "IShellFolderViewDual.") Then ; be sure it's the explorer object
$sPath =StringReplace(StringReplace(StringTrimLeft($oIE.LocationURL, 8), '%20', ' '), '/', '\') ; extract windows path from file-url
$bIE = True ; flag: found explorer
EndIf
EndIf
Next
Local $aSelection[500] = [0]
If $bIE Then
$oFV = $oIE.Document ; File-Browser (ShellFolderView)
If Not $_bDir Then $sPath = ''
For $oFI In $oFV.SelectedItems ; selected elements there
$aSelection[0] += 1
If $aSelection[0] > UBound($aSelection) Then ReDim $aSelection[UBound($aSelection) +500]
$aSelection[$aSelection[0]] = StringFormat('%s%s%s', $sPath, ($_bDir ? '\' : ''), $oFI.Name)
Next
EndIf
If $aSelection[0] = 0 Then
ReDim $aSelection[1]
Else
ReDim $aSelection[$aSelection[0]+1]
EndIf
Return $aSelection
EndFunc ;==>_GetSelectionFromTopMostExplorer
; #FUNCTION# ====================================================================================================================
; Name ..........: _GetTopmostHwndFromProcess
; Description ...: Returns the handle of the top most window of a specific process
; Syntax ........: _GetTopmostHwndFromProcess($_vProcess)
; Parameters ....: $_vProcess The Process name or PID
; $_sClass The classname of windows that will created by the specific process
; Return values .: Success The handle of the top most window
; Failure 0, set @error = 1 (process does not exists)
; @error = 2 (there is no window for this)
; Author ........: BugFix
; ===============================================================================================================================
Func _GetTopmostHwndFromProcess($_vProcess, $_sClass)
Local $aProc[2][2] = [[1],['',$_vProcess]]
If IsString($_vProcess) Then
$aProc = ProcessList($_vProcess)
If $aProc[0][0] = 0 Then
Return SetError(1,0,0)
EndIf
Else
If Not ProcessExists($_vProcess) Then Return SetError(1,0,0)
EndIf
Local $hWnd = 0, $aWin = WinList('[CLASS:' & $_sClass & ']')
If $aWin[0][0] = 0 Then Return SetError(2,0,0)
Local $tPID = DllStructCreate("int PID")
; check only the first window, has highest z-order
For $i = 1 To $aProc[0][0]
DllCall("user32.dll", "int", "GetWindowThreadProcessId", "hwnd", $aWin[1][1], "ptr", DllStructGetPtr($tPID))
If $tPID.PID = $aProc[$i][1] Then Return $aWin[1][1]
Next
Return 0
EndFunc ;==>_GetTopmostHwndFromProcess
Alles anzeigen
Nachtrag:
In der Version im vorigen Post hatte ich die Reihenfolge der Fenster aus WinList ausgelesen, musste nun aber feststellen, dass WinList diese Liste ungeordnet erstellt. Somit wurde bei gleicher Klasse immer auf das zuerst erstellte Fenster zugegriffen.
Habe ich in dieser Version korrigiert. Zusätzlich noch einen Fehler beim Auslesen aus Rootlaufwerken (Backslash wurde als Pfad mit übernommen).
#include <WinAPIProc.au3>
#include <WinAPISys.au3>
#cs
#include <Array.au3>
$aTest = _GetSelectionFromTopMostExplorer()
_ArrayDisplay($aTest)
$aTest = _GetSelectionFromTopMostExplorer(False)
_ArrayDisplay($aTest)
#ce
; #FUNCTION# ====================================================================================================================
; Name ..........: _GetSelectionFromTopMostExplorer
; Description ...: Gets an array with selected files from the top most explorer window
; Syntax ........: _GetSelectionFromTopMostExplorer([$_bDir = True])
; Parameters ....: $_bDir - [optional] Returns the full path (Default 'True'). With 'False' will only the filename returned.
; Return values .: Array with selected files. Counter at $ar[0]
; Requires.......: _GetTopmostHwndFromProcess()
; Author ........: BugFix
; ===============================================================================================================================
Func _GetSelectionFromTopMostExplorer($_bDir=True)
Local $oShell = ObjCreate("Shell.Application")
Local $oIE, $sPath = '', $oShellWindows = $oShell.Windows
Local $oDoc, $bIE = False, $oFV
For $i = 0 To $oShellWindows.Count -1 ; all opened explorer and internet explorer windows
$oIE = $oShellWindows($i)
$oDoc = $oIE.Document
If _GetTopmostHwndFromProcess('explorer.exe', 'CabinetWClass') = $oIE.Hwnd Then
If StringRegExp(ObjName($oDoc), "IShellFolderViewDual.") Then ; be sure it's the explorer object
$sPath = StringReplace(StringReplace(StringTrimLeft($oIE.LocationURL, 8), '%20', ' '), '/', '\') ; extract windows path from file-url
$sPath = StringRegExpReplace($sPath, '(\\)$', '') ; "C:\" --> "C:"
$bIE = True ; flag: found explorer
EndIf
EndIf
Next
Local $aSelection[500] = [0]
If $bIE Then
$oFV = $oIE.Document ; File-Browser (ShellFolderView)
If Not $_bDir Then $sPath = ''
For $oFI In $oFV.SelectedItems ; selected elements there
$aSelection[0] += 1
If $aSelection[0] > UBound($aSelection) Then ReDim $aSelection[UBound($aSelection) +500]
$aSelection[$aSelection[0]] = StringFormat('%s%s%s', $sPath, ($_bDir ? '\' : ''), $oFI.Name)
Next
EndIf
If $aSelection[0] = 0 Then
ReDim $aSelection[1]
Else
ReDim $aSelection[$aSelection[0]+1]
EndIf
Return $aSelection
EndFunc ;==>_GetSelectionFromTopMostExplorer
; #FUNCTION# ====================================================================================================================
; Name ..........: _GetTopmostHwndFromProcess
; Description ...: Returns the handle of the top most window of a specific process
; Syntax ........: _GetTopmostHwndFromProcess($_vProcess)
; Parameters ....: $_vProcess The Process name or PID
; $_sClass The classname of windows that will created by the specific process
; Return values .: Success The handle of the top most window
; Failure 0, set @error = 1 (process does not exists)
; @error = 2 (there is no window for this)
; Author ........: BugFix
; ===============================================================================================================================
Func _GetTopmostHwndFromProcess($_vProcess, $_sClass)
Local $aProc[2][2] = [[1],['',$_vProcess]]
If IsString($_vProcess) Then
$aProc = ProcessList($_vProcess)
If $aProc[0][0] = 0 Then
Return SetError(1,0,0)
EndIf
Else
If Not ProcessExists($_vProcess) Then Return SetError(1,0,0)
EndIf
; get the highest z-order
Local $hWnd = 0, $aWin = _WinAPI_EnumDesktopWindows(_WinAPI_GetThreadDesktop(_WinAPI_GetCurrentThreadId()), False)
For $i = 1 To $aWin[0][0]
If $aWin[$i][1] = $_sClass Then ; first found window of this class has the highest z-order
$hWnd = $aWin[$i][0]
ExitLoop
EndIf
Next
If $hWnd = 0 Then Return SetError(2,0,0)
Local $tPID = DllStructCreate("int PID")
For $i = 1 To $aProc[0][0]
DllCall("user32.dll", "int", "GetWindowThreadProcessId", "hwnd", $hWnd, "ptr", DllStructGetPtr($tPID))
If $tPID.PID = $aProc[$i][1] Then Return $hWnd
Next
Return 0
EndFunc ;==>_GetTopmostHwndFromProcess
Alles anzeigen