C # Getting a window with focus?

I am making a WPF application in C #, and every time users click somewhere outside my application, I want to display a warning with the title of a clicked window. To detect clicks outside my application, I use LowLevelMouseProc. But how to get a window that has focus in C #?

Thanks in advance!

EDIT: I know this is not related to my original question, but how would I also focus control?

+5
source share
2 answers

As for your subsequent question on how to get focus control, you can get HWND focused control using GetGUIThreadInfo . Note that you are passing this stream to which the external window belongs, and not the external window (the docs function tells you how to get the stream identifier from the handle of the external window). Focused HWND returns through member GUITHREADINFO.hwndFocus.

Note that in general, you cannot do better than HWND, because the foreground window is not necessarily a .NET application. For example, if the outer window is a WPF window, it will not tell you which WPF control in this window has focus, because WPF controls do not have HWND.

+3
source
+6

All Articles