Active windows on Windows and QWidget :: activateWindow ()

The Qt documentation for QWidget::activateWindow() states:

On Windows, if you call this when the application is currently active, then it will not be this active window. It will change the color of the taskbar to indicate that the window has changed in some way. This is because Microsoft does not allow interrupting what the user is currently in another application.

However, Skype seems to violate this rule. If Skype works, but is not an active application, I can launch it from the Start menu, and it adds an existing instance to the foreground, activates it and captures the input focus.

And how can I do this?

+4
source share
4 answers

(NOTE: It depends on how QtSingleApplication works)

The solution is stupidly simple for my problem. Just call AllowSetForegroundWindow(ASF_ANY); at the beginning of the application, and the original process will thus be allowed to go to the foreground using SetForegroundWindow() . There are no weird hacks, just one line of code to add, and no need to change QtSingleApplication.

+6
source

I do not think that you can only do this reliably with the Qt API.

There are several solutions for windows. For instance. here , and here , and here .

The method that I used earlier is to declare a shared memory section and write a handle to the application window handle. Later, when the second instance of your program starts, you can find the handle to the window of the first and activate it.

I don’t think you have a problem with Windows so that you don’t do this in this case, because your second instance is an active application, therefore it is allowed to “transfer focus” to other windows.

+1
source

Use One Application in Qt Solutions

For some applications, it is useful or even critical that they are run only once by any user. Future attempts to launch the application should activate any instance that is already running, and possibly complete an action request, for example. loading a file into an instance.

0
source

you can set setWindowOpacity from 0 to 1. The only thing you can open it all the time

-1
source

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


All Articles