简体   繁体   中英

Using Windows API Code Pack can I get Windows Explorer AddresBar path?

I would like to know whether the Class Library of the Microsoft's Windows APi Code Pack library provides a direct way to iterate the Windows Explorer instances to retrieve the current path of the address bar of each Explorer instance, in simple words, I need to get a list with all the paths that are open by Explorer.exe instances.

This is the text which I would like to retrieve (from all running instances of explorer.exe)

在此处输入图片说明

I don't know if this is possibly using Windows API Code Pack then I do not have any code to demonstrate my progress (which is Zero), I'm just asking for information about this to procceed with a better investigation, but any kind of code example will be very appreciated.

If Windows API Code Pack can't help in the task, what alternatives I have to realize this? maybe Microsoft UI automation ?

PS: I doscovered the way to retrieve it using the interop Microsoft Internet Controls , the solution is explained in this url , but I'm really interested into learn how to do it using Windows API Code Pack

This will get you most of the way there, First, add reference for Microsoft Shell Controls and Automation and Microsoft Internet Controls from the COM tab in Project -> References

Imports Shell32

Private exList As New List(Of String) '

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click

    Dim exShell As New Shell

    exList.Clear()

    For Each win As ShellBrowserWindow In DirectCast(exShell.Windows, IShellWindows)
        thisPath = ""
        If TryCast(win.Document, IShellFolderViewDual) IsNot Nothing Then
            thisPath = DirectCast(win.Document, IShellFolderViewDual).FocusedItem.Path
        ElseIf TryCast(win.Document, ShellFolderView) IsNot Nothing Then
            thisPath = DirectCast(win.Document, ShellFolderView).FocusedItem.Path
        End If

        If String.IsNullOrEmpty(thisPath) = False Then
            ExplorerFiles.Add(thisPath)
        End If

    Next
End Sub

Test output:

C:\Temp\_test
M:\Books - Non Fiction\Crusades - Iron Men and Saints\01 Iron Men and Saints.mp3
G:\_Video\_Movies

Sometimes it also seems to report the first item is selected. This might be a better way

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM