我希望能够显示与Windows屏幕保护程序对话框基本相同的列表,以及每个屏幕保护程序的名称。然而,我遇到的问题是,在对话框的下拉列表中显示的名称似乎与文件名、嵌入的文件信息、注册表中的任何内容等不对应。
例如,3D FlowerBox屏幕保护程序的文件说明为Direct3D FlowerBox。我到处都找不到"3D FlowerBox“
这些信息存储在哪里?我怎样才能检索到它。
发布于 2009-11-15 23:23:53
这个问题有点老了,但我不得不解决同样的问题,并提出了以下解决方案:
public class ScreenSaverInfo
{
public string FileName { get; set; }
public string Name { get; set; }
}
public IEnumerable<ScreenSaverInfo> GetScreenSavers()
{
string currentSSPath = null;
using (RegistryKey desktopKey = Registry.CurrentUser.OpenSubKey(@"Control Panel\Desktop"))
{
if (desktopKey != null)
{
string screenSaverExe = desktopKey.GetValue("SCRNSAVE.EXE") as string;
if (!string.IsNullOrEmpty(screenSaverExe))
{
currentSSPath = Path.GetDirectoryName(screenSaverExe);
}
}
}
HashSet<string> directories = new HashSet<string>();
directories.Add(Environment.GetFolderPath(Environment.SpecialFolder.System));
directories.Add(Environment.GetFolderPath(Environment.SpecialFolder.SystemX86));
if (currentSSPath != null)
directories.Add(currentSSPath);
foreach (string dir in directories)
{
foreach (string file in Directory.EnumerateFiles(dir, "*.scr", SearchOption.TopDirectoryOnly))
{
yield return GetScreenSaverInfo(file);
}
}
}
public ScreenSaverInfo GetScreenSaverInfo(string filename)
{
IntPtr hLibrary = IntPtr.Zero;
try
{
hLibrary = LoadLibrary(filename);
StringBuilder sb = new StringBuilder(1024);
LoadString(hLibrary, 1, sb, sb.Capacity);
return new ScreenSaverInfo
{
FileName = filename,
Name = sb.ToString()
};
}
finally
{
if (hLibrary != IntPtr.Zero)
FreeLibrary(hLibrary);
}
}
[DllImport("kernel32.dll")]
static extern IntPtr LoadLibrary(string lpFileName);
[DllImport("kernel32.dll")]
static extern bool FreeLibrary(IntPtr hLibrary);
[DllImport("user32")]
static extern int LoadString(IntPtr hInstance, int wID, [Out] StringBuilder lpBuffer, int nBufferMax);基本上,屏幕保护程序的显示名称是.scr文件中的第一个资源字符串。请注意,对于某些屏幕保护程序(例如,Windows内置屏幕保护程序),本地化资源不在主.scr文件中,而是在特定于文化的子目录中的.scr.mui文件中。您不必担心这一点,因为LoadString知道哪里可以找到足够的资源。
发布于 2009-08-27 14:59:39
看一看question I once asked here about screen saver。这是解决方案的方向。此外,似乎框架本身并不存在这样的东西。
HTH,
发布于 2009-08-27 14:51:14
我的猜测是,如果您在系统中的任何地方都找不到它,那么它将作为某种元数据存储在程序集中。使用二进制编辑器打开该文件,然后搜索您要查找的名称。
https://stackoverflow.com/questions/1341575
复制相似问题