Interface flash in Windows user interface programming
Source: Internet
Author: User
Interface flash in Windows user interface programming
In Windows graphical user interface programming, if a program draws a user interface by itself, the interface will often flash. For example, if other Windows are moved above, the user interface will scroll, which may lead to flickering. To draw a specific document in a container, you must use the OnPaint event as the control of the drawing container, and re-draw the document in the OnPaint event processing, in Windows, the OnPaint event is triggered in two cases: the container control is overwritten by other forms and then displayed, and the container control is rolled. In these cases, the Windows operating system will frequently trigger the OnPaint event, and the application will frequently re-draw the image in the drawing container. If the application is not well optimized, the user interface is likely to flash.
There are a lot of natural harm to the user interface flickering. First, it makes your program look unprofessional and even suspected of being unstable. You will allow it to exist in the pursuit of perfection; second, flashing will damage your eyesight and lead to visual fatigue.
Okay, I will not talk much about it. We will find the problem, analyze the problem, and solve the problem.
First of all, let's talk about the essence of the flash. When it comes to the essence, we have to mention some knowledge about the computer system structure and Windows Graphic User subsystem. We know that there is an area in the computer memory called video memory, while the video card scans the video memory every several milliseconds, and then draws pixels based on the operating display, therefore, the content displayed on the monitor is reset every few milliseconds. This is a hardware operation and is very fast. If the screen content does not change, the human eye cannot see this refresh, at this time, the user interface does not flash.
The figure on the right shows how the application draws the user interface. The application fills data in the display memory with the CPU support, and the video card also loads data from the display to draw the image, (If the application can directly access the display, the rendering speed should not be too fast), and the flickering user interface is rooted in this display structure. As mentioned above, the video card scans the video memory every several milliseconds to refresh the display of the display. If a display card is configured with a refresh frequency of 50Hz, it scans the display memory to refresh the display every 20 milliseconds, however, there is no relationship between the operations of the video card and the operations of the application. The video card comes with a processor, so the two objects of the application and the video card operate on the video card at the same time, the video card only reads the video memory, while the application modifies the video memory, which leads to data synchronization issues similar to multi-threaded programs. However, the hardware structure determines that there is no locking mechanism available at this time. The video card is refreshed every 20 ms, and the operating system cannot be blocked, and the application does not know when the video card will be refreshed.
At a certain time point, the application needs to draw the user interface. First, it needs to clear the drawing container, so it sets a large area of the display to white, and the application has just completed the clearing operation, every time you have time to draw the content, the video card is refreshed, and soon a large white area is displayed on the display. At the same time, the application starts to draw content, and the application runs slowly. It draws the upper half of the document in 20 milliseconds. The upper half of the document is mainly red, and the upper half is just drawn, the video card is refreshed relentlessly, and soon half of the documents are displayed on the display. Half of the white color is red. In this case, the display turns white, then, half of the display changes to red. At this time, the content of the display changes significantly twice, and then the application shows the lower body of the document for 20 milliseconds. The lower body of the document is mainly green, at this time, the video card is refreshed, and the remaining white on the other half of the display turns green. As the application draws a document, the display is no longer modified, and the display content of the monitor is no longer changed.
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.