【发布时间】:2017-07-05 16:38:46
【问题描述】:
我正在尝试从另一个应用程序创建的标准 OpenFileDialog 窗口中捕获所选文件和文件夹的路径。
我已经看到可以使用 Windows 资源管理器执行此任务:
IntPtr handle = GetOpenFileDialogHwnd();
ArrayList selected = new ArrayList();
var shell = new Shell32.Shell();
foreach(SHDocVw.InternetExplorer window in shell.Windows())
{
if (window.HWND == (int)handle)
{
Shell32.FolderItems items = ((Shell32.IShellFolderViewDual2)window.Document).SelectedItems();
foreach(Shell32.FolderItem item in items)
{
selected.Add(item.Path);
}
}
}
但是,SHDocVw.ShellWindows() 方法不返回打开的 openFileDialog hwnd。由于 Windows 资源管理器与 OpenFileDialog 非常相似,我想有一些方法可以对 Shell32.IShellFolderViewDual2 接口进行具有 OpenFileDialog 的 hwnd 的转换,例如:
var view = Shell32.ShellFolderViewDual2.FromHwnd(hwnd);
还有其他方法吗?
目标很简单,记录标准 OpenFileDialog 窗口中使用的文件。适用于 Windows 7、8、10。
我知道,这似乎是一件非常非常非常奇怪的事情。
编辑:
Inspect.exe 给我希望:
【问题讨论】:
标签: c# windows shell winapi openfiledialog