Three methods to maintain the image output by the CDC-3

Source: Internet
Author: User

To continue with the previous two topics, the third way to enable the CDC to maintain its output graphics is to use compatible DC.

  

Ideas

First, use the current drawing DC to create a compatible DC.

Compatible with DC is equivalent to a reference to the DC associated with it. It is like a canvas where users draw images. When the screen weight is painted, copy the canvas directly to the current DC to maintain the image. Speaking of a canvas, DC is compatible with a bitmap of the same size as the current customer's region.

 

The Code is as follows:

Void CGraphicView: OnLButtonUp (UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CClientDC dc (this );
CBrush * pBrush = CBrush: FromHandle (HBRUSH) GetStockObject (NULL_BRUSH ));
Dc. SelectObject (pBrush );

// If the compatible DC has been created, no more
If (! M_dcCompatible.m_hDC)
{
M_dcCompatible.CreateCompatibleDC (& dc );
CRect rect;
GetClientRect (& rect );
CBitmap bitmap ;,
// Construct a bitmap with the same size as the current customer Zone
Bitmap. CreateCompatibleBitmap (& dc, rect. Width (), rect. Height ());
M_dcCompatible.SelectObject (& bitmap );
M_dcCompatible.BitBlt (0, 0, rect. Width (), rect. Height (), & dc, 0, 0, SRCCOPY );
M_dcCompatible.SelectObject (pBrush );
}
Switch (m_nDrawType)
{
Case 1:
M_dcCompatible.SetPixel (point, RGB (0, 0 ));
Break;
Case 2:
M_dcCompatible.MoveTo (m_ptOrigin );
M_dcCompatible.LineTo (point );
Break;
Case 3:
M_dcCompatible.Rectangle (CRect (m_ptOrigin, point ));
Break;
Case 4:
M_dcCompatible.Ellipse (CRect (m_ptOrigin, point ));
Break;
}
CScrollView: OnLButtonUp (nFlags, point );
}

When the window needs to be re-painted, the compatible DC is used to build the image. The Code is as follows:

Void CGraphicView: OnDraw (CDC * pDC)
{
CGraphicDoc * pDoc = GetDocument ();
ASSERT_VALID (pDoc );

CRect rect;
GetClientRect (& rect );
// Use the copy method to re-draw the image
PDC-> BitBlt (, rect. Width (), rect. Height (), & m_dcCompatible, SRCCOPY );
}

This method is simple and easy to understand.

These three methods have finally been written, which is a summary of your own learning!

 

 

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.