Splash Screen

I decided to create a custom splash screen window for my application.

At first I had read this two articles :
As I could understand if we do as described at the first article it will not work at .Net 3.5 sp1 because original sample will have a dependency on milcore.dll.

Second sample will not work on .Net 3.5 without sp1 .

I couldn't uderstand why author had this dependency. But I knew another great sample. This application was photoSuru. They realisation hadn't this dependency. So it should work everywhere and on .Net 3.5 sp1 too.

1.Provide our own Main() method in WPF application

I used this artilce to provide my own Main method. How can I provide my own Main() method in my WPF application?
  1. I changed App.xaml BuildAction property from ApplicationDefinition to Page.
  2. Added my class with main method.
  3. And ran Application from it.

class EntryPoint
    static void Main()
        App app = new App();

The big disadvantage of this is that all Wpf Designers are failed now.

2. Get Splash Screen classes from photoSuru.

I added next files to my solution :
  • NativeMethods.cs
  • SplashScreen.cs
  • Win32Resources directory
Set path to the resoure file in the property tab.

And raised SplashScreen from it.

ScePhotoViewer.SplashScreen splash = new ScePhotoViewer.SplashScreen();

3. Determinate that window is loaded.

I don't know why, but PhotoSuru idea doesn't work. I mean that

app.LoadCompleted += new System.Windows.Navigation.LoadCompletedEventHandler(app_LoadCompleted);

static void app_LoadCompleted(object sender, System.Windows.Navigation.NavigationEventArgs e)
    Window1 window = e.Navigator as Window1;
    if (window != null)
        window.ContentRendered += new EventHandler(window_ContentRendered);
is not raise.

That's why I got jgoldb idea. He close splash in widow loaded method.

private void Window_Loaded(object sender, RoutedEventArgs e)

4. Working with native resources

I coldn't understand how I can replace icon and splash image. The solution is to rebuild resource file. Rc file is like sources. Res file is like executable program. RC.exe tool compile and build Res files from Rc.

I made simple bat file to do this operation.

"C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin\Rc.exe" SplashScreenWin32Resources.rc 
Last question was how i can set path to the resource file in the property tab ?

If I set this path in the designer it will failed. But if I edit .csprojet file in notepad and set this value by hand - project will be build successfully. I think it's a bug.

So, scenariod is :
  • Replace icon and image files
  • Rebuild RC file and get RES from it
  • Set path to the RES file in the property tab

Of course you can add rc build macros to pre-build event as jgoldb done. But this solution may compiles with error on the machine where is no such file or dicrectory. When i load his solution i've got compile error.


Our splash screen has disadvantages:
  • GDI+ processing the .PNG image loads the GDI+ DLLs which are not required by a typical WPF application and therefore will increase the overall startup time. (jgoldb wrote)
  • WPF designer are failed and if we want to see our application we should change App.xaml BuildAction property from Page to ApplicationDefinition.
PhotoSuru Sample and jgoldb sample = my simple sample. You can download it here My Splash Screen. I will use it in my application.

Last edited Sep 18, 2010 at 2:37 PM by Denis_Yakimenko, version 24


No comments yet.