我在堆栈溢出时在这里找到了这段代码,并将其修改为返回一个列表而不是一个数组列表。每当我按下一个键时都会调用该函数,虽然该函数被调用正常,但 SelectedItems() 每次似乎都是空的,即使我在桌面上突出显示了一些东西。我也在资源管理器窗口中尝试过,结果相同。有谁知道为什么它什么都不返回?stackoverflow 上的其他人似乎能够让它工作我的有什么问题?
public List<string> GetShellItems()
{
List<string> selected = new List<string>();
foreach (SHDocVw.InternetExplorer window in new SHDocVw.ShellWindows())
{
filename = Path.GetFileNameWithoutExtension(window.FullName).ToLower();
if (filename.ToLowerInvariant() == "explorer")
{
Shell32.FolderItems items = ((Shell32.IShellFolderViewDual2)window.Document).SelectedItems();
foreach (Shell32.FolderItem item in items)
{
selected.Add(item.Path);
}
}
}
return selected;
}