First, the transparent effect of background flashget is envious. The traditional Windows application wants to achieve a translucent effect. Generally speaking, the WM_Paint message window that needs to handle your window is very trouble. Now, setlayeredWindowAttributes is Windows new API, Win2000 is supported, it enables the form Transparent effect. I have been searching in Google, introducing the article in SetlayeredWindowAttributes Most of the articles of Delphi and VB. It's hard to find a VC, after the law, the VC's IDE said that I setlayeredWindowAttributes did not define! Later I thought I should be my SDK did not upgrade. So I enabled the "* .h" file of "setlayeredWindowAttribute" in the VC installation directory. Sure enough. What should I do? Upgrade SDK. I went to Microsoft's website, there will be more than 200 M M in the core SDK (even after decompression), the poor my hard drive does not have a partition greater than 200m! What to do, Such a fun API is not given, disappointed, I suddenly thought of the method of using the unapplicted API. This is a system support, but the API of the SDK, I will try him when doing Windows Unemong API! Second, briefly introduce setlayeredWindowAttributes: (see MSDN)
BOOL SetLayeredWindowAttributes (HWND hwnd, // handle to the layered window COLORREF crKey, // specifies the color key BYTE bAlpha, // value for the blend function DWORD dwFlags // action); Windows NT / 2000 / XP: Included in Windows 2000 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
The DWFLAGS has LWA_Alpha and LWA_ColorKey. LWA_ALPHA is set, the transparency is determined by Balpha, and LWA_COLORKEY is set, then specifies the transparent color to CRKEY, and other colors are displayed normally.
Note: To make the form have a transparent effect, you must first have a WS_EX_LAYERED extension attribute (the old SDK is not there).
Third, example code:
Add in OnInitDialog ():
// Add WS_EX_LAYERED extended 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; // function pointer SetLayeredWindowAttributes made fun = (MYFUNC) GetProcAddress (hInst, "SetLayeredWindowAttributes"); if (fun) fun (this-> GetsafehWnd (), 0,128,2); freeelibrary (hinst);} 唉! If the latest SDK is installed, you don't have it!
How, good effect! Slightly modified can also make a fade out of the fade, pay attention to the third parameter (128) Don't get too small, 0 words are completely transparent, you can't find the form!