在资源管理器中双击文件会正确地将文件添加到我的应用程序的最近列表中,然后我可以从应用程序的弹出菜单中再次打开它,我已将其固定在开始菜单上。
我在应用程序中有一个特殊的文件管理器,所以我使用SHAddToRecentDocs将应用程序中打开的项目添加到最近的文件中。但它没有发生,我找不到问题所在。
这是我在注册表中获得的内容:
HKEY_CLASSES_ROOT\.abc\Content Type = application/MyApp
HKEY_CLASSES_ROOT\.abc\(Standard) = MyAppProjectFile
HKEY_CLASSES_ROOT\MyAppProjectFile\shell\open\command\(Standard) = "C:\MyApp\MyApp.exe" %1
HKEY_CLASSES_ROOT\Applications\MyApp.exe\shell\open\command\(Standard) = "C:\MyApp\MyApp.exe" %1
HKCR \ Applications \ MyApp.exe下没有其他键。
就像我说的,我可以通过在资源管理器中双击它们来打开应用程序,它们会被添加到最近的文档中,一切看起来都很好。我可以从弹出窗口打开它们。
我的SHAddToRecentDocs调用获得了正确的路径,似乎根本没有做任何事情。最近的文档文件夹中没有链接。
这是我用来运行SHAddToRecentDocs的C#代码:
[DllImport("Shell32.dll", CharSet = CharSet.Unicode)]
static extern void SHAddToRecentDocs(ShellAddToRecentDocsFlags flags, string file);
[Flags]
public enum ShellAddToRecentDocsFlags
{
Pidl = 0x001,
Path = 0x002,
}
/// <summary>
/// Adds the file to recent files list in windows.
/// </summary>
/// <param name="fullPath"> Name of the file. </param>
public static void AddFileToRecentFilesList(string fullPath)
{
SHAddToRecentDocs(ShellAddToRecentDocsFlags.Path, fullPath);
}
答案 0 :(得分:1)
如果证明对FxCop代码警告的修复是不起作用的原因。
ShellAddToRecentDocsFlags API定义如下:
[DllImport("Shell32.dll", CharSet = CharSet.Unicode)]
static extern void SHAddToRecentDocs(ShellAddToRecentDocsFlags flags, string file);
将其更改为以下内容解决了问题:
[DllImport("Shell32.dll", BestFitMapping = false, ThrowOnUnmappableChar = true)]
static extern void SHAddToRecentDocs(ShellAddToRecentDocsFlags flags, [MarshalAs(UnmanagedType.LPStr)]string file);