The following code draws at OnDraw: Void CredrawDemoview :: OnDraw (CDC * PDC)
{
CredrawDemodoc * pdoc = getDocument ();
Ask_VALID (PDOC);
// Todo: Add Draw Code for Native Data HERE
Static const char * ptext = "Solve the flashing of heavy painting!";
Rect clRect;
:: getClientRect (m_hwnd, & clRect);
PDC-> FillsolidRect (& ClRect, RGB (255, 255, 255));
INT x = 100, y = 100;
RECT = {x - 20, Y - 20};
Rect.right = Rect.Left 160;
Rect.bottom = Rect.top 60;
PDC-> FillsolidRect (& Rect, RGB (0, 25, 0));
PDC-> TextOut (X, Y, PText, Strlen (PTEXT));
}
First, fill the background, then draw a green rectangle, then output a piece of text on the rectangle, so that the process will inevitably flicker, solution: Use memory DC, first draw graphics to memory DC, then copy to the screen, implement No flash drawing. The modified code is as follows:
Void CredrawDemoview :: Ondraw (CDC * PDC)
{
CredrawDemodoc * pdoc = getDocument ();
Ask_VALID (PDOC);
// Todo: Add Draw Code for Native Data HERE
Static const char * ptext = "Solve the flashing of heavy painting!";
CRECT CLRECT;
:: getClientRect (m_hwnd, & clRect);
CDC MEMDC;
MEMDC.CREATECOMPALEDC (PDC);
CBitmap Bitmap;
Bitmap.createCompaPTMAP (PDC, ClRect.Width (), ClRect.Height ());
CBitMap * PoldbitMap = MEMDC.SELECTOBJECT (& Bitmap);
Memdc.FillSolidRect (& ClRect, RGB (255, 255, 255);
INT x = 100, y = 100;
RECT = {x - 20, Y - 20};
Rect.right = Rect.Left 160;
Rect.bottom = Rect.top 60;
Memdc.fillsolidRect (& Rect, RGB (0, 255, 0));
MEMDC.TEXTOUT (X, Y, PTEXT, STRLEN (PTEXT));
PDC-> Bitblt (0, 0, Client.width (), ClRect.Height (), & MEMDC, 0, 0, SRCCOPY;
MEMDC.SELECTOBJECT (POLDBITMAP);
}
You can also add a drawing bitmap bitmap code in the above code. Note that the window should be blocked, and the ONERASEBKGND function BOOL CREDEMOVIEW :: OneRaseBkGnd (CDC * PDC)
{
// Todo: add your message handler code here and / or call defaultreturn true;
// Return CView :: OneRaseBkGnd (PDC);
}
For easy understanding, the above code is not optimized.