Recently I was tasked with making a screensaver to run on Windows and it had to run on Windows XP, Windows Vista, and Windows 7. I decided to do it with WPF as that is my new favorite technology. So like all good developers I pulled up my browser and searched for somebody who’d done it already. After a little prodding, I found several articles with relevant code samples, a few MSDN pages and some other interesting stuff. I had my screensaver built shortly after.
Then came time to make the installer for the screensaver, a standard Windows installer is no big deal. This one just needed to add a couple of registry entries for the screensaver file to make it the default and copy the output file (an executable renamed with a .scr extension) to the appropriate folder. When I ran this everything worked beautifully, except now the dropdown that lets you choose your screensaver in the display properties only displays the filename of the output file, but on older Windows versions (pre-XP) the registry key only supports making an 8 character filename the default screensaver . Sure, it works fine to have an 8 character filename since this is for XP and above, but I don’t like putting spaces in filenames and I’d never release anything that sloppy so I went digging again.
Turns out that the .scr file needs to have a Win32 native resource embedded in it that has a value in its StringTable. Doing this allowed the drop down to reference the embedded string. In a C++ application that wouldn’t be a big deal but I’m in C# where the resources are usually managed.
I went digging again. After some time, I found that I was supposed to use a Native Resource Template to create a resource file (.res) to embed into the executable. All the articles showed that clearly was the way to go, But none of them mentioned that you can’t create one of those on a C#/VB.NET project in Visual Studio. You have to create it by adding it as a Solution Item instead. It didn’t take long to figure that out but it would’ve saved me 10-15 minutes if somebody had bothered to mention it.
Creating that wasn’t a big deal, and there were examples for how to add a StringTable and the string for the friendly name. Then the next hurdle, How to embed it? Well, Visual Studio has an option to use a res file instead of the normal manifest it embeds. Of course I’m not sure how this affects the file’s Vista compliance and security settings that are normally embedded using the manifest, or even if that matters. A point for further study.
In any case, the screensaver now installs and works as expected with the appropriate title in the dropdown so I can’t complain.