【发布时间】:2013-01-07 09:48:26
【问题描述】:
我需要获取在 Windows 资源管理器中选择的当前文件集合。我从here找到了以下代码。
不过,我并不完全在那里。一方面,GetForegroundWindow 来自哪里?还有一件事,编译器抱怨就行了
var shell = new Shell32.Shell();
说
"找不到类型或命名空间名称“Shell32”(您是 缺少 using 指令或程序集引用?)”。我添加了 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);
}
}
}
【问题讨论】:
标签: c# windows-shell