fix: unable to make window transparent in later win10 versions

This commit is contained in:
MicroBlock 2025-02-03 14:59:37 +08:00 committed by GitHub
parent e7ea71be03
commit 1952a1b363
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -68,6 +68,9 @@ static DWORD getWindowExStyle(const _GLFWwindow* window)
{ {
DWORD style = WS_EX_APPWINDOW; DWORD style = WS_EX_APPWINDOW;
if (_glfw.hints.framebuffer.transparent)
style |= WS_EX_LAYERED;
if (window->monitor || window->floating) if (window->monitor || window->floating)
style |= WS_EX_TOPMOST; style |= WS_EX_TOPMOST;
@ -380,15 +383,17 @@ static void updateFramebufferTransparency(const _GLFWwindow* window)
if (FAILED(DwmIsCompositionEnabled(&composition)) || !composition) if (FAILED(DwmIsCompositionEnabled(&composition)) || !composition)
return; return;
if (IsWindows8OrGreater() || if (IsWindows8OrGreater() ||
(SUCCEEDED(DwmGetColorizationColor(&color, &opaque)) && !opaque)) (SUCCEEDED(DwmGetColorizationColor(&color, &opaque)) && !opaque))
{ {
HRGN region = CreateRectRgn(0, 0, -1, -1); HRGN region = CreateRectRgn(0, 0, -1, -1);
DWM_BLURBEHIND bb = {0}; DWM_BLURBEHIND bb = {0};
bb.dwFlags = DWM_BB_ENABLE | DWM_BB_BLURREGION; bb.dwFlags = DWM_BB_ENABLE;
bb.hRgnBlur = region; bb.hRgnBlur = region;
bb.fEnable = TRUE; bb.fEnable = TRUE;
SetLayeredWindowAttributes(window->win32.handle, 0x0030c100, 254, LWA_ALPHA);
DwmEnableBlurBehindWindow(window->win32.handle, &bb); DwmEnableBlurBehindWindow(window->win32.handle, &bb);
DeleteObject(region); DeleteObject(region);
} }
@ -1294,6 +1299,7 @@ static int createNativeWindow(_GLFWwindow* window,
#else #else
wc.lpszClassName = L"GLFW30"; wc.lpszClassName = L"GLFW30";
#endif #endif
wc.hbrBackground = (HBRUSH)CreateSolidBrush(0x00000000);
// Load user-provided icon if available // Load user-provided icon if available
wc.hIcon = LoadImageW(GetModuleHandleW(NULL), wc.hIcon = LoadImageW(GetModuleHandleW(NULL),
L"GLFW_ICON", IMAGE_ICON, L"GLFW_ICON", IMAGE_ICON,