Skip to content

Instantly share code, notes, and snippets.

@0x61726b
Last active April 25, 2023 01:32
Show Gist options
  • Save 0x61726b/7a807e04ee8f1d95425f710944667508 to your computer and use it in GitHub Desktop.
Save 0x61726b/7a807e04ee8f1d95425f710944667508 to your computer and use it in GitHub Desktop.
Rainmeter plugin for making taskbar translucent. http://arkenthera.deviantart.com/art/TranslucentTaskbar-1-0-656402039
#include <Windows.h>
#include "../../API/RainmeterAPI.h"
struct ACCENTPOLICY {
int nAccentState;
int nFlags;
int nColor;
int nAnimationId;
};
struct WINCOMPATTRDATA {
int nAttribute;
PVOID pData;
ULONG ulDataSize;
};
enum AccentTypes {
ACCENT_DISABLE = 0,
ACCENT_ENABLE_GRADIENT = 1,
ACCENT_ENABLE_TRANSPARENTGRADIENT = 2,
ACCENT_ENABLE_BLURBEHIND = 3
};
bool IsWindows10() {
OSVERSIONINFOA info;
ZeroMemory(&info, sizeof(OSVERSIONINFOA));
info.dwOSVersionInfoSize = sizeof(OSVERSIONINFOA);
GetVersionExA(&info);
return info.dwMajorVersion == 10;
}
void SetBlurBehind(HWND hwnd, AccentTypes desiredType) {
if (IsWindows10()) {
const HINSTANCE hModule = LoadLibrary(TEXT("user32.dll"));
if (hModule) {
typedef BOOL(WINAPI*pSetWindowCompositionAttribute)(HWND,
WINCOMPATTRDATA*);
const pSetWindowCompositionAttribute
SetWindowCompositionAttribute =
(pSetWindowCompositionAttribute)GetProcAddress(
hModule,
"SetWindowCompositionAttribute");
// Only works on Win10
if (SetWindowCompositionAttribute) {
ACCENTPOLICY policy =
{ desiredType
,0,desiredType == (ACCENT_ENABLE_TRANSPARENTGRADIENT) ? 255 : 0,0 };
WINCOMPATTRDATA data = { 19,&policy,sizeof(ACCENTPOLICY) };
SetWindowCompositionAttribute(hwnd, &data);
}
FreeLibrary(hModule);
}
}
else {
//Nothing
}
}
HWND TaskbarHandle = FindWindow(L"Shell_TrayWnd", NULL);
HWND SecondaryTaskbar = FindWindow(L"Shell_SecondaryTrayWnd", NULL);
struct Measure
{
AccentTypes State;
Measure() : State(ACCENT_ENABLE_BLURBEHIND) {}
};
PLUGIN_EXPORT void Initialize(void** data, void* rm)
{
Measure* measure = new Measure;
*data = measure;
}
PLUGIN_EXPORT void Reload(void* data, void* rm, double* maxValue)
{
Measure* measure = (Measure*)data;
LPCWSTR value = RmReadString(rm, L"AccentState", L"");
if (_wcsicmp(value, L"0") == 0)
{
measure->State = ACCENT_DISABLE;
}
else if (_wcsicmp(value, L"1") == 0)
{
measure->State = ACCENT_ENABLE_GRADIENT;
}
else if (_wcsicmp(value, L"2") == 0)
{
measure->State = ACCENT_ENABLE_TRANSPARENTGRADIENT;
}
else if (_wcsicmp(value, L"3") == 0)
{
measure->State = ACCENT_ENABLE_BLURBEHIND;
}
else
{
measure->State = ACCENT_ENABLE_BLURBEHIND;
}
}
PLUGIN_EXPORT double Update(void* data)
{
Measure* measure = (Measure*)data;
SetBlurBehind(TaskbarHandle, measure->State);
SetBlurBehind(SecondaryTaskbar, measure->State);
SecondaryTaskbar = FindWindow(L"Shell_SecondaryTrayWnd", NULL);
// Just in case
int GuardCounter = 0;
while (SecondaryTaskbar = FindWindowEx(0, SecondaryTaskbar, L"Shell_SecondaryTrayWnd", L""))
{
if (GuardCounter > 8)
break;
SetBlurBehind(SecondaryTaskbar, measure->State);
GuardCounter++;
}
return 0.0;
}
PLUGIN_EXPORT void Finalize(void* data)
{
Measure* measure = (Measure*)data;
SetBlurBehind(TaskbarHandle, ACCENT_DISABLE);
SetBlurBehind(SecondaryTaskbar, ACCENT_DISABLE);
SecondaryTaskbar = FindWindow(L"Shell_SecondaryTrayWnd", NULL);
int GuardCounter = 0;
while (SecondaryTaskbar = FindWindowEx(0, SecondaryTaskbar, L"Shell_SecondaryTrayWnd", L""))
{
if (GuardCounter > 8)
break;
SetBlurBehind(SecondaryTaskbar, ACCENT_DISABLE);
GuardCounter++;
}
delete measure;
}
@Robby-Sodhi
Copy link

is there anyway to make it only transparent on the desktop?

@hobbica98
Copy link

hobbica98 commented Sep 23, 2020

Hey man, for the 2 screen problem that a taskbar won't update. you need to reset the secondarytaskbar var after the while.


PLUGIN_EXPORT double Update(void* data)
{
	Measure* measure = (Measure*)data;

	SetBlurBehind(TaskbarHandle, measure->State);
	SetBlurBehind(SecondaryTaskbar, measure->State);

	SecondaryTaskbar = FindWindow(L"Shell_SecondaryTrayWnd", NULL);

	// Just in case 
	int GuardCounter = 0;
	while (SecondaryTaskbar = FindWindowEx(0, SecondaryTaskbar, L"Shell_SecondaryTrayWnd", L""))
	{
		if (GuardCounter > 8)
			break;
		SetBlurBehind(SecondaryTaskbar, measure->State);
		GuardCounter++;
	}
	SecondaryTaskbar = FindWindow(L"Shell_SecondaryTrayWnd", NULL);

	return 0.0;
}

Like so

@paramsiddharth
Copy link

paramsiddharth commented Aug 22, 2021

Can you check out Lively? It is another Windows customization tool, and is open source. It provides all different taskbar customization features. You might want to look into its source code, though it is written in C# rather than C++.

@yuceltoluyag
Copy link

i have a problem the task bar of windows still remains black pls fix

@paramsiddharth
Copy link

i have a problem the task bar of windows still remains black pls fix

@yuceltoluyag Go to Windows Settings, turn off transparency, and turn it back on. That fixes the problem for most cases.

If it doesn't, try turning the charging on and off if a laptop. Try switching the power saver and performance modes. If none of that works, then move on to looking for more solutions on the Internet and fiddle with the registry and drivers.

@CDTANK1
Copy link

CDTANK1 commented Mar 20, 2022

I've installed the translucent taskbar from deviantart and it flickers, what can i do? i tried doing
[TranslucentTaskbar]
Measure = Plugin
Plugin=TranslucentTaskbar
UpdateDivider=1
AccentState=2
but it didn't work

@distresscode
Copy link

Is it possible to hide the line shown in the screenshot? Thanks!

W11 Home 22H2

Screenshot 2023-01-22 110405

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment