从资源管理器窗口获取文件夹路径 [英] 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:UsersmmDocumentsDirectory"
But now, how to obtain the directory full path like "C:UsersmmDocumentsDirectory"
推荐答案
以下是获取该信息的方法:
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屋!
查看全文