C++ Windows11 Zugriff auf Desktophintergrund



  • Hallo liebes Forum,

    unter Windows 95/98 bis Windows 10 war es bisher kein (großes) Problem, mittels z.B. FindWindowA(...) etc. auf das Fensterhandle des Desktophintergrundes zuzugreifen oder einen hierfür nach meinem Kenntnisstand von MS undokumentierten "WorkerW-Hack" zu nutzen, um ein HDC zu erzeugen bzw. sich das HDC zu nehmen und mittels GDI, OpenGL oder DirectX hierein zu zeichnen. So habe ich schon einige, zum Teil auch schon recht ansprechende, animierte Desktophintergründe erstellt, welche schön hinter den Desktopsymbolen des Progman ihre Animationen darstellen (einfache bis komplexe Shader oder "kleine" 3D Animationen - das spielt hier aber erstmal keine Rolle).

    Seit der Installation von Windows 11 versuche ich nun immer mal wieder, Teile meines alten Quellcodes, welcher unter Windows 10 auch immer noch einwandfrei läuft, auch unter Windows 11 zum Laufen zu bekommen - doch bisher leider nur erfolglos. Die Programme melden keine Fehler und machen halt nur für den User unsichtbar im Hintergrund, was sie sollen. Sie schreiben das Ergebnis meiner Grafikoperationen in das Fenster, welches ich (hier für Windows 10) mit der Funktion "FindDeskWorkerW()" hierfür bereitstelle:

    HWND FindDeskWorkerW() {
    	HWND progman = FindWindowA("Progman", NULL);
    	SendMessageTimeoutA(progman, 0x052C, 0, 0, SMTO_NORMAL, 1000, NULL);
    	Sleep(100);
    	HWND shellWorkerW = NULL;
    	shellWorkerW = FindWindowExA(NULL, NULL, "WorkerW", NULL);
    	while (shellWorkerW) {
    		HWND shellView = FindWindowExA(shellWorkerW, NULL, "SHELLDLL_DefView", NULL);
    		if (shellView) {
    			HWND wallpaperLayer = GetWindow(shellWorkerW, GW_HWNDNEXT);
    			char className[256];
    			GetClassNameA(wallpaperLayer, className, 256);
    			if (std::string(className) == "WorkerW") {
    				doDebug("Search", "Hintergrund-Layer gefunden. Setze Parent.");
    				return wallpaperLayer;
    			}
    		}
    		shellWorkerW = FindWindowExA(NULL, shellWorkerW, "WorkerW", NULL);
    	}
    	return progman; // Fallback, falls was schief geht....
    }
    

    Zum Suchen des richtigen Windowhandles habe ich ein kleines Programm geschrieben, welches rekursiv durch alle unter Windows vorhandenen HWND's inkl. Kinder, Enkel und Schwesterfenster (die ganze Familie 🤣 ) iteriert und jeweils mittels GDI ein kleines rotes Quadrat(10,10,110,110) mittels fillrect() darstellt und evtl. Zugriffsfehler, welche hier durchaus auftreten können, abfängt. Leider konnte ich auch mit diesem "Desktophintergundbild-HWND-Suchprogramm" kein rotes Quadrat sehen - weder die Symbole des Progman noch des Wallpaper wurden rot eingefärbt oder zeigten irgendwelche ungewöhnlichen Grafik-Fragmente... einige zum testen geöffnet Fenster (Notepad, Chrome, Outlook, ...etc.) zeigten mir rote Quadrate bzw. teilweise auch nur Fragmente davon, aber der Desktop selbst und die Desktopsymbole des Progman blieben sauber - was ich schon sehr komisch fand... wo wird in Windows11 der Desktophintergrund hin gerendert oder die in den Anzeigeeinstellungen einstellbare Foto-Diashow ?

    Auch unter Einsatz von Copilot & Co. konnte ich bisher hier keine positiven Ergebnisse unter Windows 11 erzielen. Daher nun mal die Frage ins Forum - vielleicht hat das ja schonmal jemand von euch hinbekommen oder kennt eine API-Schnittstelle von Windows, welche auf den richtigen Speicherbereich der Grafikkarte zeigt, in welchem sich das Hintergrundbild aktuell befindet.

    Für jeglichen Tip in die richtige Richtung wäre ich sehr Dankbar.



  • Eine direkte Antwort habe ich nicht, aber mal ChatGPT dazu befragt:

    Is there a possibility to create shader effects or 3D animations on the desktop (but behind the icons) in Windows 11?

    Yes, it's possible to create shader effects or 3D animations on the desktop behind the icons in Windows 11, but there are certain limitations and challenges due to the way Windows handles the desktop environment. The desktop is managed by the Desktop Window Manager (DWM), and custom graphics rendering like shaders and 3D animations isn't natively supported as part of the system’s user interface. However, you can still achieve these effects using third-party software and some creative techniques.

    Let's explore a few methods and approaches for adding shader effects and 3D animations behind desktop icons.

    1. Using Third-Party Software for Shader and 3D Effects

    Third-party tools and programs can give you the ability to create animated or 3D wallpapers, or even shaders that work behind desktop icons. These programs utilize your graphics card to render the effects and allow for complex animations or 3D scenes.

    Wallpaper Engine (Shader & 3D Support)

    • Wallpaper Engine is an extremely powerful and popular tool for creating and managing animated wallpapers. It allows you to create and apply complex 2D, 3D, and even shader-based effects behind your desktop icons.

    • 3D and Shader Support:

      • Wallpaper Engine supports 3D scenes with full camera control and interactive elements.
      • You can create shader-based effects by writing custom GLSL (OpenGL Shading Language) shaders, which can be applied to the background.
      • It also supports interactive and reactive wallpapers, meaning the wallpaper can respond to system events, mouse movements, or even touch input.

      How to Use:

      • Install Wallpaper Engine (available on Steam).
      • You can create your own 3D animated scenes using built-in tools, or import models and textures.
      • You can write custom shaders using GLSL or HLSL for more advanced effects.
      • Once your scene is created, set it as your desktop wallpaper. It will render behind your desktop icons and adjust based on the settings you specify.

      Example Shader:
      You can create a simple shader effect like a wavy water effect on the background, or apply post-processing shaders such as bloom, distortion, or motion blur to create a more dynamic look.

    Lively Wallpaper (Free, with Shader Support)

    • Lively Wallpaper is a free and open-source alternative to Wallpaper Engine that also supports animated backgrounds. You can use it to set 3D animations, video wallpapers, and interactive shaders.

    • Shader & 3D Support:

      • It allows custom shaders in GLSL, making it a powerful tool for creating interactive or dynamic backgrounds using code.
      • You can also use web-based content (HTML5, JavaScript, and CSS) to create animated and 3D scenes on the desktop.

      How to Use:

      • Download and install Lively Wallpaper from Microsoft Store or GitHub.
      • Import 3D scenes, videos, or GIFs, and adjust the settings to place them behind your desktop icons.
      • If you know how to write shaders, you can use GLSL in Lively to create real-time effects.

    DeskScapes (Shader Effects)

    • DeskScapes (by Stardock) is another paid tool that lets you apply animated, 3D, and even shader-based effects to your desktop wallpaper.

    • Shader Effects:

      • DeskScapes offers the ability to create custom animations and shader effects. You can apply shaders to static or animated wallpapers.
      • It also supports video backgrounds, giving you a lot of flexibility to create dynamic and interactive wallpapers.

      How to Use:

      • Install DeskScapes.
      • You can either import custom videos or create your own shader effects.
      • Set the shader effects or 3D animations as your desktop background.

    2. Using DirectX or OpenGL for Custom Shaders (Advanced)

    For users who want a high degree of customization and control over the effects and 3D animations behind the icons, you can create your own DirectX or OpenGL application that runs on the desktop. This approach would require a fair bit of programming expertise, as you'll need to manually handle the creation of the shaders and ensure they render behind the icons.

    Steps for Creating Custom Shaders Using OpenGL/DirectX:

    • Create a Full-Screen Window:

      • You can create a borderless, transparent window that takes up the entire screen, but doesn’t cover the desktop icons.
      • The transparency can be achieved by setting the window's style to WS_EX_LAYERED (with SetLayeredWindowAttributes) and making the window background transparent.
    • Render 3D Effects or Shaders:

      • Using OpenGL or DirectX, you can render complex 3D scenes, particle effects, or shaders.
      • For shader effects, you would write your shader code (using GLSL for OpenGL or HLSL for DirectX), and apply it to a full-screen background.
      • You can use libraries like GLFW (OpenGL) or DirectX 11/12 (DirectX) to handle the rendering.
    • Ensure Desktop Icons Are Visible:

      • The key challenge here is to ensure that the desktop icons remain on top of the rendered content. To achieve this:

        • You can use DirectComposition in Windows to overlay the 3D scene without disturbing the desktop icons.
        • Alternatively, use the Windows Desktop Window Manager (DWM) API to ensure that the icons always appear on top of your custom background.
        • You’ll need to set your rendering window behind the desktop icons by creating a transparent or “layered” window, and then set its Z-order to be behind the desktop icons.

    Here’s a basic concept of how you might render a custom shader in OpenGL:

    #include <GL/glew.h>
    #include <GLFW/glfw3.h>
    
    // Initialize OpenGL context and window
    glfwInit();
    GLFWwindow* window = glfwCreateWindow(1920, 1080, "Desktop Background Shader", NULL, NULL);
    glfwMakeContextCurrent(window);
    glewInit();
    
    // Example of a simple shader
    const char* vertexShaderSource = "..."; // Your vertex shader code
    const char* fragmentShaderSource = "..."; // Your fragment shader code
    
    // Create and compile shaders, create program, etc.
    GLuint shaderProgram = glCreateProgram();
    // Attach, compile, and link shaders...
    
    // Rendering loop
    while (!glfwWindowShouldClose(window)) {
        glClear(GL_COLOR_BUFFER_BIT);
        
        // Apply the shader effect
        glUseProgram(shaderProgram);
        // Set uniforms and draw your 3D scene or shader effects
        
        glfwSwapBuffers(window);
        glfwPollEvents();
    }
    
    glfwTerminate();
    

    This approach gives you full control over the rendered effects, but it requires handling the complexities of transparency and desktop interactions.


    3. Interactive or Reactive 3D Effects

    You can make the shader or 3D animations interactive, such that they react to mouse movements, system events, or time-of-day changes. This can be done using:

    • Wallpaper Engine: You can create or download interactive wallpapers that respond to mouse movement, clicks, or system events.
    • Lively Wallpaper: Similar to Wallpaper Engine, you can create or download interactive HTML5-based backgrounds.

    For example, a shader could respond to the position of your mouse, or a 3D animation could change depending on the time of day (e.g., a scene with the sun setting as time passes).


    4. Limitations & Considerations

    • Performance: Shader effects and 3D animations can be demanding on your GPU, especially if the effects are complex. Be mindful of system performance when using these methods.
    • Desktop Interactions: You must be careful to ensure that desktop icons remain visible and functional. Some programs, like Wallpaper Engine, handle this well, while others might require manual adjustments.
    • System Resources: Continuous background effects, especially those using shaders and 3D rendering, will consume CPU and GPU resources. Make sure your system can handle it without significant slowdowns.

    Conclusion

    While Windows 11 doesn't natively support complex 3D animations or shader effects behind desktop icons, you can still achieve these effects using third-party tools like Wallpaper Engine, Lively Wallpaper, or DeskScapes. If you're more technically inclined, creating custom DirectX or OpenGL applications for rendering shaders and 3D scenes is also an option, although it requires advanced programming skills.

    If you want a smooth, easy-to-use solution, Wallpaper Engine or Lively Wallpaper is the way to go, offering powerful shader support and interactive 3D scenes that can sit behind your desktop icons without performance issues. Would you like more details on setting up these tools or creating custom shaders?


    Du kannst dir ja mal das Open-Source Projekt Lively Wallpaper sowie dessen Sourcen dazu anschauen.


Anmelden zum Antworten