TaskBar_SetAttr - translucent / blur / coloring Windows TaskBar

Post your working scripts, libraries and tools for AHK v1.1 and older
User avatar
joedf
Posts: 8958
Joined: 29 Sep 2013, 17:08
Location: Canada
Contact:

Re: TaskBar_SetAttr - translucent / blur / coloring Windows TaskBar

Post by joedf » 19 Apr 2021, 11:59

I am not sure about 3 monitors, but I think you'll want to give this a try:
replace the Shell_TrayWnd with Shell_SecondaryTrayWnd in the code in the quote. :think:
Image Image Image Image Image
Windows 10 x64 Professional, Intel i5-8500, NVIDIA GTX 1060 6GB, 2x16GB Kingston FURY Beast - DDR4 3200 MHz | [About Me] | [About the AHK Foundation] | [Courses on AutoHotkey]
[ASPDM - StdLib Distribution] | [Qonsole - Quake-like console emulator] | [LibCon - Autohotkey Console Library]

10inchOfSnow
Posts: 23
Joined: 26 Jul 2019, 06:41

Re: TaskBar_SetAttr - translucent / blur / coloring Windows TaskBar

Post by 10inchOfSnow » 20 Apr 2021, 01:10

joedf wrote:
19 Apr 2021, 11:59
I am not sure about 3 monitors, but I think you'll want to give this a try:
replace the Shell_TrayWnd with Shell_SecondaryTrayWnd in the code in the quote. :think:
Well, already done it and, this is strange, changed only second monitor taskbar :o

User avatar
joedf
Posts: 8958
Joined: 29 Sep 2013, 17:08
Location: Canada
Contact:

Re: TaskBar_SetAttr - translucent / blur / coloring Windows TaskBar

Post by joedf » 20 Apr 2021, 07:14

I guess you need to run it for each monitor... I am not sure what you do for the 3rd monitor...
Image Image Image Image Image
Windows 10 x64 Professional, Intel i5-8500, NVIDIA GTX 1060 6GB, 2x16GB Kingston FURY Beast - DDR4 3200 MHz | [About Me] | [About the AHK Foundation] | [Courses on AutoHotkey]
[ASPDM - StdLib Distribution] | [Qonsole - Quake-like console emulator] | [LibCon - Autohotkey Console Library]

farse
Posts: 3
Joined: 16 May 2022, 08:49

Re: TaskBar_SetAttr - translucent / blur / coloring Windows TaskBar

Post by farse » 17 May 2022, 02:32

@10inchOfSnow
@joedf

Code: Select all

TaskBar_SetAttr(accent_state := 0, gradient_color := "0x01000000")
{
    static init, hTrayWnd, ver := DllCall("GetVersion") & 0xff < 10
    static pad := A_PtrSize = 8 ? 4 : 0, WCA_ACCENT_POLICY := 19

    accent_size := VarSetCapacity(ACCENT_POLICY, 16, 0)
    NumPut((accent_state > 0 && accent_state < 4) ? accent_state : 0, ACCENT_POLICY, 0, "int")

    if (accent_state >= 1) && (accent_state <= 2) && (RegExMatch(gradient_color, "0x[[:xdigit:]]{8}"))
        NumPut(gradient_color, ACCENT_POLICY, 8, "int")

    VarSetCapacity(WINCOMPATTRDATA, 4 + pad + A_PtrSize + 4 + pad, 0)
    && NumPut(WCA_ACCENT_POLICY, WINCOMPATTRDATA, 0, "int")
    && NumPut(&ACCENT_POLICY, WINCOMPATTRDATA, 4 + pad, "ptr")
    && NumPut(accent_size, WINCOMPATTRDATA, 4 + pad + A_PtrSize, "uint")
    WinGet, hTrayWnd,, ahk_class Shell_TrayWnd 
    if !(DllCall("user32\SetWindowCompositionAttribute", "ptr", hTrayWnd, "ptr", &WINCOMPATTRDATA))
        throw Exception("Failed to set transparency / blur", -1)

    WinGet, hMultipleMonitor, List, ahk_class Shell_SecondaryTrayWnd 
    if(hMultipleMonitor)
    {
        Loop %	hMultipleMonitor {
            if !(DllCall("user32\SetWindowCompositionAttribute", "ptr", hMultipleMonitor%A_Index% , "ptr", &WINCOMPATTRDATA))
                throw Exception("Failed to set transparency / blur 2", -1)
        }
    }
    return true
}

