Layered Windows window translucent effect, layered window

Source: Internet
Author: User

Layered Windows window translucent effect, layered window

 

Introduction: Layered Windows is a type of windows window that provides a semi-transparent effect (Alpha hybrid ). The translucent effect can be seen literally, but in fact, according to MSND, this type of window can better support non-rectangular windows, to make the display more smooth and smooth (secretly guessed the effect achieved by using hardware acceleration ). WS_EX_LAYERED before win8 can only be used for top-level windows, and Windows 8 and later versions can also be used. Usage:

The first thing to do is to addWS_EX_LAYEREDStyle. Call laterSetLayeredWindowAttributes (). The function is prototype as follows:

  

Bool winapi SetLayeredWindowAttributes (_ In _ HWND hwnd, // window handle _ In _ COLORREF crKey, // sets the relative weight of the color channel using RGB macro _ In _ BYTE bAlpha, // Alpha value, between 0-2-25 _ In _ DWORD dwFlags //Lwa_pldHA or LWA_COLORKEY, Or both );
/*
*LWA_ALPHA: Use Alpha to display transparency
LWA_COLORKEY: Uses RGB channels to filter colors
*/
So what are the differences between the two flags, or what are their respective effects? I will understand it later.

When LWA_COLORKEY is validTheWhen LWA_ALPHA is valid, use half of the window.

Color is regarded as transparentTransparency. The Alpha value is specified by the parameter. 

The left side is LWA_COLORKEY, and the right side of the window is LWA_ALPHA. The overall display is translucent, and

The circular area of RGB = (255,) on the image is regarded as the circular area drawn on the window. (Also notice the round

The coordinates of the transparent window are calculated in the upper left corner of the rectangle)

 

The two effects can be used at the same time. The effect is a translucent Black Moon.

You can use the UpdataLayeredWindow () function to update the Layered Window. For example, you can reset its transparency, position, size, and shape. This function updates the entire window. You do not need to worry about the update of the blocked window. The system will handle the problem. (For a Layered window system, the following images are always saved and automatically updated. This means that more memory is occupied. Therefore, you do not need to delete the WS_LAYERED style through SetWindowLong. This will be explained below)

When you click the mouse on a transparent part (for example, the missing part of the left crescent or set the Alpha value to 0 on the right), the mouse message is displayed in the window, that is, the Layered window does not accept mouse messages here. This is in line with what we see is what we get from the design concept. Users don't have to understand what Alpha hybrid is.

How to set the Layered window to a normal window

If transparent effects are no longer needed, removing the Layered attribute as soon as possible can improve the performance. The standard practice is as follows:

// Remove WS_EX_LAYERED from this window stylesSetWindowLong(hwnd,               GWL_EXSTYLE,              GetWindowLong(hwnd, GWL_EXSTYLE) & ~WS_EX_LAYERED);// Ask the window and its children to repaintRedrawWindow(hwnd,              NULL,              NULL,              RDW_ERASE | RDW_INVALIDATE | RDW_FRAME | RDW_ALLCHILDREN);

Finally, if the window has been created, you can call SetWindowLong () to reset the window style. However, change the style of a window that has been displayed on the screenWS_EX_LAYEREDYou will find that the window is missing. After calling UpdataLayeredWindow () or SetLayeredWindowAttributes (), you will see what you want.

In addition, onceSetLayeredWindowAttributesCalled.UpdateLayeredWindowThe call will fail until the Layered attribute of the window is changed again.

 

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.