Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
1.44/5 (2 votes)
See more:
Hi there,

On Windows startup (using Windows 10) the window order (by Spy++) looks like this:
WorkerW
Progman
   * SHELLDLL_DefView

After pressing WIN+TAB it looks like this:
Progman
WorkerW
   * SHELLDLL_DefView

Since my program is a child of SHELLDLL_DefView and it gets semi-transparent after pressing WIN+TAB i want to get this change done per code and not suddenly by a user.

I tried this, but nothing happens:
C#
IntPtr progmanHandle = FindWindowEx(IntPtr.Zero, IntPtr.Zero, "Progman", null);
IntPtr shell = FindWindowEx(progmanHandle, IntPtr.Zero, "SHELLDLL_DefView", null);
IntPtr workerWHandle = FindWindowEx(IntPtr.Zero, IntPtr.Zero, "WorkerW", null);
SetParent(shell, workerWHandle);


Please help!
Julian
Posted
Updated 7-Sep-16 7:26am
Comments
Richard Deeming 5-Oct-15 9:36am    
Messing with the window parents, particularly at such a low level, is almost certainly the wrong thing to do.

Try explaining what you're actually trying to achieve, and someone will probably be able to tell you the right way to do it. :)
Julian Reimer 5-Oct-15 9:39am    
I want my program to replace the Windows desktop and this was the way most people did this.

1 solution

C#
private static IntPtr GetDesktopListView(){
    var hDesktop = IntPtr.Zero;
    var hProgman = W32Api.FindWindow("Progman", "");

    if (hProgman != IntPtr.Zero){
        // hProgman is usable!
        hDesktop = W32Api.FindWindowEx(hProgman, IntPtr.Zero, "SHELLDLL_DefView", 
            IntPtr.Zero);
    }
    if (hDesktop != IntPtr.Zero){
        // hDesktop is usable!
        return W32Api.FindWindowEx(hDesktop, IntPtr.Zero, "SysListView32", 
            IntPtr.Zero);
    }

    // If we reach this point, that means that "SHELLDLL_DefView" is NOT a sibling
    // of "Progman"! Now we gotta spawn "WorkerW" from "Progman" (Windows 7 and beyond)
    // (shhhh... this windows message is NOT DOCUMENTED!)
    const int WmSpawnWorker = 0x052C;
    W32Api.SendMessage(hProgman, WmSpawnWorker, 0, 0);

    hDesktop = W32Api.GetDesktopWindow();
    IntPtr hShellViewWin;
    var hWorkerW = IntPtr.Zero;
    do {
        hWorkerW = W32Api.FindWindowEx(hDesktop, hWorkerW, "WorkerW", IntPtr.Zero);
        hShellViewWin = W32Api.FindWindowEx(hWorkerW, IntPtr.Zero, "SHELLDLL_DefView", 
            IntPtr.Zero);
    } while (hShellViewWin == IntPtr.Zero && hWorkerW != IntPtr.Zero);
    return W32Api.FindWindowEx(hShellViewWin, IntPtr.Zero, "SysListView32",
        IntPtr.Zero);
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900