Question

I would like to share with you this post as I wasted a lot of time to understand why the WS_EX_LAYERED flag did not work on a fresh install of Windows (my test was on a Win7, I don't know if it can be reproduced on a Win8 o.s.).

This was my code:

...

hParentWindow=hWnd;
HWND myWnd=CreateWindowEx(WS_EX_LAYERED|WS_EX_PALETTEWINDOW,_T("STATIC"),_T(""), WS_POPUP|SS_BITMAP,position.left,position.top, position.right, position.bottom,hWnd,NULL,hInst,NULL);

Then I wanted to add a transparent layer:

CWnd::FromHandle(myWnd)->SetLayeredWindowAttributes(RGB(0,0,0), 255*0.6, LWA_ALPHA);

Running the code, the window never appeared! And this was not a child window (the WS_EX_LAYERED does not work for a child window), so the WS_EX_LAYERED flag should have worked.

Why?

Was it helpful?

Solution

After spending almost a day in searching for the solution, I found that the target PC (the one that hosts the executable) had the Aero Peek theme disabled because it had never run the "Performance Information and Tools"!

So, IMHO, a programmer that is going to use the WS_EX_LAYERED in his code, must determine if the Aero Peek is turned on or not (for example by looking into the \HKEY_CURRENT_USER\Software\Microsoft\Windows\DWM key registry and check the EnableAreoPeek registry value), otherwise some windows could not be shown correctly in any PCs.

Hope this makes you to save your time!

OTHER TIPS

I have been through the same issues today (Rosario I feel your pain of 2 years ago!).

I couldn't work out why windows were disappearing completely. I'm sure others may end up at this page for the same reason.

As such I wanted to pick up on one point.

The key factor to this seems to be that "Desktop Window Manager Session Manager" service must be running for transparent layers to function.

That EnableAeroPeek registry value, which relates to whether you see a full-screen preview of the windows as you look through them (eg. with alt-TAB or hovering over task manager mini-previews), can remain off and it not connected to the availability of transparency in tests I have carried out on multiple machines.

Similarly, if that registry setting is on but the DWMSM service being off, it will not give you transparency.

Rosario I'm sorry to contradict your own answer to your own question, but I think it's an important distinction!

So far the only way to test for the availability of transparency on Windows 7 & later before making a call which fails (or turns a window invisible) seems to be by checking for a running dwm.exe process.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top