Specifiying twice LWA_COLORKEY in Win32 API

Viewed 121

I'm trying to find a way to be able to replace 2 COLORS on a specific Window (which isn't made by me, it's another problem).

LONG ExtendedStyle = GetWindowLong(handle,GWL_EXSTYLE );
SetWindowLong(handle,GWL_EXSTYLE,ExtendedStyle | WS_EX_LAYERED );
::SetLayeredWindowAttributes(handle,RGB(251,254,249),0,LWA_COLORKEY);

This works well, now I'm trying to call twice:

::SetLayeredWindowAttributes(handle,RGB(251,254,249),0,LWA_COLORKEY);

with a different color code

LONG ExtendedStyle = GetWindowLong(handle,GWL_EXSTYLE );
SetWindowLong(handle,GWL_EXSTYLE,ExtendedStyle | WS_EX_LAYERED );
::SetLayeredWindowAttributes(handle,RGB(251,254,249),0,LWA_COLORKEY);
::SetLayeredWindowAttributes(handle,RGB(251,254,220),0,LWA_COLORKEY);

This does NOT work and only the last one is taken into account, I've searched extensively and wish to not go into too advanced solutions as my problem seems simple. Anyone has a clue?

EDIT: I'm sorry I'm very unfamiliar with this API and I have a client that requires me to replace 2 colors (or more) in a window, I'm already losing way too much time on this. Your help is very very welcome. Thank you

1 Answers

According to the document of SetLayeredWindowAttributes function, if you use a parameter LWA_COLORKEY, all areas of the form where the color is crKey will become transparent and the bAlpha parameter is invalid. So only the last function is valid. If you want to make multiple areas transparent, you can set them to the same color in advance.

Related