OpenFileDialog间谍 [英] OpenFileDialog Spy

查看:102
本文介绍了OpenFileDialog间谍的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正试图从另一个应用程序创建的标准OpenFileDialog窗口中捕获所选文件和文件夹的路径.

I'm trying to capture the path of selected files and folders from the standard OpenFileDialog window created by another application.

我已经看到可以使用Windows资源管理器执行此任务:

I have seen that is possible to perform this task with windows explorer:

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的主体进行投射.

However, the SHDocVw.ShellWindows () method does not return the opened openFileDialog hwnd. As windows explorer is very similar to OpenFileDialog, I imagine there is some way to do a cast having the hwnd of OpenFileDialog for the Shell32.IShellFolderViewDual2 interface like:

var view = Shell32.ShellFolderViewDual2.FromHwnd(hwnd);

还有其他方法吗?

目标很简单,记录标准OpenFileDialog窗口中使用的文件.在Windows 7、8、10中可用.

The goal is simple, make a log of files used in standard OpenFileDialog windows. Workable in Windows 7, 8, 10.

我知道,这似乎是非常非常非常奇怪的事情.

I know, it seems a very very very strange thing.

Inspect.exe给我希望:

Inspect.exe give me hope:

推荐答案

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

An open file dialog is not a shell window so it won't show up in the ShellWindows list.

您可以发送未记录的WM_GETISHELLBROWSER(WM_USER + 7)消息到对话框窗口,但是返回的IShellBrowser指针仅在同一进程内有效.在另一个进程中使用它会导致访问冲突.

You can send the undocumented WM_GETISHELLBROWSER (WM_USER+7) message to the dialog window, but the returned IShellBrowser pointer is only valid inside the same process. Using it in another process would cause access violation.

一旦获得IShellBrowser,您就可以获取其他接口,例如IShellView或IFolderView2 .对于选择,您要使用IFolderView2 :: GetSelection.

Once you got IShellBrowser you can get other interfaces like IShellView or IFolderView2. For selection you want to use IFolderView2::GetSelection.

可以将代理DLL注入到目标进程中以控制文件对话框,但是您不能使用C#编写DLL.

It is possible to inject a proxy DLL into the target process to control the file dialog, but you can't write the DLL in C#.

这篇关于OpenFileDialog间谍的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