简体   繁体   中英

C++ Set window below (or above) the icons on the desktop

I'm trying to place a window either above or below the icons on the desktop. I mostly just want it to stay attached to the desktop at all times. Similar to Rainmeter or Wallpaper engine. So far, everything I tried either disables interaction, or gets minimized when you use the "Show Desktop" button. Any ideas on how to achieve this? I'm using electron and a native module in node to do this.

It's an old subject, but I'll find out how to do it recently and answer it.

The method is to find the handle of SHELLDLL_DefView , the parent of the desktop window, and then make the SHELLDLL_DefView handle the parent of my window to fix it to the desktop.

The method is to find the handle of SHELLDLL_DefView , the owner of the desktop window, and then make the SHELLDLL_DefView handle the owner of my window to fix it to the desktop.

SHELLDLL_DefView is located under the Progma or WorkerW handle. This is a code to prevent ShowDesktop from being used in the Electget package created by ffi-napi to attach the Electron browserWindow to the desktop.

const GWLP_HWNDPARENT = -8;

// find SHELLDLL_DefView in Progma
const progman = user32.FindWindowExA(ref.NULL, ref.NULL, 'Progman', ref.NULL);
let defView = user32.FindWindowExA(progman, ref.NULL, 'SHELLDLL_DefView', ref.NULL ); 

// find SHELLDLL_DefView in WorkerW    
if (!defView) {
  const desktopHWnd = user32.GetDesktopWindow();
  let workerW = 0;
  do {
    workerW = user32.FindWindowExA(desktopHWnd, workerW, 'WorkerW', ref.NULL); 
    defView = user32.FindWindowExA(workerW, ref.NULL, 'SHELLDLL_DefView', ref.NULL );
  } while (!defView && workerW);
}

if (!defView) return false;

// make the SHELLDLL_DefView handle the parent of my window
user32.SetWindowLongPtrA(hWnd, GWLP_HWNDPARENT, defView);

This allows you to create a window where you can click and interact without being hidden by ShowDesktop.


2022-03-29

There was a wrong word, so I corrected it. According to doc , it is not a parent window, but an owner window. In the doc , it is strange that the GWLP_HWNDPARENT constant is related to the parent window. However, when tested with Spy++ , the corresponding constant changes the owner window.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM