views:

144

answers:

3

I'm launching an application from a WPF app using the Process class that displays a splash screen at startup. Rather than show the user the splash screen, I'd like to hide the application for the first couple of seconds after starting it by keeping my window topmost and maximized. The problem is that starting this application automatically takes my window out of topmost mode and shows the windows task bar. Is there a way to prevent the process from showing a window for a few second until it starts up, then displaying its window?

A: 

Can't you just set the visibility of the MainWindow that starts up to Collapsed and then toggle it after the splash launches?

mstrickland
Thanks, I tried but the app doesn't respond to that. It still tried to make itself topmost.
James Cadd
+1  A: 

Do you own the application you are trying to start without showing it's main window directly at startup? In that case do the following.

Override the Application.OnStartup method in your App class and do your initialization there. No windows or taskbar buttons will be displayed (automatically) until after that method finishes.

using System.Diagnostics;
using System.Threading;
using System.Windows;

namespace DelayedStartDemo
{
    public partial class App : Application
    {
        protected override void OnStartup(StartupEventArgs e)
        {
            Thread.Sleep(5000);

            base.OnStartup(e);

            Debug.Assert(MainWindow == null);
        }

        protected override void OnActivated(System.EventArgs e)
        {
            Debug.Assert(MainWindow != null && 
                         MainWindow.Visibility == Visibility.Visible && 
                         MainWindow.ShowInTaskbar);

            base.OnActivated(e);
        }
    }
}
Wallstreet Programmer
Thank you for the idea, unfortunately I don't own the application whos splash screen i'm trying to suppress.
James Cadd
+1  A: 

So you have two application fighting about being top most window but of course only one can be top most at the same time. Windows rightfully don't let a single application make that decision, that would be a security hole. See Raymond Chen's answer here why: http://blogs.msdn.com/oldnewthing/archive/2005/06/07/426294.aspx

Wallstreet Programmer