Since the mapping is too complex and frequent, it often flicks, and some methods of preventing flicker are as follows:
(1) Replace INVALIDATE () with INVALIDATERECT (). Invalidate () will cause image redraw between the entire window, which requires a longer time, and invalidateERECT () only retires content in the Rect area, so the required time will be less. Don't call Invalidate for a small area, you don't want yourself to calculate the RECT that needs to be redempt. In fact, if you really need to improve the blink, calculate the time used by RECT is more than once. There is a much less time to need to redraw content.
(2) Prohibition of the system erase your window. The system will help you use the specified background color to erase the window with the specified background. However, it may be very small in the area that needs to be heavy. Alternatively, in your redraw between these things, you have to start a lot of calculations. At this time you can prohibit the system from erase the original image. Until you have calculated all the data, you will cover the parts that need to be wiped with a background color (such as: Dc.FillRect (Rect, & Brush); RECT is the area that needs to be erased, brush is a brush with a background color. ), Draw new graphics. To prohibit the system from erase your window, you can reload the onerasebkgnd () function, allowing it to return True. Such as Bool CMywin :: OneRaseBkGnd (CDC * PDC) {Return True; // Return CWnd :: OneRaseBkGnd (PDC); // comment out the original statement of the system. }
(3) Effective erase. When erase the background, don't rub the wipe. For example, let you put a big Edit box on a window, almost the entire window, then you frequently erase the entire window background will cause the Edit to continue to combat a dramatic flash. In fact you can create a CRGN The area that needs to be erased, only erase this part. Such as
GetClientRect (RectClient); RGN1.CreateRectrGnIndirect (RectClient); Rgn2.createRectRgnIndirect (m_RECTEDIT);
IF (RGN1.Combinergn (& RGN1, & RGN2, RGN_XOR) = error) // After processing RGN1 only includes customer area outside the Edit box, this, Edit will not be overwritten by my background and lead to redraw. {Assert (False);} brush.createsolidbrush (m_clrbackgnd); PDC-> FillRgn (& RGN1, & Brush); brush.deleteObject (); Note: Method 2 is used at the same time when using this method.
(4). Using Memorydc first in memory, replicates the picture, replicates to the screen. This is used for a long time for a drawing process. After all, the memory operation is relatively fast, and the copy to the screen is one-time, at least there will be clearly seeing a situation from left to the right.
Void CMYWIEW :: OnDraw () // CScrollView Under Double Buffer Memory Realization: {CRECT Rect; GetClientRect (& Re);
CDC * m_pmemorydc = new CDC (); cbitmap * m_pbitmap = new cbitmap ();
Cpoint scrollpoint = getScrollPosition ();
m_pMemorydc-> CreateCompatibleDC (PDC); m_pbitmap-> createcompatiblebitmap (PDC, Rect.right 1, Rect.bottom 1); // The bitmap here is necessary, otherwise we have a big black block. cbitmap * PoldBMP = m_pMemorydc-> selectObject (m_pbitmap); // m_pmemorydc-> selectstockObject (white_brush); // Draw a white background method One //m_pmemorydc->Rectangle (1, 1 ,ract.right 2, Rect.bottom 2 ); // m_pmemorydc-> selectstockObject (null_brush);
m_pMemorydc-> Patblt (0, 0, Rect.right, Rect.Bottom, Whitness); // Draw a white background method 2
// ---------------- as follows is the way to display pictures ----------------------- -------------------------------- // bitmap bm; // cbitmap pbitmap; //pbitmap.loadbitmap(IDB_bitmap2 ); // cdc * PTDC = new CDC (); // PTDC-> CreateCompaTibleDC (PDC); // cBitmap * POM = PTDC-> SelectObject (& Pbitmap); // Pbitmap-> GetObject (Sizeof (BM), & BM ); //M_pmemorydc/bitbitblt(0-scrollpoint.x,0-scrollpoint.y, bm.bmwidth, bm.bmheight, ptdc, 0,0, srcopy; // PTDC-> deletedc (); // delete PTDC; // -------------- picture shows ----------------------------- -----------------------------------------
// m_pmemorydc-> setrop2 (r2_not); // Set the drawing mode
m_pMemorydc-> MoveTo (0-scrollpoint.x, 0-scrollpoint.y); m_pMemorydc-> lineto (1000-scrollpoint.x, 5000-scrollpoint.y);
PDC-> Bitblt (scrollpoint.x, scrollpoint.y, reference.right, rect.bottom, m_pmemorydc, 0, 0, srcopy);
M_PMEMORYDC-> SelectObject (PoldBMP); m_pbitmap-> deleteObject (); m_pmemorydc-> deletedc ();
Delete m_pbitmap; delete m_pmemorydc;}