Set focus on my application

I have an application that will basically work in the background. I want certain system events to be handled to make the application steal focus using the foreground application, whatever it is. But UIElement.Focus () seems to only set focus in a WPF application. That is, if the WPF application already has focus as a whole, then Focus () focuses on the right control. But I need to steal focus from another application and put it in my application. How can i do this?

I do not need a system modal dialog. That is, after the window steals focus, it should be possible for the user to immediately switch to another application without rejecting the window of my application.

An application can already be restored, minimized, or even “minimized” when it needs to steal system focus. Assume that it is minimized, and focus theft during window restoration is unacceptable.

+3
source share
1 answer

If you don't mind doing som p / invokes, the function SetForegroundWindowshould help you:
http://pinvoke.net/default.aspx/user32/SetForegroundWindow.html

+6
source

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


All Articles