Solution for Windows GDI mapping flicker in Visual C + + programming _c language

Source: Internet
Author: User

The example in this article describes the solution for Windows GDI mapping flashing in Visual C + + programming. Share to everyone for your reference. Specifically as follows:

The general Windows complex interface needs to use multiple layers of windows and be embellished with textures, so it's inevitable to flicker 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 principle, the call to the GDI function to the screen output is not immediately displayed on the screen
is just written to the memory, and the video card every time the contents of the memory output to the screen, this is the refresh cycle.

The general video card refresh cycle is 1/80 seconds or so, the specific number can set itself.

This is the problem, general drawing is the background color first, and then the contents of the painting, if these two operations are not the same
Refresh cycle, then give people the visual feeling is, first see only the background color of the image, and then see the picture of the content,
This will feel the flicker.

Workaround:

As fast as possible to output the image, so that the output in a refresh cycle to complete, if the output of a lot of slow, then use
Memory buffering method, first the content to be output in memory ready, and then output to video memory. To know that an API call can generally
Completed in a refresh cycle.

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

Reason two:

The complex interface has multiple layers of windows, when Windows changes the size of the window is the first redraw the parent window, and then redraw the child window, child parent
The process of painting a window can generally not be completed within a refresh cycle, so it renders a flicker.

We know there's no need to repaint the part of the parent window that covers the Quilt 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 will not be repaint.

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

Reason three:

Sometimes you need to use some control on the window, ie, when you change the size of the window IE will blink, even if you have a Ws_clipchildren
is useless. The reason is that the class style of the window has Cs_hredraw or cs_vredraw, which means that the window changes in width or height
Repaint, but this will cause IE to blink

Workaround:

When registering a window class, do not use these two styles, if the window needs to change the size of the time to repaint, then you can wm_size
Call RedrawWindow.

Reason four:

There are many windows on the interface, and many windows are moved and resized when resized, and 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 finished before returning, so the process is slow, so that the visual effects may flicker.

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 the size and position of all windows at once.

There is a place to pay special attention to carefully calculate how many windows to move, Begindeferwindowpos set
The number must be consistent with the actual number, otherwise under Win9x, if the actual number of Windows moved more than the call Begindeferwindowpos
The number of times set, may cause system crashes. There is no such problem under the Windows NT series.

I hope this article will help you with the Visual C + + program design.

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.