获取从资源管理器窗口中的文件夹路径 [英] Get folder path from Explorer window
本文介绍了获取从资源管理器窗口中的文件夹路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个指针,指向一个打开资源管理器窗口,我想知道它的完整路径。
I have a pointer to an opened Explorer Window and i want to know its full path.
例如:
int hWnd = FindWindow(null, "Directory");
但现在,如何获得类似目录的完整路径C:\用户\毫米\文件\目录
推荐答案
下面是一个方式来获得这些信息:
Here's a way to obtain that information:
IntPtr MyHwnd = FindWindow(null, "Directory");
var t = Type.GetTypeFromProgID("Shell.Application");
dynamic o = Activator.CreateInstance(t);
try
{
var ws = o.Windows();
for (int i = 0; i < ws.Count; i++)
{
var ie = ws.Item(i);
if (ie == null || ie.hwnd != (long)MyHwnd) continue;
var path = System.IO.Path.GetFileName((string)ie.FullName);
if (path.ToLower() == "explorer.exe")
{
var explorepath = ie.document.focuseditem.path;
}
}
}
finally
{
Marshal.FinalReleaseComObject(o);
}
从这个改编:的http://msdn.microsoft.com/en-us/library/windows/desktop/bb773974(v=vs.85).aspx
干杯
编辑:我改变ie.locationname,这是不返回的完整路径,以ie.document.focuseditem。路径,这似乎是到目前为止工作
I changed ie.locationname, which was not returning the full path, to ie.document.focuseditem. path, which seems to be working so far.
这篇关于获取从资源管理器窗口中的文件夹路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文