我可以显示编程选择多个文件,然后在Windows资源管理器这样的单个文件:在Windows资源管理器
explorer.exe /select, "c:\path\to\file.txt"
不过,我不知道如何选择多个文件。没有选择的排列我尝试过工作。
注:我看了这些页面的文档,都没有帮助。
https://support.microsoft.com/kb/314853
http://www.infocellar.com/Win98/explorer-switches.htm
我可以显示编程选择多个文件,然后在Windows资源管理器这样的单个文件:在Windows资源管理器
explorer.exe /select, "c:\path\to\file.txt"
不过,我不知道如何选择多个文件。没有选择的排列我尝试过工作。
注:我看了这些页面的文档,都没有帮助。
https://support.microsoft.com/kb/314853
http://www.infocellar.com/Win98/explorer-switches.htm
这应该是可能与外壳函数SHOpenFolderAndSelectItems
EDIT
这里是示出如何使用在C/C++函数,没有错误检查一些示例代码:
//Directory to open
ITEMIDLIST *dir = ILCreateFromPath(_T("C:\\"));
//Items in directory to select
ITEMIDLIST *item1 = ILCreateFromPath(_T("C:\\Program Files\\"));
ITEMIDLIST *item2 = ILCreateFromPath(_T("C:\\Windows\\"));
const ITEMIDLIST* selection[] = {item1,item2};
UINT count = sizeof(selection)/sizeof(ITEMIDLIST);
//Perform selection
SHOpenFolderAndSelectItems(dir, count, selection, 0);
//Free resources
ILFree(dir);
ILFree(item1);
ILFree(item2);
它无法通过的explorer.exe
根据你真的想完成你可能能够AutoHotKey做什么来完成。这是一个惊人的免费工具,用于自动执行通常无法做到的事情。它应该随Windows一起提供。这个脚本将选择你的文件,并在你点击F12时突出显示下面的两个文件。
F12::
run explorer.exe /select`, "c:\path\to\file.txt"
SendInput {Shift Down}{Down}{Down}{Shift Up}
return
也可以将这两个中间行放在一个文本文件中,然后将它传递给autohotkey.exe。他们还可以选择编译脚本,这可以使它成为一个可以调用的独立exe文件。很好的帮助文件。
@Orion,可以使用C#中的autohotkey。你可以将一个autohotkey脚本变成一个独立的可执行文件(大约400k),可以由你的C#应用程序启动(就像启动资源管理器一样)。你也可以传递它的命令行参数。它没有任何运行时要求。
这是其中一个问题,它可能是很好的考虑你想要达到什么,以及是否有更好的方法。
要多补充一些背景 - 我们公司开发了一个C#客户端应用程序,它允许用户加载文件和做的东西与他们,有点像iTunes如何管理你的MP3文件,而不会显示你在磁盘上的实际文件。
这是有用的,选择应用程序中的文件,并做了“让我在Windows Explorer`命令这个文件 - 这就是我想实现的,并且为单个文件这样做。
我们有一个ListView,它允许用户在应用程序中选择多个文件,并移动/删除/等等。如果所有源文件都在同一个目录中,至少在所有源文件都在同一个目录中的情况下,将这个“在windows中显示此文件”命令很好,至少如果不可能,那么它就不是主要功能。
我想你可以使用FindWindowEx
来获取Windows资源管理器的SysListView32,然后使用SendMessage
和LVM_SETITEMSTATE
来选择项目。难以知道物品的位置......也许LVM_FINDITEM
可用于此。
Grr我想这样做。媒体播放器当你选择2+文件并右键单击并执行“打开文件位置”,但不完全知道如何(我真的不想花时间w/procmon找出它)。
在Explorer中选择多个文件的真正方法是下一个
非托管代码看起来像这样(编译自中国代码帖子,修复了其中的错误)
static class NativeMethods
{
[DllImport("shell32.dll", ExactSpelling = true)]
public static extern int SHOpenFolderAndSelectItems(
IntPtr pidlFolder,
uint cidl,
[In, MarshalAs(UnmanagedType.LPArray)] IntPtr[] apidl,
uint dwFlags);
[DllImport("shell32.dll", CharSet = CharSet.Auto)]
public static extern IntPtr ILCreateFromPath([MarshalAs(UnmanagedType.LPTStr)] string pszPath);
[ComImport]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
[Guid("000214F9-0000-0000-C000-000000000046")]
public interface IShellLinkW
{
[PreserveSig]
int GetPath(StringBuilder pszFile, int cch, [In, Out] ref WIN32_FIND_DATAW pfd, uint fFlags);
[PreserveSig]
int GetIDList([Out] out IntPtr ppidl);
[PreserveSig]
int SetIDList([In] ref IntPtr pidl);
[PreserveSig]
int GetDescription(StringBuilder pszName, int cch);
[PreserveSig]
int SetDescription([MarshalAs(UnmanagedType.LPWStr)] string pszName);
[PreserveSig]
int GetWorkingDirectory(StringBuilder pszDir, int cch);
[PreserveSig]
int SetWorkingDirectory([MarshalAs(UnmanagedType.LPWStr)] string pszDir);
[PreserveSig]
int GetArguments(StringBuilder pszArgs, int cch);
[PreserveSig]
int SetArguments([MarshalAs(UnmanagedType.LPWStr)] string pszArgs);
[PreserveSig]
int GetHotkey([Out] out ushort pwHotkey);
[PreserveSig]
int SetHotkey(ushort wHotkey);
[PreserveSig]
int GetShowCmd([Out] out int piShowCmd);
[PreserveSig]
int SetShowCmd(int iShowCmd);
[PreserveSig]
int GetIconLocation(StringBuilder pszIconPath, int cch, [Out] out int piIcon);
[PreserveSig]
int SetIconLocation([MarshalAs(UnmanagedType.LPWStr)] string pszIconPath, int iIcon);
[PreserveSig]
int SetRelativePath([MarshalAs(UnmanagedType.LPWStr)] string pszPathRel, uint dwReserved);
[PreserveSig]
int Resolve(IntPtr hwnd, uint fFlags);
[PreserveSig]
int SetPath([MarshalAs(UnmanagedType.LPWStr)] string pszFile);
}
[Serializable, StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode), BestFitMapping(false)]
public struct WIN32_FIND_DATAW
{
public uint dwFileAttributes;
public FILETIME ftCreationTime;
public FILETIME ftLastAccessTime;
public FILETIME ftLastWriteTime;
public uint nFileSizeHigh;
public uint nFileSizeLow;
public uint dwReserved0;
public uint dwReserved1;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)]
public string cFileName;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 14)]
public string cAlternateFileName;
}
public static void OpenFolderAndSelectFiles(string folder, params string[] filesToSelect)
{
IntPtr dir = ILCreateFromPath(folder);
var filesToSelectIntPtrs = new IntPtr[filesToSelect.Length];
for (int i = 0; i < filesToSelect.Length; i++)
{
filesToSelectIntPtrs[i] = ILCreateFromPath(filesToSelect[i]);
}
SHOpenFolderAndSelectItems(dir, (uint) filesToSelect.Length, filesToSelectIntPtrs, 0);
ReleaseComObject(dir);
ReleaseComObject(filesToSelectIntPtrs);
}
private static void ReleaseComObject(params object[] comObjs)
{
foreach (object obj in comObjs)
{
if (obj != null && Marshal.IsComObject(obj))
Marshal.ReleaseComObject(obj);
}
}
}
如果文件之间并不相互依赖,那么效果不好吗? – Svish 2009-12-06 11:56:40
这就是为什么我说“依赖”和“可能”。在autohotkey中有很多选项,包括自动搜索,我只举了一个例子。 – bruceatk 2009-12-08 19:42:54
我不知道为什么这被标记下来。当你需要做一些你无法用现有的API做的事时,AutoHotkey是一个很好的解决方案。它有很多保护措施可以用来确保正确的程序是针对性的。有很多可能性。被标记为答案的答案不是答案。这只是一个明显的陈述,这就是首先提出问题的原因。我会建议任何人标记这个答案应该先看看AutoHotkey并了解它可以做什么。它应该被嵌入到窗口中。 – bruceatk 2010-01-20 17:37:11