I'm making an app that displays what keys you are pressing, and I was wondering if there was a way to overlay some image widgets on top of the screen so that they stay on top even when you are in full screen mode. I'm using WPF with Visual Studio. A link to a tutorial or a download to an example would help a ton!
Asked
Active
Viewed 2,064 times
1 Answers
0
You haven't clarified whether you want the widgets to appear over top of all windows, or just your WPF one.
If you want it to appear over just your window then look into use an adorner.
If you want it to appear over all windows then use this WindowSinker class which intercepts the WM_SETFOCUS message for your window and calls SetWindowPos to set the HWND_TOPMOST flag.

Mark Feldman
- 15,731
- 3
- 31
- 58
-
Will the widgets still be able to display over apps that are in fullscreen mode? – LegendaryWolf43 Mar 09 '21 at 04:45
-
Yes. I've used this in multiple production environments to display WPF windows that appear over top of all all other applications running on the system, including apps running in full-screen mode. – Mark Feldman Mar 09 '21 at 09:45
-
I replaced every "HWND_BOTTOM" to "HWND_TOPMOST" in the Window Sinker class. I tried using it on my window by putting the following on Window_Loaded `WindowSinker.WindowExtensions.SetSinker(???, Topmost);` For the question marks its asking me for a dependency object. What do I put there? – LegendaryWolf43 Mar 13 '21 at 22:54
-
I used the WindowSinker class in that answer as is, with no changes. Then, in the WPF window that I needed to keep on top I created a member variable: `WindowSinker sinker;`. Finally, in that window's constructor I did `sinker = new WindowSinker(this);`, then `sinker.Sink();`, followed by the usual `InitializeComponent();`. – Mark Feldman Mar 16 '21 at 09:35
-
Also, make sure you're using the code in James M's answer, which I linked to directly, not the accepted answer. It contains code for 2 classes i.e. `WindowSinker` and `WindowExtensions`. – Mark Feldman Mar 16 '21 at 09:40