Skip to content

Window transparency doesn't work on Windows 10 #260

Closed

Description

@sbercx

The DwmEnableBlurBehindWindow method for making windows transparent on Windows doesn't seem to work on Windows 10 anymore. On Windows 10 the DwmExtendFrameIntoClientArea function can be called with the margins set to -1 to make it fully transparent.

EDIT: The new method only works if the window decorations are disabled.

Activity

  1. added
    DS - win32
    S - enhancement
    on Aug 17, 2017
  2. LYP951018 commented on Jan 22, 2018

    @LYP951018

    I'm trying to implement this by GetProcAddress in runtime. But should we cache kernel32 module handle in winit? Otherwise we may need to call LoadLibrary(or GetModuleHandle) every time the method is called.

  3. retep998 commented on Jan 22, 2018

    @retep998
    Contributor

    Use lazy_static to lazily load kernel32.dll and keep the handle to it around and do the same for each of the function pointers. Never let go.

  4. added
    H - help wanted
    D - hard
    P - normal
    on May 6, 2018
  5. haudan commented on Jun 18, 2018

    @haudan

    I will attempt to fix this as part of #568.

  6. subnomo commented on Oct 13, 2018

    @subnomo
    Contributor

    I've enabled transparency using layered windows. It works with window decorations, as well. See my patch:

    diff --git a/src/platform/windows/window.rs b/src/platform/windows/window.rs
    index 259376f4..a227c090 100644
    --- a/src/platform/windows/window.rs
    +++ b/src/platform/windows/window.rs
    @@ -905,6 +905,10 @@ unsafe fn init(
             ex_style |= winuser::WS_EX_NOREDIRECTIONBITMAP;
         }
     
    +    if attributes.transparent {
    +        ex_style |= winuser::WS_EX_LAYERED;
    +    }
    +
         // adjusting the window coordinates using the style
         winuser::AdjustWindowRectEx(&mut rect, style, 0, ex_style);
     
    @@ -959,6 +963,11 @@ unsafe fn init(
                                                   format!("{}", io::Error::last_os_error()))));
             }
     
    +        if attributes.transparent {
    +            let opacity = 100; // transparency value 0-255
    +            winuser::SetLayeredWindowAttributes(handle, 0x0, opacity, winuser::LWA_ALPHA);
    +        }
    +
             WindowWrapper(handle)
         };

    EDIT: This works if you just want a transparent window, it's not a replacement for DwmEnableBlurBehindWindow...

  7. added a commit that references this issue on Oct 18, 2018
  8. subnomo commented on Dec 8, 2018

    @subnomo
    Contributor

    @francesca64 I believe this was fixed by #675 😁

  9. added a commit that references this issue on Jan 5, 2022
    9998fe4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    D - hardDS - win32H - help wantedP - normalS - enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions