One of the cool new features that I am working on for RC2 of Package Explorer is a start page that is presented when the application starts. Because of the graphical nature of these startpages many applications like IDEs choose to use an HTML page that is displayed in a WebBrowser control of some sort. I of course wanted to do the same and bumped in to some interesting hurdles for which I didn't find a fix that I liked. So, here's my solution for doing this. (Did I mention that Package Explorer is starting to get really cool, and it's got some nifty pieces of code as well, like the Main routine)
First of all, a screenie (mind you, it is a work in progress, as it appears the transparency isn't quite transparent)
And yes, I have Maarten to thank for designing this. I really suck at it, so his designs are very welcome. Thanks Maarten!
Now the issue. Personally I don't like to have resource files loose on disk. I like to embed them in the DLL and only have one file to deploy. I at least like that for not frequently changing resources. For the startpage this would mean I need to embed the HTML (no problem) and the images (hmmm). To access the images inside the DLL I planned to use the res:// protocol. It can access resources in a DLL for just this purpose (and many others I would suspect). The downside, a .NET embedded resource is different from a Win32 embedded resource which the res:// protocol handler understands in IE. There are tools that you can use to embed resources manually after the build, but I am a programmer and I don't like to do things manually. I bet you don't either :)
My solution? I have a separate project for the start page HTML and images. The first task is to allow Win32 resources to appear in the .NET DLL. The CSC compiler has a switch to allow you to do just this. You can edit the CSPROJ project file to tell Visual Studio to use this switch and select the right resource file for the compilation. You can edit the project file using Notepad or something. Visual Studio will detect the change and ask you to reload the project.
<PropertyGroup>
<Win32Resource>StartPage.res</Win32Resource>
</PropertyGroup>
That's step 1, now to get a .RES file. This is rather easy and can be neatly integrated into the build. The RC.exe compiler can take a .RC file to compile into a .RES file. So it's just two easy steps to make it work. First you create a .RC file for the resource compiler:
Background.bmp Bitmap "Background.bmp"
FieldsetBackGround.bmp Bitmap "FieldsetBackGround.bmp"
FieldsetLabelBackGround.bmp Bitmap "FieldsetLabelBackGround.bmp"
Logo.bmp Bitmap "Logo.bmp"
Next you add a prebuild commandline to the poject using Visual Studio.
"C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\Bin\rc" /r "$(ProjectDir)StartPage.rc"
That's it. You can now just compile the project and it will first compile a .RES file from the resource definition and this .RES file will be embedded into the DLL automatically.
Now the cool thing is that you cannot only reference the embedded resources using the normal tags such as IMG
<img src="res://PackageExplorer.StartPage.dll/#2/LOGO.BMP" />
But you can also reference the resources from CSS (at least in IE that I am aware of)
fieldset
{
background-image: url(res://PackageExplorer.StartPage.dll/#2/FIELDSETBACKGROUND.BMP);
}
No more clutter on the harddrive and the possible deletion / change by Joe User.
Hope it helps.