0

I have a window and then I create a child window using the following code:

HWND childHwnd = CreateWindowExA(WS_EX_LAYERED, "Test", "Test", WS_CHILD, 0, 0, 500, 500, mainHwnd, NULL, instance, NULL);

After it has been created I can control the opacity using:

static COLORREF color = RGB(255, 0, 0);
SetLayeredWindowAttributes(childHwnd, color, 127, LWA_ALPHA);

It works fine but I also have to support Windows 7 and MSDN says the following:

Windows 8: The WS_EX_LAYERED style is supported for top-level windows and child windows. Previous Windows versions support WS_EX_LAYERED only for top-level windows.

I have installed Windows 7 in a VM and sadly it doesn't works. What could be the workaround to achieve the same opacity control over a child window in Windows 7?

I also tried to make it a standalone window and just follow the position of the parent window but the user experience is not that good when the window gets moved fast.

ppp
  • 3
  • 1
  • 2
  • 3
    There's no "workaround", it's simply not supported. If you want a transparent effect from a child window on Windows 7 you'll need to render it that way yourself. – Jonathan Potter Dec 05 '22 at 07:12
  • 1
    Little point trying to support an ancient OS like win 7. I mean, it's time to drop support for win 8.1 so win 7 should be long gone. – David Heffernan Dec 06 '22 at 20:38

1 Answers1

0

According to the documentation:

Using Layered Windows

In order to use layered child windows, the application has to declare itself Windows 8-aware in the manifest.

I suggest you refer to this answer:

https://stackoverflow.com/a/42570249/11872808

In Windows 7, you could try to use the SetWindowRgn() function.

I suggest you refer to this question:

Creating a Transparent Child window on top of non-transparent Parent Window (win32)

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
Jeaninez - MSFT
  • 3,210
  • 1
  • 5
  • 20