VC realizes the transparency of the top window and realizes the transparency of the child window "Focus: child window transparent processing"

Source: Internet
Author: User

Tags: window transparent

I in the VC development process, many times because the window transparent and painstakingly, in my previous article "Updatelayeredwindow and SetLayeredWindowAttributes" has indicated the realization window transparent method, During the actual development process I have been following this approach, but it is not always proven, the actual application process defects exposed as follows:

(1) setlayeredwindowattributes and Updatelayeredwindow Two API functions can only be applied to the level window, that is, non-child window;

(2) TheUpdatelayeredwindow method is more efficient than setlayeredwindowattributes, but it is done by drawing to a memory intermediate device context , the device context is copied to the specified level window, which means that all the drawing must be implemented in the memory device context, even including all child controls, sotransparency is achieved through it, and all child controls on the parent window are "missing", so pay special attention to [this is also the experience summary, remember! ], but the advantage is that specifying an opacity of 255 times, it automatically from the use of PNG alpha[is certainly not necessarily a PNG map, as long as the map has an alpha channel] channel to transparent window, that is, transparency is the transparency of the picture, otherwise you can use the const without mapping Solid transparent specifies transparency; There are two ways of setlayeredwindowattributes transparency, the first is by specifyingCOLORREFCrkey, the mask color, which is the mask color that is specified as parameter 2 to be rejected window, automatically converts the background of the masked color in all backgrounds to Crkeyfully Transparent, of course, when using the mask color method, you must specifyDWORDdwflags forLwa_colorkey, that is, the use of mask color transparency, the second way is not to use the mask color, but to use transparency to transparent and do not care about your background color in the end, just add a layer of transparency to the entire window, then Crkey ignore fill 0, The Balpha opacity is specified as an arbitrary value of 0-255, 0 refers to full transparency, and 255 refers to full opacity, when the specified DWORD dwflags is lwa_alpha.

BOOL SetLayeredWindowAttributes (HWND hwnd, COLORREF crkey, BYTE balpha, Dwor D dwFlags); By contrast, it is known that the first transparent method in SetLayeredWindowAttributes is to remove the pixels of the mask-color position one after the other, and Updatelayeredwindow is implemented by binary and operation. So the efficiency of Updatelayeredwindow is much higher;
(3) because it is a hierarchy window, in the actual application of the transparent window is set to transparent window caused by the problem is that when you switch to other pages, you must manually hide the change Level window, if the manual setparent this level window is invalidated, after the call automatically with Ws_ The child attribute causes the transparency of the hierarchy window to not be implemented;
(4) Minimized after the display, transparent window display faster than other windows, feel covered in other windows of the transparent window "is not a gang", lost the general;
(5) Transparent window to go to the desktop alone, the application of the minimum is not visible;
 above is a transparent method using the hierarchy window to And the use of this method to expose a number of problems, in order to improve or avoid the above methods, I have been looking for the way to make the sub-window transparent, unfortunately, the use of hollow painting brush, which makes me realize: hollow Hollow_brush is equal to Null_brush, meaning is not to use painting brush, That is, not to do painting brush fill, not fill is actually transparent, mentioned this side do not know if you have to realize the child window transparent method? Forget it, suspense, listen to me: the first window and the child controls on the window are drawn to what kind of background is by what method   tell   Span style= "Color:rgb (51,51,51); font-family: ' Microsoft Yahei '; line-height:30px "> window, the word here is very critical, is to tell not to let you code implementation, right! is to tell the parent window whether the background of this window or the child control of this window is to be drawn by default by the return value of OnCtlColor, whether it is to return this window or the child control of this window through  onctlcolor parameter uint nCtlColor type specified, when CTLCOLOR_DLG is the background color of the specified window, when it is ctlcolor_edit tell the background color of the edit box, Ctlcolor_ Button tells the default background color ...  
With the above pointing analysis, we just intercept the On_wm_ctlcolor message, and then return the empty Brush (hbrush) Getstockobject (Hollow_brush), regardless of the type of processing function. At this time the window is transparent, "the window is designated as a child window of another window, then the child window is also transparent", if you want the transparent child window to underline, draw a rectangle and so on to implement OnLButtonDown, OnLButtonUp and onmousemove message functions, Draw in the Onerasebkground processing function! Simple, huh?
OK, the above is the realization of the Window transparent 3 methods (4 kinds of transparent way, including setlayeredwindowattributes two), if still unknown white window transparent, I have the corresponding demon here, we can go to download, I hope you all have harvest, This is the power I share!
child window Transparent: http://download.csdn.net/detail/lixiang987654321/8846755
Level window transparency and child window transparency: http://download.csdn.net/detail/lixiang987654321/8847067

VC realizes the transparency of the top window and realizes the transparency of the child window "Focus: child window transparent processing"

Related Article

Beyond APAC's No.1 Cloud

19.6% IaaS Market Share in Asia Pacific - Gartner IT Service report, 2018

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.