Take the 2-minute tour ×

I have an application written in .NET. The previous version had no problems: you double-click on the icon or run it from a command line and when it starts up, it's the main window and has focus as you'd expect.

The latest version displays a splash screen before the main window and now the splash screen comes to the foreground ok but the main one does not always end up the main window. Sometimes it does, sometimes it doesn't. (When launched from the command line it invariably doesn't). When the main window does not come to the foreground and get focus, the taskbar icon shows as a steady orange.

I see lots of hits on the net about how MS added a facility to prevent applications stealing focus from others, centered around the ForegroundLockTimeout registry setting and related settings, but the behaviors described above for the different versions happen on the same machine.

I have tried called Activate in the main form when it finally gets created, and also SetForegroundWindow, all to no avail.

Any help is appreciated.

share|improve this question
Thanks for all the suggestions - in the end the one that worked for me was another question/answer on this forum. stackoverflow.com/questions/278237/… Basically attaching to the foreground thread, bringing mine to the top and giving it focus, then detaching from that thread. –  Sam Oct 29 '09 at 13:10
add comment

3 Answers

Sounds like your main window doesn't always get the focus back from the splash screen. Have you tried simply calling SetFocus in the main form's OnLoad handler?MSDN

share|improve this answer
By jove I think you've got it. I thought the Activate method gave a form focus as well but from reading the docs it says "Activating a form brings it to the front if this is the active application, or it flashes the window caption if this is not the active application." It's going to suck if this is all it was - I feel like an utter novice... –  Sam Sep 27 '09 at 23:18
Sadly this didn't work in the end. It might work on my dev machine but not another dev's machine or the tester's system. –  Sam Sep 28 '09 at 17:33
add comment

You should probably have the splash screen set focus to the main app window as it is going away.

As far as Window's knows your splash screen IS your app since it's the first toplevel window shown after the process is started. So that window gets the focus, but any OTHER window trying to grab focus on that same app startup (the icon click/run command) is believed to be a focus thief.

You can get around this by having the window that Window's believes has a right to have focus be the one to transfer focus to a new window.

So you splash should SetFocus on the main window BEFORE the splash is destroyed. If you destroy the focus window, then the focus is nowhere, which is probably what is happening currently in your app.

share|improve this answer
add comment

I just corrected a similar problem. Just make sure your splash screen closes after your main form as shown (it will show in background of the splash if your splash is "always on top").

share|improve this answer
add comment

Your Answer