This should work on any monitor.

User avatar
joedf
Posts: 8958
Joined: 29 Sep 2013, 17:08
Location: Canada
Contact:

Re: TaskBar_SetAttr - translucent / blur / coloring Windows TaskBar

Post by joedf » 17 May 2022, 13:30

Thanks for sharing @farse ! :+1:
Image Image Image Image Image
Windows 10 x64 Professional, Intel i5-8500, NVIDIA GTX 1060 6GB, 2x16GB Kingston FURY Beast - DDR4 3200 MHz | [About Me] | [About the AHK Foundation] | [Courses on AutoHotkey]
[ASPDM - StdLib Distribution] | [Qonsole - Quake-like console emulator] | [LibCon - Autohotkey Console Library]

william_ahk
Posts: 493
Joined: 03 Dec 2018, 20:02

Re: TaskBar_SetAttr - translucent / blur / coloring Windows TaskBar

Post by william_ahk » 26 Jul 2022, 06:24

I don't really fancy the wasteful :D SetTimer approach for the Start Menu workaround. Without getting too complicated by listening to window events here's a really simple approach I figured:

Code: Select all

SetBatchLines -1
UPDATE_TASKBAR()

loop {
    WinWaitActive ahk_class Windows.UI.Core.CoreWindow
    UPDATE_TASKBAR()
    WinWaitNotActive ahk_class Windows.UI.Core.CoreWindow
    UPDATE_TASKBAR()
    hA := WinActive("A")
    WinWaitNotActive % "ahk_id" hA
    UPDATE_TASKBAR()
}
return

UPDATE_TASKBAR() {
    TaskBar_SetAttr(3)
}
Edit: Guys I discovered a sad truth. It looks like WinWait is also essentially polling which makes it no different than SetTimer :facepalm:
Last edited by william_ahk on 17 Aug 2022, 06:32, edited 2 times in total.

User avatar
joedf
Posts: 8958
Joined: 29 Sep 2013, 17:08
Location: Canada
Contact:

Re: TaskBar_SetAttr - translucent / blur / coloring Windows TaskBar

Post by joedf » 26 Jul 2022, 08:13

Oooouuu event based yes please. :+1:
Image Image Image Image Image
Windows 10 x64 Professional, Intel i5-8500, NVIDIA GTX 1060 6GB, 2x16GB Kingston FURY Beast - DDR4 3200 MHz | [About Me] | [About the AHK Foundation] | [Courses on AutoHotkey]
[ASPDM - StdLib Distribution] | [Qonsole - Quake-like console emulator] | [LibCon - Autohotkey Console Library]

User avatar
moefr01
Posts: 115
Joined: 25 Nov 2015, 09:01
Location: Germany

Re: TaskBar_SetAttr - translucent / blur / coloring Windows TaskBar

Post by moefr01 » 29 Jul 2022, 13:39

@jNizM: Thanks for sharing :thumbup:
Tested on Windows 11 64Bit German. Found out when use both commands successively:

Code: Select all

…
TaskBar_SetAttr(1)
TaskBar_SetAttr(2)
ExitApp
…
No settimer-coding is needed to prevent loosing taskbar-transparency by clicking the startbutton or pressing the win-button.
Be sure the transparency under display-settings is off before.
Cheers moefr01 :wave:

Post Reply

Return to “Scripts and Functions (v1)”