When drawing a graph using the Double Buffer technology of MFC, we often ignore a detail ----> support for the InvalidateRect function.
We know that to improve the rendering efficiency, we often only need to re-paint the area to be drawn, that is, call InvalidateRect.
Generally, the OnPaint processing code is:
CWnd: OnPaint ()
{
CPaintDC dc (this );
CMemoryDC memDC (& dc );
// Draw with memDC
DrawByMemoryDC (& memDC );
// Copy to CPaintDC
Dc. Bilt (memDC );
}
Here, CPaintDC will process the Rect parameters passed in by the InvalidateRect function. pixel painting and copying operations are not performed in the Rect region, but our CMemoryDC does not, therefore, dual buffering is very inefficient.
To solve this problem, you can use the following method to crop areas that do not need to be drawn:
CRect invalidateRect = dc. m_ps.rcPaint; // dc is CPaintDC
If (invalidateRect. left> m_rtClient.left) // m_rtClient indicates the size of the customer zone.
{
CRect leftClipRect (m_rtClient.left, m_rtClient.top, invalidateRect. left, m_rtClient.bottom );
MemDC. ExcludeClipRect (leftClipRect );
}
If (invalidateRect. top> m_rtClient.top)
{
CRect topClipRect (invalidateRect. left, m_rtClient.top, invalidateRect. right, invalidateRect. top );
MemDC. ExcludeClipRect (topClipRect );
}
If (invalidateRect. bottom <m_rtClient.bottom)
{
CRect bottomClipRect (invalidateRect. left, invalidateRect. bottom, invalidateRect. right, m_rtClient.bottom );
MemDC. ExcludeClipRect (bottomClipRect );
}
If (invalidateRect. right <m_rtClient.right)
{
CRect rightClipRect (invalidateRect. right, m_rtClient.top, m_rtClient.right, m_rtClient.bottom );
MemDC. ExcludeClipRect (rightClipRect );
}
This article from "fall in love with the floor" blog, please be sure to keep this source http://mmmn143.blog.51cto.com/2541616/1266181