0

Is there a way to make an WPF application persist on top of the desktop when one uses the show desktop shortcut (WINDOWS+D) on windows?

I am trying to make an desktop overlay application with widgets. (Same concept as rainmeter) I currently am using functions in user32.dll to keep the window positioned on top of the desktop.

This works perfectly fine until i use WINDOWS+D

I've tried:

  • On the window Deactivated event, inserting the window's position above the Desktops position

  • Parenting the window to the desktop

Any suggestions would be greatly appreciated!

Ruben Versavel
  • 161
  • 2
  • 12

1 Answers1

3

One (possibly dirty) way would be to register a hotkey to capture a WIN+D call as suggested in this answer: https://stackoverflow.com/a/824395/12167858

Once you have a way to capture the hotkey you can find out whether or not its trigger-event fires before or after the native WIN+D response (showing the desktop).

I did not test this myself just yet, however, if it does fire after the native response, you're good to go. Otherwise, if such a solution would be acceptable, you could use a Task.Delay() to wait for Windows to finish minimizing all visible windows.

/edit: I forgot the critical part: Once you have ensured that Windows is done doing its things, call the code below (as suggested here: https://stackoverflow.com/a/6837421/12167858) to get the window back to its original state:

if (myWindow.WindowState == WindowState.Minimized)
myWindow.WindowState = WindowState.Normal;
Skelp
  • 121
  • 5
  • Hello! Thanks for replying I have managed to get global hotkey capturing working for windows+d. When i execute the code you have provided nothing happens. The window state was and stays `WindowState.Normal` before and after the execution of the windows + d shortcut. It seems that the Z-Index of the desktop gets increased to hide all other windows. – Ruben Versavel Oct 07 '19 at 18:59