I found an even better way!
Code:
#include <windows.h>
#include "stdafx.h"
TCHAR szClassName[] = TEXT("Blur");
LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch (msg)
{
case WM_NCHITTEST:
wParam = DefWindowProc(hWnd, msg, wParam, lParam);
if (wParam == HTCLIENT)
return HTCAPTION;
else
return wParam;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, msg, wParam, lParam);
}
return 0;
}
void SetWindowBlur(HWND hWnd)
{
const HINSTANCE hModule = LoadLibrary(TEXT("user32.dll"));
if (hModule)
{
struct ACCENTPOLICY
{
int nAccentState;
int nFlags;
int nColor;
int nAnimationId;
};
struct WINCOMPATTRDATA
{
int nAttribute;
PVOID pData;
ULONG ulDataSize;
};
typedef BOOL(WINAPI*pSetWindowCompositionAttribute)(HWND, WINCOMPATTRDATA*);
const pSetWindowCompositionAttribute SetWindowCompositionAttribute = (pSetWindowCompositionAttribute)GetProcAddress(hModule, "SetWindowCompositionAttribute");
if (SetWindowCompositionAttribute)
{
ACCENTPOLICY policy = { 3, 0, 0, 0 };
WINCOMPATTRDATA data = { 19, &policy, sizeof(ACCENTPOLICY) };
SetWindowCompositionAttribute(hWnd, &data);
}
FreeLibrary(hModule);
}
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPreInst, LPSTR pCmdLine, int nCmdShow)
{
MSG msg;
WNDCLASS wndclass = {
0,
WndProc,
0,
0,
hInstance,
0,
LoadCursor(0, IDC_ARROW),
(HBRUSH)GetStockObject(BLACK_BRUSH),
0,
szClassName
};
RegisterClass(&wndclass);
RECT taskpos;
HWND taskbar = FindWindow(L"Shell_TrayWnd", NULL);
GetWindowRect(taskbar, &taskpos);
HWND hWnd = CreateWindowEx(
WS_EX_TOOLWINDOW | WS_EX_TOPMOST ,
szClassName,
TEXT("Blur"),
WS_POPUP,
taskpos.left,
taskpos.top,
taskpos.right - taskpos.left,
taskpos.bottom - taskpos.top,
0,
0,
hInstance,
0
);
SetParent(taskbar, hWnd);
SetWindowBlur(hWnd);
ShowWindow(hWnd, SW_SHOW);
// i wanna add some darkening effect later on, draw a half-transparent black rectangle on the whole window
while (GetMessage(&msg, 0, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
Just create a window with the same size and position as the taskbar and then set the taskbar as the child of this window. This gives you total control over the taskbar's background (you can draw anything in the window, and it will be the taskbar's background.)
Sorry if the code is a bit messy, that's a prototype.