Setlayeredwindowattributes is a new API for windows. It is only supported by Win2000 and later versions. It can make the form transparent.
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
Bool setlayeredwindowattributes (
Hwnd, // handle to the layered window
Colorref crkey, // specifies the Color Key
Byte balpha, // value for the blend function
DWORD dwflags // action
);
Some constants:
Ws_ex_layered = 0x80000;
Lwa_alpha = 0x2;
Lwa_colorkey = 0x1
Dwflags contains lwa_alpha and lwa_colorkey. If lwa_alpha is set, balpha is used to determine the transparency. If 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 ).
【
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 );
}
]
# Define ws_ex_layered 0x00080000
# Define lwa_colorkey 0x00000001
# Define lwaf_alpha 0x00000002
Typedef bool (* _ setlayeredwindowattributes) (hwnd, colorref, byte, DWORD );
_ Setlayeredwindowattributes;
Void setlayered (hwnd, int POS)
{
Setlayeredwindowattributes = (_ setlayeredwindowattributes) getprocaddress (getmodulehandle (// "user32.dll //"), // "setlayeredwindowattributes ///");
If (setlayeredwindowattributes = NULL)
Return;
Else {
_ Try {
Setwindowlong (hwnd, gwl_exstyle, getwindowlong (hwnd, gwl_exstyle) | ws_ex_layered );
Setlayeredwindowattributes (hwnd, RGB (0, 0), POs, lwa_alpha );
}
_ Handler T (exception_execute_handler ){
Afxmessagebox (// "system false ///");
}
}
}