Implementation of transparent window (opaque content such as text picture above window)

Source: Internet
Author: User
Tags transparent color

Implementation of transparent window (opaque content such as text picture above window)

This article discusses the purpose of this article through SetLayeredWindowAttributes.

The implementation of SetLayeredWindowAttributes must set the window to the extended style of ws_ex_layered. However, only the Ws_popup window can set the extension style of the ws_ex_layered. This means that only transparent windows can be implemented in the popup window, which is not possible in the Ws_child style window.

I was trying for a long while to find No.

The prototype of SetLayeredWindowAttributes is as follows:

[CPP]View Plaincopy
    1. BOOL SetLayeredWindowAttributes ( hwnd hwnd,
    2. colorref Crkey,
    3. BYTE Balpha,
    4. DWORD dwFlags
    5. );

The first parameter is the handle of the window to be set, the second one is to set a transparent color, the third is to set the transparency, the range of Balpha is 0-255, if it is 0, then completely transparent, if it is 255, is completely opaque. The fourth parameter is whether the setting is transparent according to the transparent color or according to Balpha.     Or two of them are set. If DwFlags is set to Lwa_colorkey, then Crkey will work, all the crkey color areas in the window will be transparent, and if DwFlags is set Lwa_alpha then Balpha will work. The entire window will be transparent according to the Balpha value. You can also set these two together to achieve both effects.

For example, the following code:

SetLayeredWindowAttributes (M_hwnd,rgb (255,0,255),

(BYTE),lwa_alpha| Lwa_colorkey);

All the magenta areas of the window will be fully transparent, then the remaining area is translucent.

Remember, it is not possible to set it separately, such as the following is not required to set up:

SetLayeredWindowAttributes (M_hwnd,

RGB (255,0,255), 0,lwa_colorkey);

SetLayeredWindowAttributes (m_hwnd,0, (BYTE) 220,lwa_alpha);

Let's implement a semi-transparent tip window:

1. Because our window is to implement a tip, this window is an irregular window, all need to map to achieve the border, and so on, all need magenta full, the other part of the semi-transparent effect. The following code can be used in oncreat or OnInitDialog:

SetLayeredWindowAttributes (M_hwnd,rgb (255,0,255),

(BYTE),lwa_alpha| Lwa_colorkey);

2. Then, we need the overall window, but the above text content can not be transparent, this problem can not be resolved, all can only in this window and then set a popup upwindow window, background brush a pure color, such as

RGB (0,255,0), and then oncreat or OnInitDialog with the SetLayeredWindowAttributes Settings window is fully transparent, the display of the content is drawn in this upwindow, so it seems to achieve the window translucent, But the above text is opaque effect.

The code is as follows:

SetLayeredWindowAttributes (M_hwnd,rgb (0,255,0), 0,lwa_colorkey);

Write the following code in the Upwindow OnPaint:

CRect RC;

GetClientRect (&RC);

dc. Fillsolidrect (Rc,rgb (0,255,0);

This will achieve the effect we need.

is what I achieved:

Original link: http://blog.csdn.net/tangaowen/article/details/6054123

http://blog.csdn.net/huasonl88/article/details/8697768

Implementation of transparent window (opaque content such as text picture above window)

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.