Make the window transparent

Source: Internet
Author: User
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 ///");
}
}
}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.