Why SetWindowCompositionAttribute makes text also transparent

szx0427 101 Reputation points
2025-02-03T03:24:51.68+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
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,726 questions
C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,845 questions
{count} votes

1 answer

Sort by: Most helpful
  1. szx0427 101 Reputation points
    2025-02-06T15:05:07.1466667+00:00

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.