How to keep a window visible at all times, but not force it to be on top

I am building a "desktop gadget", I have disabled manual minimization of the window, but now there is another problem: the system can still hide the window if the user presses Windows+ D, for example.

Hiding this method does not fire normal minimize / resize / visibility events. I want to do something almost like TopMost

but without forcing the order of the window.

It might be possible to set a global shortcut event using the win32 API and shortly set TopMost

to true, but that sounds very hacky.

I found one solution, but it doesn't seem to work on Windows 10: Watching the window via Show Desktop / Win + D  Another common option that would write an actual desktop gadget is not possible on Windows 10 given their outdated behavior.

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

+2


source to share


1 answer


This function works 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 slightly better than Watching the window visible via Show Desktop / Win + D , as the window can be overflowed with other windows (just like any other window). Using the SetParent window for all other windows.

+3


source







All Articles