Qt Need to bring Qt application to the forefront from win32 application

I have a simple win32 application that uses the createProcess method to invoke a Qt application.

The problem is that I like to bring the Qt application to the forefront.

Who is responsible for this? Win32 parent application or Qt application?

+3
source share
3 answers

An application that currently has foreground focus is the only one that is allowed to change foreground focus. You need to use the SetForegroundWindow function to realize this right.

The Notes section of the documentation contains an applicable list of restrictions:

The system limits which processes can set the foreground window. A process can set a foreground window only if one of the following conditions is true:

  • The process is a foreground process.
  • The process was started by the foreground process.
  • The process received the last input event.
  • There is no foreground process.
  • The foreground process is being debugged.
  • The foreground is not locked (see LockSetForegroundWindow ).
  • SPI_GETFOREGROUNDLOCKTIMEOUT (see SPI_GETFOREGROUNDLOCKTIMEOUT in SystemParametersInfo ).
  • There is no menu.

An application cannot force a window in the foreground while the user is working with another window. Instead, Windows flashes a window taskbar button to notify the user.

The real question is why you should do this at all. Changing the foreground application is likely to cause you problems with all the restrictions that Windows places on it, or with your users. This is a very dangerous action for the user, which is one of the reasons why Windows has tightened its restrictions in recent years.

+3
source

Get the handle to the Qt application window and call SetForegroundWindow

http://msdn.microsoft.com/en-us/library/ms633539.aspx

+2
source

You probably want to do this from the parent process. The cleanest / most reliable way to use SetForegroundWindow is to call it from a process that is currently in the foreground.

0
source

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


All Articles