Demonstrates implementation of the Windows 10 Acrylic Effect on C++ Win32 Apps using DWM Private APIs and Direct Composition

Overview

Win32 Acrylic Effect

A Demonstration of Acrylic Effect on C++ Win32 applications using Direct Composition and DWM private APIs.

Table of Contents
  1. Overview
    • A Short History
    • About This Project
  2. Possible Methods
    • SetWindowCompositionAttribute()
    • Windows.UI.Composition - Interop
    • Windows Maginification API
    • Desktop Duplication API
    • DWM Private APIs
  3. Backdrop Sources
    • Desktop Backdrop
    • Host Backdrop
  4. Features
  5. Known Limitations
  6. Supported Versions

Overview

sample

A Short History

The Windows 10 Acrylic Effects was first introduced on UWP Apps after the Windows Fall Creators Update on 2017, Since Then Developers were trying to implement the acrylic effect on normal Windows Applications such as WPF, Win32 etc.The most Commonly used method was SetWindowCompositionAttribute(), but it didn't last long, from Windows 10 1903 the window starts to become laggy while dragging (This issue seems to be fixed in windows insider previews but not on any stable versions of windows).

About This Project

This project is just a demonstration about implementing (or possible ways to implement) a custom acrylic effect on Win32 Application using DWM APIs and Direct Composition. This is just a basic implementation, Still there is a lot of room for improvement such as noise overlay and other blending effects. We will also discuss about possible ways to achieve Acrylic Effects.

Possible Methods

