I recently saw the following text on the Internet for processing graphics.
Most of our drawing processes are stored in the ondraw or onpaint functions. ondraw calls onpaint for screen display. When the window needs to be re-painted for any reason
Always use the background color to clear the display area and then call onpaint. The background color often has a large contrast with the drawing content, so that the background color and the display image alternate in a short time, display window
It looks like a flash.
..........................
This requires the dual-Cache method. In addition to displaying images on the screen, the dual-buffer mode also displays images in the memory. We can first draw the image to be displayed in the memory, and then one time
To overwrite the images in the memory to the screen at a point by point (this process is very fast, because it is a very regular memory copy ). In this way, you can use any background color with a large contrast when drawing in the memory.
The Division will not Flash because it cannot be seen. When it is attached to the screen, the final image in the memory is slightly different from the screen display image (if there is no motion, of course there is no difference), so that it will not flash.
I wrote an article for the first time. please correct me if something is wrong .. dual cache: Prepare an area in the memory, load the bitmap to be displayed to the memory, and then call the bitblt function to copy the memory device to the display device, in this way, the screen will be blocked .. the following are the implementation steps in VC ..
1. Create a single-document MFC program named test1.
2. Add two member functions in ctest1view: void showbmp usedbbuffer (); // use the Double Cache to display the bitmap void showbmp (); // The bitmap is displayed without the Double Cache .. add a menu command, start timer, and observe the two effects
3. The main implementation code is as follows:
// Use the dual-Cache Technology to display bitmaps to prevent screen flashes
Void ctest1view: showbmp usedbbuffer ()
{
CDC * PDC = getdc ();
Cbitmap BMP back, BMP front, bmp mem; // background, foreground, memory bitmap
CDC backdc, frontdc, memdc; // background device, foreground device, and memory device
// Create a bitmap compatible with the Display Device
BMP mem. createcompatiblebitmap (PDC, 1024,768 );
// Load bitmap
BMP back. loadbitmap (idb_bitmap_back );
BMP front. loadbitmap (idb_bitmap_front );
// Create a device compatible with the Display Device
Backdc. createcompatibledc (PDC );
Frontdc. createcompatibledc (PDC );
Memdc. createcompatibledc (PDC );
// Select the bitmap device.
Memdc. SelectObject (& BMP MEm );
Backdc. SelectObject (& BMP back );
Memdc. bitblt (0, 0, 1024,768, & backdc, 0, 0, srccopy );
// Select the foreground bitmap into the device
Frontdc. SelectObject (& BMP front );
Memdc. bitblt (0, 0, 1024,768, & frontdc, 0, 0, srccopy );
// Display the bitmap to the display device only once, and no pop-up screen will appear
PDC-> bitblt (0, 0, 1024,768, & memdc, 0, 0, srcand );
// Release resources
PDC-> deletedc ();
Backdc. deletedc ();
Frontdc. deletedc ();
Memdc. deletedc ();
}
// The dual cache technology is not used, and a pop-up screen appears.
Void ctest1view: showbmp ()
{
CDC * PDC = getdc ();
Cbitmap BMP back, BMP front; // background, foreground bitmap
CDC backdc, frontdc; // background device, foreground device, and memory device
// Load bitmap
BMP back. loadbitmap (idb_bitmap_back );
BMP front. loadbitmap (idb_bitmap_front );
// Create a device compatible with the Display Device
Backdc. createcompatibledc (PDC );
Frontdc. createcompatibledc (PDC );
// Select the background bitmap device.
Backdc. SelectObject (& BMP back );
PDC-> bitblt (0, 0, 1024,768, & backdc, 0, 0, srccopy); // display the background bitmap
// Select the foreground bitmap into the device
Frontdc. SelectObject (& BMP front );
PDC-> bitblt (0, 0, 1024,768, & frontdc, 0, 0, srccopy); // display foreground bitmap
/************************
Display bitmap twice (displays the background first and then the foreground ),
A pop-up screen is displayed.
**************************/
// Release resources
PDC-> deletedc ();
Backdc. deletedc ();
Frontdc. deletedc ();
}
//
// Add a menu command to start a timer
Void ctest1view: onmenuitemstart ()
{
// Todo: add your command handler code here
Settimer (1, 5, null );
}
// In the ontimer () function, view the two effects
Void ctest1view: ontimer (uint nidevent)
{
// Todo: add your message handler code here and/or call default
Showbmp usedbbuffer (); // uses the dual-Cache Technology to display bitmaps to prevent transient screens.
// Showbmp (); // The Double Cache Technology is not used, and a pop-up screen is displayed.
Cview: ontimer (nidevent );
}