Troubleshoot problems with flashing pictures on the screen copying DCS

Source: Internet
Author: User

This article summarizes the problems that have recently been encountered with double-buffered drawing. (Copy someone else's writing is very good)

Double buffering is an issue that uses frequent techniques in drawing to prevent drawing flicker.

Working with Frames:

CDC M_MEMDC;

Initializing a compatible memory DC
M_memdc.createcompatibledc (PDC);
CBitmap M_bmpwave;

Creating device-compatible bitmap buffers
if (!m_bmpwave.createcompatiblebitmap (pdc,m_bmpwidth,m_bmpheight))
{
Errormessagebox (Ids_createbitmaperror);
return false;
}
Select a bitmap to use in a memory DC for drawing
M_poldbmp = M_memdc.selectobject (&m_bmpwave);

Here you use a memory DC for various drawing operations

.......

Pdc->bitblt (0,0,width,height,&m_memdc,0,0,srccopy); Copy the memory image to the current device DC to complete the display of the drawing

Subsequent treatment

The framework is like this, talk about the problems I have encountered.

1. The memory bitmap cannot be displayed in the device DC.

Of course, my code is much more. So the situation is difficult to debug, only to estimate possible problems. Through debugging and analysis, find out the problem. For some reason, I used two memory DC, I first selected bitmap through SelectObject to the first memory DC to draw, and then the second memory DC in the same bitmap selected and deformed operation, The second memory DC is then copied through the BitBlt to the current device DC. Initially, the bitmap was not copied successfully, the problem is that the second DC when the bitmap is selected, the first memory DC does not have bitmap selected, so the problem should be bitmap can not be selected at the same time two different DC operation. The problem is found, and the solution is either, or before the second DC is selected, the first DC is chosen first. Either use only a single memory DC.

This issue was later seen in MSDN as follows:

An application can select a bitmap to memory device contexts only and into the one memory device context at a time.

To prove my idea is correct. It seems that the document should be looked at more, a lot of questions in the document are actually described.

2. When the memory bitmap is copied, it is displayed in black and white.

This is the way the bitmap was created, CreateCompatibleBitmap (Pdc,m_bmpwidth,m_bmpheight), the first parameter to create a bitmap represents the device DC, and the bitmap will use the color and format compatible with the device DC. If a pointer to a memory DC is passed in, the bitmap uses the color board of the memory DC. The memory DC defaults to black-and-white mode. So bitmaps created using memory DC are naturally black and white.

Explanation of MSDN:

When a memory device context is created, GDI automatically selects a monochrome the stock bitmap for it.

If PDC is a memory device context, the bitmap returned have the same format as the currently selected bitmap in that device Context.

Well, the solution is to use the current device DC to create a bitmap instead of a memory DC.

Troubleshoot screen flicker problems replicating DC issues

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.