How to intercept the “Show Desktop” event?

2020-07-30 02:06发布

问题:

I'm looking for a way to intercept the ShowDesktop event and set my window at front. Is there a way doing it without using API hooks? Thanks, Omer.

回答1:

If you're writing a Windows taskbar style dock then simply make sure your window has WS_EX_TOPMOST set and 'Show Desktop' will leave it alone. Alternatively use SetWindowPos to make it the top-most window after it has been created, e.g.:

SetWindowPos(hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE); 

Update: You need to use the Windows Application Bar API to make a 'dock' style app. See here for more details.

Application bars also need to be removed from the top-level list displayed when you Alt+Tab etc, which can be done by adding the WS_EX_TOOLWINDOW and removing WS_EX_APPWINDOW.

I should of made this clear earlier, apologies.