There are different ways to achieve Acrylic Effect on Windows 10 and some might be able to work on Windows 7,8 (i haven't tested yet).

SetWindowCompositionAttribute()

SetWindowCompositionAttribute() is an undocumented api in windows which allows us to enable Acrylic Effect, DWM Blur (same as DwmEnableBlurBehindWindow()) and transparency for Window. Since it is an undocumented API this api might be changed or removed in future versions of windows. As i had mentioned earlier creating acrylic effect using this API will cause lag while dragging or resizing window, And also the blur effect will disappear during maximize until the window is completely maximized

Windows.UI.Composition - Interop

The Windows.UI.Composition-Win32-Samples on microsoft repository actually provides a way to implement acrylic effect on Windows Forms and WPF. This was one of the closest way to achieve acrylic effect in WPF. But WPF uses diffrent rendering technology and the acrylic effect is rendered using direct composition, So it always cause Airspace Issue. There is only two possible ways to overcome this issue:

1. Overlapping Windows:

You can create multiple WPF windows one for rendereing the WPF Content and one for Acrylic Effect, These windows should be transparent and must communicate with each other to sync the window resize, window drag and other events, this is possible by overriding WndProc. But this method will cause Flickerng on resize and also affects the Acrylic Effect during maximize animation. (This has been tested before)

2. WPF Swapchain Hack:

This is another possible way that i haven't tested yet, but theoretically it might be working. This can be done by hacking into WPF Swapchain to obtain its back buffer and copy it into an ID2D1Bitmap or similar and then passing it to the Windows.UI.Composition.Visual by using somethng like Composition Native Interoperation. By this way we may be able to overcome the Airspace Issue with WPF Acrylic Effect. ( ๐Ÿ˜… The truth is Currently i was only able to get the swapchain backbuffer from WPF)

Windows Maginification API

The Windows Manification API can also provide the visual behind a window (Backdrop) by using the MagImageScalingCallback(), but it has been deprecated after windows 7.There might be a chance for creating the blur effect on windows 7 by passing the bitmap obtained from MagImageScalingCallback() to D2D1Effects such as gaussian blur. The MagImageScalingCallback() also throws exception if the source rectangle coordinates is out of desktop coordinates.

Desktop Duplication API

The Windows Desktop Duplication API is also one possible way for creating an acrylic effect, The Desktop Duplication API can be used to capture the entire desktop including the window itself, but on windows 10 2004 Edition Microsoft has added a new parameter WDA_EXCLUDEFROMCAPTURE in SetWindowDisplayAffinity() function which will help us to capture the whole desktop but excluding the windows for which WDA_EXCLUDEFROMCAPTURE is applied. But everything comes with a price, by doing so you wont be able to capture that window by screenshot or screencapture and earlier versions of windows doesn't support WDA_EXCLUDEFROMCAPTURE.

DWM Private API

The dwmapi.dll consist of some private api which can be used to capture each windows or a group of windows into an IDCompositionVisual. If you decompile the dwmapi.dll using some decompiler like IDA By HexRays and explore DwmEnableBlurBehindWindow() function you will be able to find DwmpCreateSharedThumbnailVisual() function which helps us to capture a window into IDCompositionVisual. In this sample we mainly use two functions DwmpCreateSharedThumbnailVisual() and DwmpCreateSharedVirtualDesktopVisual() for creating the visual and we use DwmpUpdateSharedVirtualDesktopVisual() and DwmpUpdateDesktopThumbnail() for updating the visual.

A special thanks to ADeltaX for the implementation.(DWM Thumbnail/VirtualDesktop IDCompositionVisual example)

Once the visual is obtained, The graphics effect such as Gaussian blur,Saturation etc.. is applied to the visual and finally it is rendered back to the window by using Direct Composition. This method also has several limitations such as Airspace Issue while using with other platforms like WPF.

Backdrop Sources

In this sample we have defined two backdrop sources for acrylic effect, They are:

1. Desktop Backdrop

A Desktop Backdrop use the desktop visual as the source for acrylic effect. so no other windows under the host window will be captured for blurring. it will be the plain desktop wallpaper. This is done by using DwmpCreateSharedThumbnailVisual().

2. Host Backdrop

A Host Backdrop uses Desktop Backdrop as the background visual and also captures all the windows which are under the host window for blurring. This is done by using DwmpCreateSharedVirtualDesktopVisual() function.

You can adjust the backdrop source in this example using BackdropSource enum.

// For Host Backdrop
compositor->SetAcrylicEffect(hwnd, AcrylicCompositor::BACKDROP_SOURCE_HOSTBACKDROP, param); 
// For Desktop Backdrop
compositor->SetAcrylicEffect(hwnd, AcrylicCompositor::BACKDROP_SOURCE_DESKTOP , param);     

Features

  • Reduced flickering while resizing or dragging
  • Multiple Backdrop Sources
  • You can exclude a particular window from acrylic like the host window does for itself.

Known Limitations

  • Sometimes the Desktop icons are missing in the acrylic effect.
  • There is no straight way to implement this in WPF or Win UI3.
  • Airspace Issue : Currently you can only use Direct Composition to draw something on top of acrylic effect.
  • Realtime Acrylic not supported, which means the host window redraw acrylic only when it is activated so fallback color is used.
  • Exclusion Blending and Noise effect not added (Can be implemented)

Supported Versions

This sample has been currently tested on:

Operating System Version Build
Windows 10 Pro 20H2 19042.1052

Join with us ๐Ÿšฉ

You can join our Discord Channel to connect with us. You can share your findings, thoughts and ideas on improving / implementing the Acrylic Effect on normal apps.

You might also like...
This is no malware, This is no virus. This is my implementation of the effect from Mrs.Major3.
This is no malware, This is no virus. This is my implementation of the effect from Mrs.Major3.

BloodMelter This is no malware, This is no virus. This is a very small effect of very small blood for a some PC. Table Of Contents Preview About Warni

A simple thread-safe implementation of runtime obfuscation for Win32 applications.
A simple thread-safe implementation of runtime obfuscation for Win32 applications.

Thread-Safe Win32 Runtime Obfuscation A simple thread-safe implementation of runtime obfuscation for Win32 applications. The main use case for this is

A simple utility that cold patches dwm (uDWM.dll) in order to disable window rounded corners in Windows 11

Win11DisableRoundedCorners A simple utility that cold patches the Desktop Window Manager (uDWM.dll) in order to disable window rounded corners in Wind

Celeborn is a Userland API Unhooker that I developed for learning Windows APIs and Syscall implementations

Celeborn is a Userland API Unhooker that I developed for learning Windows APIs and Syscall implementations. It mainly detects and patches hooking instructions in NTDLL.dll file. All PRs are welcome!

GameBoy emulator with debugger written in C++ using Win32 and SDL2
GameBoy emulator with debugger written in C++ using Win32 and SDL2

่„ณ(ใฎใ†)่…(ใต) DMG-01 emulator written in modern C++ using Win32 API and SDL2. It is intended as a hobby project to sharpen my C++ skills. The emulator is

Implementation of Monocular Direct Sparse Localization in a Prior 3D Surfel Map (DSL)

Implementation of Monocular Direct Sparse Localization in a Prior 3D Surfel Map (DSL)

A tool for detecting manual/direct syscalls in x86 and x64 processes using Nirvana Hooks.
A tool for detecting manual/direct syscalls in x86 and x64 processes using Nirvana Hooks.

manual-syscall-detect A tool for detecting manual/direct syscalls in x86 and x64 processes using Nirvana Hooks. Description A full write-up of this to

This repository gives an idea about how to use UART/SPI/I2C communication using HAL APIs

STM32-UART-SPI-I2C communication with Arduino board using HAL APIs This repository gives an idea about how to use UART/SPI/I2C communication using HAL

A framework for building native Windows apps with React.
A framework for building native Windows apps with React.

React Native for Windows Build native Windows apps with React. See the official React Native website for an introduction to React Native. React Native

Comments
  • How to exclude a specific window from the Acrylic background?

    How to exclude a specific window from the Acrylic background?

    Hi bro, I'm still trying the overlap windows, but I found the foreground window will also become part of the acrylic background, it looks weird, could you please teach me how can I exclude it from the acrylic effect?

    Maybe I should use the following variable?

    https://github.com/Extrimis/Win32-Acrylic-Effect/blob/4aee11e6eab7fa5257114bfd47ff72d2746a82c2/Acrylic%20Window/AcrylicCompositor.h#L146

    opened by wangwenx190 10
  • BUG: Some cleanup is needed when closing the window

    BUG: Some cleanup is needed when closing the window

    Hi, bro, thanks for the fantastic repo! It's quite impressive!

    But when I was debugging this repo in Qt Creator, I got some warning messages when the window is closing:

    DXGI WARNING: Process is terminating. Using simple reporting. Please call ReportLiveObjects() at runtime for standard reporting. [ STATE_CREATION WARNING #0: ]
    DXGI WARNING: Live Producer at 0x0000025575ED72E8, Refcount: 4. [ STATE_CREATION WARNING #0: ]
    

    Looks like some cleanup is needed at window shutdown. Do you have any clue of how to fix it?

    BTW, I'm using a 4K monitor and I set scale factor to 250%, I found that the acrylic background is too large. But if I set dpi awareness to PerMonitorV2 programtically, it looks normal again. Maybe you should fix this as well. But using the manifest file is easier.

    good first issue 
    opened by wangwenx190 7
  • Usage in OpenGL application

    Usage in OpenGL application

    This works brilliantly in a stand-alone window, however when I try to implement it in an OpenGL & GLFW window , any objects drawn by OpenGL do not appear . Any ideas what could be wrong? (Windows 10 21H1 )

    opened by MayaankAshok 3
  • Different render on different monitors at same computer

    Different render on different monitors at same computer

    I have 3 monitors

    • 1 - fullHD(horizontal)
    • 2 - 4k (main)(horizontal)
    • 3 - fullHD(vertical)

    Results:

    image

    image

    image

    Also. At main monitor (2) - not focus background became black, but on 1/3 all ok.

    Thanks

    bug 
    opened by VISTALL 13
Owner
Selastin
Selastin
Acrylic & aero blur effect on Flutter Windows ๐Ÿ’™.

flutter_acrylic Acrylic & aero blur effect on Flutter Windows. Installation Mention in your pubspec.yaml.

Hitesh Kumar Saini 441 Jan 8, 2023
matrix-effect This is a dumb matrix effect type thing

matrix-effect This is a dumb matrix effect type thing. It's only like one source file which should compile... Define __POSIX or __WIN though, for posi

null 42 Sep 23, 2022
My build of dwm based on dwm-flexipatch.

This dwm 6.2 (67d76bd, 2021-03-29) side project has a different take on dwm patching. It uses preprocessor directives to decide whether or not to incl

Utkarsh Verma 3 Oct 20, 2022
find likely coding segments in DNA using composition-normalised hexamer tables

hextable makes files of statistics that hexamer uses to scan for likely coding regions

Richard Durbin 14 Jan 21, 2022
stacked acrylic gasket mounted ergonomic keyboard

Splay46 Build guide This keyboard requires soldering of really small smd components like USB Type C Receptacle(0.3mm pitch), Atmega32U4(0.8mm pitch),

kobakos 41 Jan 6, 2023
A Windows user-mode shellcode execution tool that demonstrates various techniques that malware uses

Jektor Toolkit v1.0 This utility focuses on shellcode injection techniques to demonstrate methods that malware may use to execute shellcode on a victi

null 95 Sep 5, 2022
A creative composition studio for Scheme hackers.

Flux Compose A creative composition studio for Scheme hackers. What is it? This project is (or more accurately, will be) a studio for creative composi

Flux Harmonic 20 Sep 21, 2022
iconv implementation using Win32 API to convert.

win_iconv is a iconv implementation using Win32 API to convert. win_iconv is placed in the public domain. ENVIRONMENT VARIABLE: WINICONV_LIBICON

null 167 Jan 1, 2023
List & Read the processes memory using Windows APIs (PSAPI/ToolHelpAPI/WTSAPI)

Dumper List & Read the processes memory using Windows APIs PSAPI ToolHelp WTSAPI Usage The Dumper tool list the running procceses and provide the abil

ใƒ ใƒใƒณใƒžใƒ‰ 6 Dec 6, 2022
Tiny blocker of Windows tracking and telemetry written in plain C++/Win32 API.

Tiny blocker of Windows tracking and telemetry written in plain C++/Win32 API. Just run once as admin and forget. No questions asked. No harmful actions performed like other Windows spying blockers try.

null 6 Dec 23, 2022