Experience in solving windows program interface flash Problems

Source: Internet
Author: User
Http://blog.joycode.com/yaodong/archive/2004/11/26/39764.aspx
Experience in solving windows program interface flash Problems

Generally, complex Windows interfaces require multi-layer windows and textures for beautification. Therefore, it is inevitable that the window will flash when moving or changing the size.

Let's talk about the causes of flickering.

Cause 1:
If you are familiar with the graphics card principle, calling the GDI function to output to the screen is not immediately displayed on the screen.
It is only written to the video memory, and the video card outputs the video content to the screen at intervals, which is the refresh cycle.

Generally, the refresh cycle of a video card is about 1/80 seconds. You can set the number on your own.

This is the problem. Generally, the background color is first painted, and then the content is painted. If these two operations are not the same
After the refresh period is completed, the visual experience is to first see the image with only the background color, and then see the image on the painting,
In this way, you will feel flickering.

Solution: output the image as quickly as possible so that the output can be completed within a refresh cycle. If the output content is much slower, use
The memory buffer method first prepares the content to be output in the memory and then outputs the content to the video memory at a time. You must know that an API call is generally acceptable.
Completed within a refresh cycle.

For GDI, use the memory DC creation method.

Cause 2:

A complex interface consists of multiple layers of windows. When the window size is changed in windows, the parent window is re-painted first, and then the child window is re-painted.
The process of repainting windows is generally not completed in a refresh cycle, so it will flash.

We know that there is no need to reproduce the blocked part of the quilt window in the parent window.

Solution: Add ws_clipchildren style to the window so that the blocked part of the quilt window in the parent window will not be re-painted.

If there are overlapping windows at the same level, you need to add the ws_clipsiblings style.

Cause 3:

Sometimes you need to use some controls in the window, such as IE. When the size of your window changes, ie will flash, even if you have ws_clipchildren
It's useless. The reason is that the class style of the window is cs_hredraw or cs_vredraw. These two styles indicate that the window width or height changes.
Re-draw, but this will cause IE to flash

Solution: Do not use these two styles when registering the window class. If the window needs to be re-painted when the size is changed, you can use the wm_size
Call redrawwindow.

Cause 4:

There are many windows on the interface, and many windows need to be moved and changed in size when the window is changed. If you use movewindow or setwindowpos APIs
Change the size and position of the window. Because they are returned only after the window is re-painted, the process is slow and the visual effect may flash.

Solution:

Use the following APIs to process window movement: begindeferwindowpos, deferwindowpos, and enddeferwindowpos.
Call begindeferwindowpos to set the number of windows to be moved.
Use deferwindowpos to move the window. This API does not actually cause window movement.
Enddeferwindowpos changes the size and position of all windows at a time.

Pay special attention to the following points: calculate the number of windows to be moved and set begindeferwindowpos.
The number of windows must be the same as the actual number. Otherwise, in Win9x, if the number of windows actually moved is more
The number, which may cause system crashes. This problem does not occur in the Windows NT series.

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.