Some experience in solving the flicker Problem of Windows program interface

Source: Internet
Author: User

The general Windows complex interface needs to use multi-layered windows and to beautify with stickers, so it is unavoidable to blink when the window moves or changes size.

Let's talk about the cause of the flicker.

Reason one:
If you are familiar with the graphics card principle, the call to the GDI function output to the screen is not immediately displayed on the screen
Just write to the video memory, and the video card every time the content of the video memory output to the screen, this is the refresh cycle.

The normal graphics card refresh period is 1/80 seconds or so, the specific number can be set by themselves.

This is the problem, the general drawing is to draw the background color, and then the content is drawn up, if the two operations are not the same
Refresh period is completed, then the visual experience is that the first to see only the background color of the image, and then see the picture of the content,
This will make you feel a flicker.

Solution: As soon as possible to output the image, so that the output in a refresh cycle to complete, if the output of a lot more slowly, then the use of
Memory buffer method, first the content to be output in memory ready, and then output to video memory. To know that an API call can generally
Complete within a refresh cycle.

For GDI, the way to create a memory DC is

Reason two:

The complex interface consists of multi-layered windows that redraw the parent window when the window changes size, and then redraw the child window, the child parent
The window redraw process generally cannot be completed within a refresh period, so it will flicker.

We know there's no need to repaint the part of the quilt window that's on the parent window.

Workaround: Add a style ws_clipchildren to the window so that the part of the parent window that is blocked by the quilt window is not redrawn.

If there is overlap between sibling windows, then you need to add ws_clipsiblings style

Reason three:

Sometimes you need to use some controls on the window, ie, when your window changes size, ie flashes, even if you have Ws_clipchildren
is useless. The reason is that the class style of the window is Cs_hredraw or Cs_vredraw, which means that the window changes in width or height.
Re-painting, but this will cause IE to blink

Workaround: Do not use these two styles when registering the window class, if the window needs to change the size when the redraw, then can be in the wm_size time
Call RedrawWindow.

Reason four:

There are many windows on the interface, and many of the windows are moved and resized when changing size, if you use MoveWindow or SetWindowPos two APIs to
Change the size and position of the window, because they are waiting for the window to be redrawn before returning, so the process is very slow, so that the visual effect may blink.

Workaround:

Use the following APIs to handle window movement, Begindeferwindowpos, Deferwindowpos,enddeferwindowpos
First call Begindeferwindowpos to set the number of Windows to be moved
Using DeferWindowPos to move the window, this API does not really cause the window to move
Enddeferwindowpos changes the size and position of all windows at once.

There is a place to pay special attention to the careful calculation of how many windows to move, Begindeferwindowpos set
The number must be consistent with the actual number, otherwise under Win9x, if the number of Windows actually moved more than the call Begindeferwindowpos
Can cause the system to crash if you set the number of There is no such problem under the Windows NT series.

(go) Some experience in solving the flicker Problem of Windows program interface

Related Article

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.