Windows Transparency Problems
February 20, 2006 7:38 PM Subscribe
OK, so I figured out, through lots of painful browsing of MSDN, how to make windows (partially) transparent, and also how to chroma-key windows. And it works great, but only in windows 2000. In windows XP it works only in certain cirumstances. Need windows programmer to help me...
posted by RustyBrooks to Computers & Internet (15 answers total)
Here's the basic code snippet, where title and red/green/blue are defined upstream of this.
HWND hwnd = FindWindow(NULL, title);
COLORREF crkey = RGB(red, green, blue);
SetWindowLong(hwnd, GWL_EXSTYLE, GetWindowLong(hwnd, GWL_EXSTYLE) | WS_EX_LAYERED);
SetLayeredWindowAttributes(hwnd, crkey, alpha, LWA_COLORKEY | LWA_ALPHA);
This is like textbook, out of the windows example pages.
* It works on windows 2000
* It works on windows XP, EXCEPT it seems that I can only do it to windows that are NOT related to main application that is running the code above. That is, I can pick, say, my email window and make it transparent, but not another toplevel in my application.
I actually suspect that it may be a problem with how me/windows is "finding" the window. That first line where I get the HWND, I suspect that maybe it is not finding the window, under windows XP, if it's part of my application. The windows MSDN pages indicate that a different method is used if the window is/is not part of the application, so I suspect that may be the source of the problem.
I'm a unix programmer, doing this in windows out of necessity and I am in way over my head. I either need a better way to "find" window handles, or I need a way to verify whether FindWindow is finding anything, or if it's finding the "right" window.
The C code above is in a module, called by a scripting language called Tcl/Tk, so I don't really have low-level access to the toplevel windows in other ways (that is, I'm not explicitly creating them myself)