I have a pointer to an opened Explorer Window and i want to know its full path.
For Example:
int hWnd = FindWindow(null, "Directory");
But now, how to obtain the directory full path like "C:UsersmmDocumentsDirectory"
I have a pointer to an opened Explorer Window and i want to know its full path.
For Example:
int hWnd = FindWindow(null, "Directory");
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);
}
Adapted from this: http://msdn.microsoft.com/en-us/library/windows/desktop/bb773974(v=vs.85).aspx
Cheers
EDIT: I changed ie.locationname, which was not returning the full path, to ie.document.focuseditem. path, which seems to be working so far.