How to use the SetLayeredWindowAttributes function, dialog transparent method __ function
Source: Internet
Author: User
This article introduces a way to make the dialog transparent use the following API functions, of course, MFC in the CWnd class also has the function (note: I use the environment for VS2008, you can directly use the function, VC6.0 different use of different methods, the introduction on the Web): The prototype of the function is BOOL SetLayeredWindowAttributes (HWND hwnd,//Handle to the layered window colorref Crkey,//Specifies the color key BYTE bAl PHA,//value for the blend function DWORD dwflags/action);
Where the HWND is the handle of the transparent form,//MFC CWnd class has not changed the Crkey to mask color, you can use RGB (R,G,B) to specify. ColorKey Balpha is transparency, with a value range of (0,255), where 0 represents full transparency and 255 is opaque. dwflags is transparent and can take two values: When the value is Lwa_alpha, the Crkey parameter is invalid, the Balpha parameter is valid, and when the value is Lwa_colorkey, all the colors in the form are Crkey and the Balpha parameter is invalid. Lwa_alpha = 0x2 lwa_colorkey=0x1 can also take a combination of two values: Lwa_alpha or Lwa_colorkey. Such crkey will become fully transparent, while other places are based on the Balpha parameters to determine transparency. SetLayeredWindowAttributes (0, Lwa_alpha);
Note: To make a form transparent, first make the window have ws_ex_layered extended properties by:
Add the following code to the function OnInitDialog ()
SetWindowLong (M_hwnd,gwl_exstyle,getwindowlong (This->getsafehwnd (), Gwl_exstyle) ^WS_EX_LAYERED);
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.