The question is that the application does not receive focus in XP / W2K3

I have an application written in .NET. There was no problem in the previous version: you double-click on the icon or launch it from the command line, and when it starts, this is the main window and has focus, as you would expect.

The latest version displays a splash screen in front of the main window, and now the splash screen appears in the foreground, but the main thing does not always end in the main window. Sometimes this happens, sometimes it is not. (When launched from the command line, it invariably does not work). When the main window does not come to the fore and focus, the taskbar icon appears as orange.

I see a lot of hits on the network about how MS added a tool to prevent the focus of applications from being stolen from others, in the center of which is the ForegroundLockTimeout registry setting and related settings, but the above-described behaviors for different versions occur on the same computer.

I tried calling Activate in the main form when it was finally created, as well as SetForegroundWindow, all to no avail.

Any help is appreciated.

+3
source share
3 answers

You should probably have the focus set on the screen of the main application window when it leaves.

Window , , , . , , , ( click/run icon), .

, , Window , , .

, SetFocus , . , , , , .

+4

, . SetFocus OnLoad? MSDN

+2

I just fixed a similar problem. Just make sure that your splash screen closes after your main form, as shown (it will be displayed on a splash background if your splash is β€œalways on top”).

+1
source

Source: https://habr.com/ru/post/1718658/


All Articles