Why SetWindowCompositionAttribute makes text also transparent

szx0427 101 信誉分
2025-02-03T03:09:20.4966667+00:00

When I called SetWindowCompositionAttribute to make the main window blurred, text of controls on it also became transparent and thus hard to read.
用户的图像

I want to keep the text pure black without transparency while the main window is blurred and transparent. How could I achieve that?

By the way, I found that seemingly all black pixels on the window will become transparent (I set the background of the main window to black so that u can find it transparent in the pic) when SetWindowCompositionAttribute is called, that all white pixels will keep opaque and that other colors will be semi-transparent with a bit of its original color (see the bottommost control in the pic above, which is a Syslink and originally blue). Hope this will be helpful to you guys.

The code fragment in which I call the API:

DWORD accent[4] = { 3,0,0,0 }; // 3 means AccentState=ACCENT_ENABLE_BLURBEHIND
struct {
	DWORD attrib;
	PVOID pvData;
	UINT cbData;
} AttribData = {19,accent,sizeof(accent)}; // 19 is WCA_ACCENT_POLICY
SetWindowCompositionAttribute(m_hWnd, &AttribData); // m_hWnd is my main window
Windows API - Win32
Windows API - Win32
一组适用于桌面和服务器应用程序的核心 Windows 应用程序编程接口 (API)。 以前称为 Win32 API。
132 个问题
C++
C++
一种通用的高级编程语言,作为 C 编程语言的扩展而创建,除了用于低级别内存操作的功能外,还具有面向对象、泛型和功能性等特点。
160 个问题
{count} 票

1 个答案

排序依据: 非常有帮助
  1. szx0427 101 信誉分
    2025-02-06T14:55:58.9466667+00:00
    0 个注释 无注释

你的答案

问题作者可以将答案标记为“接受的答案”,这有助于用户了解已解决作者问题的答案。