Windows has built-in protection that prevents focus theft from the currently active user stream. This means that you can successfully use the Activate() form from another window that currently has focus.
For example, if a dialog box is displayed in the main window of the application, the windows will gladly make him concentrate, because the main application is simply concentrated in the same stream and can transmit this.
In the case of a splash screen, your main shape may not be a focused window for several reasons. Either because your splash screen has focus, or because the end user started downloading your application, and then started doing something else (maybe playing with his email or browser), which means that your application does not have focus generally. (Can you see the window on the taskbar trying to get focus?)
In the first case, you want your splash screen to activate the main form and then close it. (As before, to close the screen saver, and then try to activate the main form). If you mess with threads, you can also opt out of using wincon pinvoke to call SetForegroundWindow() with a window handle. You can pass a window handle around the threads. This ensures that windows respond to your focus request, since the focused form is currently making a request.
Here's a neat article on the subject of focus theft:
The only way that Windows 2000 and Windows XP allows the Application Window to go to the front is if the thread it runs on is the thread of the foreground window at that time. So, you have to attach the thread of your application to the foreground thread and then bring the application window to the foreground. After that you need to disconnect your stream (all this happens only if the user has another application window as an active foreground window). Source: Forcing Forward
Someone redid this article code in C # in this other StackOverflow post: https://stackoverflow.com/a/168389/ (It seems that some definitions for PInvoke calls are missing, but you can easily find on Google using "pinvoke" and the name of the Win32 interface you need.)
Benway
source share