I. background
Do you envy the transparency of flashget? traditional Windows ApplicationsProgramTo achieve a translucent effect, you generally need to process the wm_paint message window of your own window.
Annoying. Now, setlayeredwindowattributes is a new Windows API, which is supported by Win2000 and later. It can make the form transparent
Result: I searched for the setlayered?wattributesArticleMostly from Delphi and VB. It's hard to find a VC,
After the process was done in accordance with the law, the VC Ide said that my setlayered?wattributes is not defined! Later I thought that my SDK was not upgraded, So I installed
The "*. H" file for searching "setlayeredwindowattributes" does not exist. What should I do? Upgrade the SDK. I will go to the Microsoft website and check the new SDK.
The core SDK has more than two hundred MB (larger after decompression). Sorry, no partition on my hard disk is larger than MB! What should I do? This interesting API cannot be used :(
When I was disappointed, I suddenly thought of the method of using APIs that were not publicly available. This is a system support API that my SDK does not have. I will try using it as an API that is not publicly available in windows!
ExampleCodeRun
Ii. Brief Introduction to setlayeredwindowattributes
(See msdn for details)
Bool setlayeredwindowattributes (
Hwnd, // handle to the layered window
Colorref crkey, // specifies the Color Key
Byte balpha, // value for the blend function
DWORD dwflags // action
);
<Requirements>
Windows NT/2000/XP: supported ded in Windows 2000 and later.
Windows 95/98/me: unsupported.
Header: declared in winuser. h; Include windows. h.
Library: Use user32.lib.
Some constants:
Ws_ex_layered = 0x80000;
Lwa_alpha = 0x2;
Lwa_colorkey = 0x1
Dwflags include lwa_alpha and lwa_colorkey.
If lwa_alpha is set, balpha is used to determine the transparency.
If the lwa_colorkey is set, the transparent color is specified as the crkey, and other colors are displayed normally.
Note: To make the form transparent, you must first have the ws_ex_layered extension attribute (which is not available in the old SDK ).
Iii. Sample Code
:
Add oninitdialog:
// Add the ws_ex_layered extension attribute
Setwindowlong (this-> getsafehwnd (), gwl_exstyle,
Getwindowlong (this-> getsafehwnd (), gwl_exstyle) ^ 0x80000 );
Hinstance hinst = loadlibrary ("user32.dll ");
If (hinst)
{
Typedef bool (winapi * myfunc) (hwnd, colorref, byte, DWORD );
Myfunc fun = NULL;
// Get the setlayeredwindowattributes function pointer
Fun = (myfunc) getprocaddress (hinst, "setlayeredwindowattributes ");
If (fun) Fun (this-> getsafehwnd (), 0,128, 2 );
Freelibrary (hinst );
}
Alas! If you have installed the latest SDK, you don't have to worry about it!
How about it? Good results! A slight modification can also make a fade-out effect. Note that the third parameter (128) should not be too small. If it is 0, it is completely transparent and you will not be able to find the form!
I hope it will be helpful to beginners. If you have any problems, please correct me.