How to stop WS_EX_LAYERED causing mouse clicks to go through.

WorkKuls 6 Reputation points

WS_EX_LAYERED shouldn't usually pass mouse clicks according to the documentation. Yet it does. It basically has the same effect as WS_EX_TRANSPARENT.
This happens no matter what the opacity value is when using SetLayeredWindowAttributes(). However, this only happens when I use a manifest file to list the supported OSs(windows 8 and up).
The reason the manifest file is necessary is because that's the way to support child windows from having extended styles(this is needed to give translucency to child windows).
I have been trying to fix this/trying other ways to get the desired effects for roughly a week, but all was in vain.

One more thing. The non-client area remains unaffected initially but passes mouse clicks after minimizing. Here is a video showcasing this--->
I compile through GCC after linking the manifest file through .res and DLLs. Here is the makefile -->
Manifest file -->
Full code -->

Here is the WM_CREATE code(in case you don't want to see the entire code)

case WM_CREATE:  
        SetWindowLongA(hwnd, GWL_EXSTYLE, GetWindowLongA(hwnd, GWL_EXSTYLE) | WS_EX_LAYERED);  
        SetWindowPos(hwnd, NULL, 0, 0, 0, 0, SWP_FRAMECHANGED);  
        SetLayeredWindowAttributes(hwnd, RGB(255, 0, 0), 0 /*doesn't matter*/, LWA_COLORKEY);  
        hbackground = CreateWindowExA(0,  
                                      WS_CHILD | WS_VISIBLE | SS_BITMAP,  
        setImage(hbackground, background_image_name, monitor_dimension.width, monitor_dimension.height);  
        SetWindowLongA(hbackground, GWL_EXSTYLE, GetWindowLongA(hbackground, GWL_EXSTYLE) | WS_EX_LAYERED);  
        SetWindowPos(hwnd, NULL, 0, 0, 0, 0, SWP_FRAMECHANGED);  
        SetLayeredWindowAttributes(hbackground, 0, (255 * 50) / 100, LWA_ALPHA);  
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,067 questions
{count} vote

1 answer

Sort by: Most helpful
  1. Xiaopo Yang - MSFT 7,106 Reputation points Microsoft Vendor

    It's an unexpected behavior and I'm reporting it. It's recommended to avoid using child window with WS_EX_LAYERED as @Castorix31 suggested.
    As this issue is complex, please open an incident via 'Contact us' tab at link below so that our engineer can work with you closely: and please choose the 'Technical Support - Coding/Debugging' for Windows SDK for this issue. In-addition, if the support engineer determines that the issue is the result of a bug the service request will be a no-charge case and you won't be charged.

    0 comments No comments