4

I'm creating a "desktop gadget" of sorts, I've disabled manual minimizing of the window, but now there is another problem: the system can still hide the window if the user presses Windows+D, for example.

When hidden that way, no usual minimize/resize/visibility events are fired. I want to do something almost like TopMost, but without forcing the window order.

Maybe it's possible to install a global shortcut event using win32 API, and briefly set TopMost to true, but that sounds very hackish.

I found one solution, but it does not seem to work on Windows 10: Keeping window visible through "Show Desktop"/Win+D The other common option, which would be writing an actual desktop gadget, is not possible on Windows 10, given their deprecation.

Are there any other methods to keep a window visible (but not on top of the screen) at all moments?

Community
  • 1
  • 1
  • 1
    The user explicitly presses a key command for "show me my desktop"; what makes you sure that he really means "show me my desktop and this one gadget". What would happen if he had many of these gadgets, all using more screen space than available? – sisve Jan 27 '16 at 18:21
  • @SimonSvensson I am aware of all the usability concerns. This application is being developed exclusively to one specific home user that desires it to behave exactly like that. Said user already has the "Sticky Notes" from Windows 7 installed on his Windows 10 machine, and expects similar behaviour. – This company is turning evil. Jan 27 '16 at 18:24
  • 4
    Yes, a desktop gadget is what it takes. Removed from Windows. And Sticky Notes is not sticky anymore, it also gets minimized. Hopefully they pay you enough. – Hans Passant Jan 27 '16 at 18:33

1 Answers1

4

This function is working for me:

BOOL FixShowDesktop(HWND hWnd)
{
    HWND hWndTmp = FindWindowEx(NULL, NULL, L"Progman", NULL);
    if (hWndTmp)
    {
        hWndTmp = FindWindowEx(hWndTmp, NULL, L"SHELLDLL_DefView", NULL);
        if (hWndTmp)
        {
            SetWindowLongPtr(hWnd, -8, (LONG_PTR)hWndTmp);
            return TRUE;
        }
    }
    return FALSE;
}

Note, this code is a bit better then from Keeping window visible through "Show Desktop"/Win+D because the window can be overflowed by other windows (like any other window). Using SetParent places window under all other windows.

tordex
  • 41
  • 4