【问题标题】:OpenFileDialog SpyOpenFileDialog 间谍
【发布时间】: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


    【解决方案1】:

    打开的文件对话框不是 shell 窗口,因此它不会显示在 ShellWindows 列表中。

    你可以send the undocumented WM_GETISHELLBROWSER (WM_USER+7) message to the dialog window,但是返回的IShellBrowser指针只在同一个进程内有效。在另一个进程中使用它会导致访问冲突。

    获得 IShellBrowser 后,您可以get other interfaces like IShellView or IFolderView2。对于选择,您要使用 IFolderView2::GetSelection。

    可以在目标进程中注入代理DLL来控制文件对话框,但不能用C#编写DLL。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-09-26
      • 2018-02-15
      • 1970-01-01
      • 2023-03-06
      • 1970-01-01
      相关资源
      最近更新 更多