ineedh3lp Posted December 22, 2011 Posted December 22, 2011 I understand. Is there any way to adapt it to other file managers by passing a different classname to ObjCreate? I would appreciate any tip that would lead to a solution. Thank you!
KaFu Posted December 22, 2011 Posted December 22, 2011 No, if at all (meaning the other file manager providing an object interface) this had to be build from the scratch. Better take a look at the ControlListView(), _GUICtrlListView_* ,ControlTreeView() and _GUICtrlTreeView_* functions in the help-files. Use the AU3Info to determine the control classes and go on from there. OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2024-Oct-13) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Oct-13) HMW - Hide my Windows (2024-Oct-19) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2024-Oct-20) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16)
ineedh3lp Posted December 22, 2011 Posted December 22, 2011 ControlListView() is what I need. Thank you for pointing me in the right direction, KaFoo!
ZGorlock Posted March 25, 2012 Posted March 25, 2012 Hello, I am new to this forum and am only here because of this threads relativity to a question I have been trying to get answered. How do I return the local address or addresses of the object or objects currently highlighted in Windows Explorer as a string or array? I am trying to get a program that I am writing to be able to get the locations of what is highlighted upon request. I have the MSDN at my disposal if it is needed. Thanks in advance
subzerostig Posted March 25, 2012 Posted March 25, 2012 Nice script, will probs come in handy(Like if I want to block access to the C: drive) There are 10 types of people in this world. Those that understand binary, and those that do not
Moderators Melba23 Posted March 25, 2012 Moderators Posted March 25, 2012 ZGorlock, Welcome to the AutoIt forum. Using Ascend4nt's code from post #35 you can get the selected items in string or array form like this: expandcollapse popup#include <Array.au3> Local $oErrorHandler = ObjEvent("AutoIt.Error", "_ComErrFunc") $aWinList=WinList("[REGEXPCLASS:^(Explore|Cabinet)WClass$]") For $i = 1 To $aWinList[0][0] ; Get base folder and selections $aSelection = _ExplorerWinGetSelectedItems($aWinList[$i][1]) ; Display as strings ConsoleWrite("Explorer Window: " & $aSelection[1] & " Selection(s)" & @CRLF) For $j = 2 To $aSelection[0] + 1 ConsoleWrite(@TAB & $aSelection[$j] & @CRLF) Next ; Display as array _ArrayDisplay($aSelection, "Explorer Instance #" & $i & " / " & $aWinList[$i][0]) Next ; ========================================================================================================================== ; Func _ObjectSHFolderViewFromWin($hWnd) ; ; Returns an 'ShellFolderView' Object for the given Window handle ; ; Author: Ascend4nt, based on code by KaFu, klaus.s ; ========================================================================================================================== Func _ObjectSHFolderViewFromWin($hWnd) If Not IsHWnd($hWnd) Then Return SetError(1,0,0) Local $oShell,$oShellWindows,$oIEObject,$oSHFolderView ; Shell Object $oShell=ObjCreate("Shell.Application") If Not IsObj($oShell) Then Return SetError(2,0,0) ; Get a 'ShellWindows Collection' object $oShellWindows = $oShell.Windows() If Not IsObj($oShellWindows) Then Return SetError(3,0,0) ; Iterate through the collection - each of type 'InternetExplorer' Object For $oIEObject In $oShellWindows If $oIEObject.HWND = $hWnd Then ; InternetExplorer->Document = ShellFolderView object $oSHFolderView=$oIEObject.Document If IsObj($oSHFolderView) Then Return $oSHFolderView Return SetError(4,0,0) EndIf Next Return SetError(-1,0,0) EndFunc ; ========================================================================================================================== ; Func _ExplorerWinGetSelectedItems($hWnd) ; ; ; Author: klaus.s, KaFu, Ascend4nt (consolidation & cleanup, Path name simplification) ; ========================================================================================================================== Func _ExplorerWinGetSelectedItems($hWnd) If Not IsHWnd($hWnd) Then Return SetError(1,0,'') Local $oSHFolderView Local $iSelectedItems,$iCounter=2,$aSelectedItems[2] = [0, ""] $oSHFolderView=_ObjectSHFolderViewFromWin($hWnd) If @error Then Return SetError(@error,0,'') ; SelectedItems = FolderItems Collection object->Count $iSelectedItems = $oSHFolderView.SelectedItems.Count Dim $aSelectedItems[$iSelectedItems+2] ; 2 extra -> 1 for count [0], 1 for Folder Path [1] $aSelectedItems[0]=$iSelectedItems ; ShellFolderView->Folder->Self as 'FolderItem'->Path $aSelectedItems[1]=$oSHFolderView.Folder.Self.Path ; ShellFolderView->SelectedItems = FolderItems Collection object $oSelectedFolderItems = $oSHFolderView.SelectedItems #cs ; For ALL items in an Explorer window (not just the selected ones): $oSelectedFolderItems = $oSHFolderView.Folder.Items ReDim $aSelectedItems[$oSelectedFolderItems.Count+2] #ce For $oFolderItem In $oSelectedFolderItems $aSelectedItems[$iCounter] = $oFolderItem.Path $iCounter += 1 Next Return SetExtended($iCounter-2,$aSelectedItems) EndFunc ;==>_ExplorerWinGetSelectedItems Func _ComErrFunc($oError) ConsoleWrite("COM Error occurred:" & @CRLF & _ "Number: " & @TAB & $oError.number & @CRLF & _ "Windescription:" & @TAB & $oError.windescription & @CRLF & _ "Description is: " & @TAB & $oError.description & @CRLF & _ "Source is: " & @TAB & $oError.source & @CRLF & _ "Helpfile is: " & @TAB & $oError.helpfile & @CRLF & _ "Helpcontext is: " & @TAB & $oError.helpcontext & @CRLF & _ "Lastdllerror is: " & @TAB & $oError.lastdllerror & @CRLF & _ "Scriptline is: " & @TAB & $oError.scriptline & @CRLF & _ "Retcode is: " & @TAB & $oError.retcode & @CRLF & @CRLF) EndFunc ;==>_ComErrFunc M23 AGlassman 1 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
ZGorlock Posted March 27, 2012 Posted March 27, 2012 ZGorlock, Welcome to the AutoIt forum. Using Ascend4nt's code from post #35 you can get the selected items in string or array form like this: expandcollapse popup#include <Array.au3> Local $oErrorHandler = ObjEvent("AutoIt.Error", "_ComErrFunc") $aWinList=WinList("[REGEXPCLASS:^(Explore|Cabinet)WClass$]") For $i = 1 To $aWinList[0][0] ; Get base folder and selections $aSelection = _ExplorerWinGetSelectedItems($aWinList[$i][1]) ; Display as strings ConsoleWrite("Explorer Window: " & $aSelection[1] & " Selection(s)" & @CRLF) For $j = 2 To $aSelection[0] + 1 ConsoleWrite(@TAB & $aSelection[$j] & @CRLF) Next ; Display as array _ArrayDisplay($aSelection, "Explorer Instance #" & $i & " / " & $aWinList[$i][0]) Next ; ========================================================================================================================== ; Func _ObjectSHFolderViewFromWin($hWnd) ; ; Returns an 'ShellFolderView' Object for the given Window handle ; ; Author: Ascend4nt, based on code by KaFu, klaus.s ; ========================================================================================================================== Func _ObjectSHFolderViewFromWin($hWnd) If Not IsHWnd($hWnd) Then Return SetError(1,0,0) Local $oShell,$oShellWindows,$oIEObject,$oSHFolderView ; Shell Object $oShell=ObjCreate("Shell.Application") If Not IsObj($oShell) Then Return SetError(2,0,0) ; Get a 'ShellWindows Collection' object $oShellWindows = $oShell.Windows() If Not IsObj($oShellWindows) Then Return SetError(3,0,0) ; Iterate through the collection - each of type 'InternetExplorer' Object For $oIEObject In $oShellWindows If $oIEObject.HWND = $hWnd Then ; InternetExplorer->Document = ShellFolderView object $oSHFolderView=$oIEObject.Document If IsObj($oSHFolderView) Then Return $oSHFolderView Return SetError(4,0,0) EndIf Next Return SetError(-1,0,0) EndFunc ; ========================================================================================================================== ; Func _ExplorerWinGetSelectedItems($hWnd) ; ; ; Author: klaus.s, KaFu, Ascend4nt (consolidation & cleanup, Path name simplification) ; ========================================================================================================================== Func _ExplorerWinGetSelectedItems($hWnd) If Not IsHWnd($hWnd) Then Return SetError(1,0,'') Local $oSHFolderView Local $iSelectedItems,$iCounter=2,$aSelectedItems[2] = [0, ""] $oSHFolderView=_ObjectSHFolderViewFromWin($hWnd) If @error Then Return SetError(@error,0,'') ; SelectedItems = FolderItems Collection object->Count $iSelectedItems = $oSHFolderView.SelectedItems.Count Dim $aSelectedItems[$iSelectedItems+2] ; 2 extra -> 1 for count [0], 1 for Folder Path [1] $aSelectedItems[0]=$iSelectedItems ; ShellFolderView->Folder->Self as 'FolderItem'->Path $aSelectedItems[1]=$oSHFolderView.Folder.Self.Path ; ShellFolderView->SelectedItems = FolderItems Collection object $oSelectedFolderItems = $oSHFolderView.SelectedItems #cs ; For ALL items in an Explorer window (not just the selected ones): $oSelectedFolderItems = $oSHFolderView.Folder.Items ReDim $aSelectedItems[$oSelectedFolderItems.Count+2] #ce For $oFolderItem In $oSelectedFolderItems $aSelectedItems[$iCounter] = $oFolderItem.Path $iCounter += 1 Next Return SetExtended($iCounter-2,$aSelectedItems) EndFunc ;==>_ExplorerWinGetSelectedItems Func _ComErrFunc($oError) ConsoleWrite("COM Error occurred:" & @CRLF & _ "Number: " & @TAB & $oError.number & @CRLF & _ "Windescription:" & @TAB & $oError.windescription & @CRLF & _ "Description is: " & @TAB & $oError.description & @CRLF & _ "Source is: " & @TAB & $oError.source & @CRLF & _ "Helpfile is: " & @TAB & $oError.helpfile & @CRLF & _ "Helpcontext is: " & @TAB & $oError.helpcontext & @CRLF & _ "Lastdllerror is: " & @TAB & $oError.lastdllerror & @CRLF & _ "Scriptline is: " & @TAB & $oError.scriptline & @CRLF & _ "Retcode is: " & @TAB & $oError.retcode & @CRLF & @CRLF) EndFunc ;==>_ComErrFunc M23 Could someone please convert this to C code?
Moderators Melba23 Posted March 27, 2012 Moderators Posted March 27, 2012 (edited) ZGorlock,Could someone please convert this to C code?- 1. This is the AutoIt forum - if you want C code, I suggest you go to a C forum.- 2. This now has nothing to do with the original thread - please do not go off-topic. M23 Edited March 27, 2012 by Melba23 Typo Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
stormbreaker Posted March 27, 2012 Posted March 27, 2012 (edited) Thanx a lot. This was surely a handy function, you saved me 20 lines of code. Edited March 27, 2012 by MKISH ---------------------------------------- :bye: Hey there, was I helpful? ---------------------------------------- My Current OS: Win8 PRO (64-bit); Current AutoIt Version: v3.3.8.1
MilesAhead Posted March 29, 2012 Posted March 29, 2012 (edited) If you are in a position to stipulate the user enable "display full path in title bar" and/or "display full path in addressbar" for XP and later systems then I find this function very fast for polling: expandcollapse popupFunc Poll4Folder() Do While 1 $handle = _WinAPI_GetForegroundWindow() $className = _WinAPI_GetClassName($handle) If $className = "ExploreWClass" Or $className = "CabinetWClass" Then ExitLoop Else Return EndIf WEnd $title = _WinAPI_GetWindowText($handle) $text = WinGetText($title) $folders = _StringBetween($text, "Address: ", @LF) If Not @error Then $folder = $folders[0] Else $textLines = StringSplit($text, @LF) If $textLines[0] > 1 Then $folder = $textLines[2] Else $folder = $textLines[1] EndIf EndIf If $folder = $tmp Then $weight += 1 If $weight = $weightTrigger Then _Insert_Folder($folder) $weight = 0 $tmp = "" Return EndIf ElseIf _ValidPath($folder) Then $tmp = $folder $weight = 1 Return EndIf ExitLoop Until 0 EndFunc ;==>Poll4Folder Note that it uses some global variables and a function to insert the Folder into an array for saving to disk and displaying in a Gui ListBox. It works on XP, Vista and W7 both 32 and 64 bit. The business with the Weight variable is because I tried to tune it to avoid saving every single folder as the user drills down by double clicking. Whenever the user pauses for a split second the folder should be saved. It's not perfect but I've been using it on some MRU folder caching programs for a few years and I haven't had complaints. edit: I know there are apparent redundancies like getting the title of the window using the tile of the window. But I determined via trial and error that it works better that way. Could be due to not setting text matching to slow mode. But this code has worked for a long time so it ain't broke and I don't fix it. edit2: You may substitute FileExists() for _ValidPath() function. _ValidPath() is just an attempt to avoid calling FileExists() on network drives that aren't mapped any longer etc.. Doing that tends to induce a pause as the FileExist() call times out. Edited March 30, 2012 by MilesAhead My Freeware Page
hg2051 Posted July 26, 2014 Posted July 26, 2014 If you have a file "F' selected in folder "folderX",you can retrieve its long name by simulating Windows' RightClick+CopyFileName" WinActivate("C:...FolderX","Address: C:...FolderX") Send("{SHIFTDOWN}{F10}{SHIFTUP}{UP}{UP}{UP}{UP}{UP}{UP}{UP}{UP}{UP}{UP}{ENTER}");The number of "{UP}" depends on the position of "Copy file name" in your right click's button Sleep(110) $path=ClipGet() MsgBox(0,"$path",$path)
AGlassman Posted August 19, 2022 Posted August 19, 2022 (edited) Melba23's code is remarkable to someone as dumb as me. But it works like a champ. I looked at a number of Send Key techniques but I really don't like doing things that way when there is another way. Thank you Melba23. Nice piece of code! Here's what you get when you pass Melba23's _ExplorerWinGetSelectedItems function the handle to a Windows Explorer window. The directory is the first element of the array and any selected items follow. Edited August 20, 2022 by AGlassman Add image
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now