Solve the window refreshing flicker

xiaoxiao2021-03-05  22

The general Windows complex interface requires the use of multi-layer windows and to beautify the map, so it is inevitably blinking when the window moves or changed.

First talk about the cause of flashing

Cause 1: If you are familiar with the graphics principle, call the GDI function to output it to the screen, it is not immediately written on the screen, and the graphics card outputs the contents of the memory to the screen every other time, this is the refresh cycle. .

The refresh period of the general graphics card is about 1/80 seconds, and the specific numbers can be set by themselves.

This is coming, and the general draw is a top picture color, then draw the content, if the two operations are not completed in the same refresh cycle, then give people a visual feeling, first see only background colors Image, then see an image of the drawing, this will feel flicker.

Workaround: Try to output an image quickly, make the output to be completed in one refresh cycle, if the output content is slow, then the method of memory buffer is used, first put the content you want to output in memory, and then output to memory once. To know that an API call can generally be completed within a refresh cycle.

For GDI, you can use the method of creating a memory DC.

Cause 2:

The complex interface has a multi-layer window consisting of windows when the window changes the size, then the process of heavy paintings, then the child window, the sub-parent window will not be completed in a refresh cycle, so it will flash .

We know that the part that blocks the sub-window on the parent window is actually not necessary to swear.

Workaround: Add a style WS_CLIPCHILDREN to the window so that the part that is blocked by the sub-window on the parent window will not call.

If there is a overlap between the same level window, then you need to add a WS_CLIPSIBLINGS style.

Reason three:

Sometimes I need to use some controls on the window, such as IE, IE will flash when your window changes, even if you have WS_CLIPCHILDREN. The reason is that the window of the window has CS_HREDRAW or CS_VREDRAW, and the two styles indicate that the window will redraw when the width or height changes, but this will cause IE flashing.

Workaround: Do not use these two styles when registering window classes, if the window needs to redraw while changing the size, then call RedRawWindow when WM_SIZE.

Cause four:

There are many windows on the interface, and change the larger hours to move and change the size. If you use MoveWindow or SetWindowPos two APIs to change the size and location of the window, because they are waiting for window heavy blow to return, so the process is very slow Such visual effects may flash.

Solution:

Use the following API to handle the window movement, BegindeferWindowPos, DeferWindowPos, EnddeferWindowPOS first invoke the number of webs that you need to move Use DeferWindowPos, move the window, this API doesn't really cause window moving EnddeferWindowPos to complete all the windows of all windows and Location changes.

There is a place to pay special attention to it. To carefully calculate how many windows you want to move, the number of BegindeferWindowPos must be consistent with the actual number, otherwise, if the actual moving window is more than calling BeGindeferWindowPos The number of settings may cause the system to crash. There will be no such problem under the Windows NT series.

// Author added:

If you set the drag window to display the window content in the property, the screen looks a lot. You can get off in your application via API SystemParameters (). This will look better in the user. This is just my personal suggestion. The above article is very good, it will be reposted.

转载请注明原文地址:https://www.9cbs.com/read-38561.html

New Post(0)