Use Duilib to develop translucent alien form programs (with source code and demo)

Source: Internet
Author: User

Reprint please explain the original source, thank ~~:http://blog.csdn.net/zhuhongshu/article/details/43532791

The function of the translucent shaped form has already had the basic function in the old version of the Duilib, but because there have been more defects, I have been suggesting less use, even my own to write a cool dog project is only in a few small places with a translucent shaped form. But today, after discussing with several other friends in the group, we found many problems and solutions. So I instantly repaired the current library and wrote a demo of the translucent alien form to test the effect. The translucent form here is implemented with the Updatelayeredwindow function, not a double-decker form.


In this blog, I mainly explain a few points:


1. Some problems existed in the previous version using translucent shaped form

2, the new version of the approximate solution

3. Where there is no complete solution

4, the use of translucent shaped form should pay attention to the place


Don't say much nonsense, first show the demo:



Existing Problems and solutions:


Issue 1: Font penetration

This is the biggest problem of the previous translucent form, due to the shortcomings of GDI itself, resulting in the lack of transparent channel information when rendering text, resulting in text penetration, before using the Heat group master Alpha repair method, but not completely solve the problem. For this I have modified the text rendering function. When the form is transparent or the user turns on GDI + text rendering mode, the text is rendered using GDI +. The way to turn on semitransparent mode is to set the Bktrans property of the window label for the XML layout to True. The way to turn on GDI + text rendering mode is to set the Gdiplustext property of the window label for the XML layout to True. The Bktrans property and the Gdiplustext property are independent. (If you feel that the default GDI text rendering isn't good enough, you can use the Gdiplustext property to get better rendering).


GDI + 's rendering efficiency is known to be low, but according to my Test text rendering only with GDI + words can not see the impact of efficiency.


Issue 2: Font penetration 2

Or the font through the text, even if the text rendering to GDI + and the alpha repair, but still found that there will be a problem of font penetration, which is what I wondered before. And today I did a lot of tests and found that it was related to the background color of the control. If you do not set the background color of the control or the back color is translucent, the rendered text will not penetrate, and the background color is set and the opacity will penetrate, and the background color fill is responsible for the Drawcolor function of the Crenderenghine class. Observed source after discovery. If the background color's transparency is set to FF (that is, opaque), the background color is populated with GDI functions, and if transparency is set, the AlphaBlend function is used to populate the background with a bitmap. So the problem is still on the transparent channel (which means that the alpha fix doesn't solve the problem completely).


So as long as you let duilib fill the background color with transparent information will not cause penetration, and then read the code found duilib the default alpha background color padding code more. I personally feel better to fill the background color directly with GDI +. The code is as follows:


    if (color <= 0x00ffffff) return; Gdiplus::graphics Graphics (HDC); Gdiplus::solidbrush Brush (Gdiplus::color ((lobyte (color) >>24), Getbvalue (color), getgvalue (color), Getrvalue (color)); graphics. FillRectangle (&brush, Rc.left, Rc.top, Rc.right-rc.left, rc.bottom-rc.top);


This code is relatively simple, should not affect the efficiency it?


Issue 3: Form Refresh is incomplete

The original library compiled semi-transparent special-shaped program, sometimes the form of incomplete refresh, such as: The general of a semi-transparent program dragged to the outside of the screen, and then double-click the title bar to maximize his, then minimize, and then drag the program to the screen, you will find that the original screen outside the interface is not drawn at all.


The cause of this problem is that the Updatelayeredwindow function is required to use the profiled form, and the form is drawn by the Updatelayeredwindow when the function is used, and in many cases WM_PAINT messages are not triggered. The trace code is found to be caused by incomplete information when calling the GetUpdateRect function after a program restore to obtain updated zone information. So I intercepted the wm_syscommand message in the Cmanagerui class, and found that the program was set M_bisrestore to true after maximizing the restore, M_bisrestore as a flag. Refreshes the entire program interface, not just the Getupdatertect acquired area, if M_bisrestore is true when the interface is refreshed in WM_PAINT.


Not yet fully resolved.


Some of the previously described issues are resolved with code that mates with Alpha repair. You can basically use a translucent shaped form. However, there are still some unresolved problems:

1. The edit control is not effective in translucent mode. The edit control inside the Duilib calls the Win32 edit control, and in order to use it in semitransparent mode, you have to use the edit control of the Ws_popup style form Win32. However, there are some problems with the appearance of this form. is when you click the edit control of the Duilib to Flash. It is recommended that you use the RichEdit control instead of edit, and that the RichEdit control supports semitransparent or fully transparent backgrounds.


2, although the RichEdit control can be used normally, but because of his internal rendering of the text is not processed transparent channel, it will lead to text penetration. Text penetration occurs only if the RichEdit control is completely free of background color or background image.


Where you should be aware of using translucent shaped forms


It is important to note that the use of the RichEdit control, if you let RichEdit directly exposed to full transparency, text rendering will be problematic. If RichEdit sets a background color or background color, or if his parent controls have a background color background, then all is fine. Fortunately, there should be no place for the RichEdit to be exposed directly to the full transparent position. The text box that was sent in the front is made with RichEdit.


If penetration is found when using RichEdit, it is recommended to replace the TextColor value or Bkcolor value to fix the problem.



Summarize:


As a result of this modification of more places, the design of files and code is also a bit messy, I can not provide a separate source files. Specific changes can be found by SVN to compare the new version and the old version of the code to know. Source code and demo I have updated to my library, support Duilib and Uilib: Click to open the link



Redrain 2015.2.5


Use Duilib to develop translucent alien form programs (with source code and demo)

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.