nperovic / GuiEnhancerKit

Elevate your AHK Gui development with extended methods and properties.
https://github.com/users/nperovic/projects/5?pane=info
MIT License
16 stars 1 forks source link

Is it also possible to apply acrylic effect? #4

Open H5820121 opened 2 months ago

H5820121 commented 2 months ago

I would be very grateful if you could write, how you can apply for mygui an acrylic effect or other effects, Or you can't just Mica (Alt)? Thank you!

1j01 commented 2 months ago

I was able to get acrylic working by enabling DWMWA_USE_HOSTBACKDROPBRUSH and using DWMSBT_TRANSIENTWINDOW (3) instead of DWMSBT_TABBEDWINDOW (4) for the backdrop type.

#Include "./GuiEnhancerKit.ahk"

; https://learn.microsoft.com/en-us/windows/win32/api/dwmapi/ne-dwmapi-dwmwindowattribute
DWMWA_USE_HOSTBACKDROPBRUSH := 16
DWMWA_SYSTEMBACKDROP_TYPE := 38
; https://learn.microsoft.com/en-us/windows/win32/api/dwmapi/ne-dwmapi-dwm_systembackdrop_type
DWMSBT_AUTO := 0
DWMSBT_NONE := 1
DWMSBT_MAINWINDOW := 2
DWMSBT_TRANSIENTWINDOW := 3
DWMSBT_TABBEDWINDOW := 4

ShowTestWindow() {
    Win := GuiExt()

    Win.SetFont("cWhite s16", "Segoe UI")
    Win.SetDarkTitle()  ; needed for dark window background apparently, even though there's no title bar
    Win.SetDarkMenu()  ; should be unnecessary in this simple example

    Win.BackColor := 0x000000

    ; Sample content
    Win.Add("Text", "x0 y0 w300 h200 Center +0x200", "Hello, world!")

    ; Close when pressing Escape
    Win.OnEvent("Escape", (*) => Win.Destroy())
    ; Always on top makes it easy to preview the blur effect against different backgrounds.
    Win.Opt("+AlwaysOnTop -SysMenu -Caption -Border +Owner")

    ; Seem to have to show the window before enabling the blur effect
    Win.Show("w300 h200")

    ; Enables rounded corners.
    ; Doesn't seem to hide the border if the window is already shown, but `-Border` takes care of that.
    Win.SetBorderless(6)
    ; Set blur-behind accent effect. (Supported starting with Windows 11 Build 22000.)
    if (VerCompare(A_OSVersion, "10.0.22600") >= 0) {
        Win.SetWindowAttribute(DWMWA_USE_HOSTBACKDROPBRUSH, true)  ; required for DWMSBT_TRANSIENTWINDOW
        Win.SetWindowAttribute(DWMWA_SYSTEMBACKDROP_TYPE, DWMSBT_TRANSIENTWINDOW)
    }
}

ShowTestWindow()

Notes:

H5820121 commented 2 months ago

@1j01 Wonderful, thank you very much! How do I change the opacity setting? Thanks!

1j01 commented 1 month ago

@H5820121 I don't know.