我需要获取在Windows资源管理器中选择的文件的当前集合。我从这里找到了下面的代码。
不过,还有一些问题需要解决。首先,GetForegroundWindow
是什么意思?其次,在该行上,编译器会发出警告。
var shell = new Shell32.Shell();
说:
"类型或命名空间名称 'Shell32' 无法找到(是否缺少使用指令或程序集引用?)"。我已将SHDocVw添加为引用,但我仍无法通过编译器。请问有人能帮我完成这个吗?
IntPtr handle = GetForegroundWindow();
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);
}
}
}