我有一个指向打开的资源管理器窗口的指针,我想知道它的完整路径。
例如:
int hWnd = FindWindow(null, "Directory");
但是现在,如何获取目录完整路径,如 "C:\Users\mm\Documents\Directory"
最佳答案
这是获取该信息的一种方法:
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.path
,这似乎到目前为止有效。
关于c# - 从资源管理器窗口获取文件夹路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20960316/