我希望能够显示
Windows屏幕保护程序对话框显示的基本相同的列表,以及每个屏幕保护程序的名称.然而,我遇到的问题是,对话框下拉列表中显示的名称似乎与文件名,嵌入文件信息,注册表中的任何内容等无关.
例如,3D FlowerBox屏幕保护程序具有Direct3D FlowerBox的文件描述.我无法在任何地方找到“3D FlowerBox”.
这些信息存储在哪里?
我该如何检索它.
解决方法@H_301_9@
这个问题有点陈旧,但我只需要解决同样的问题并提出以下解决方案:
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知道在哪里可以找到足够的资源.
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知道在哪里可以找到足够的资源.