利用双缓冲技术解决屏闪问题需要注意的还有在利用 Invalidate发送消息的时候Invalidate(FLASE)表示不擦出原来直接开始绘制Invalidate(TRUE)表示将所有的擦出后重新绘制 void CMyCADView::OnDraw(CDC* pDC) { //获得View矩形区域 RECT rect; this->GetClientRect(&rect); //建立内存DC CDC hmemdc; hmemdc.CreateCompatibleDC(pDC); //建立一个与pDC内的位图一样的内存位图 CBitmap membitmap; membitmap.CreateCompatibleBitmap(pDC,rect.right,rect.bottom); //将内存位图与内存DC绑定 hmemdc.SelectObject(membitmap); //将内存DC背景设置白色 hmemdc.FillSolidRect(0,0,rect.right,rect.bottom,RGB(255,255,255)); //获得链表当前pos POSITION pos = m_Linelist.GetHeadPosition(); //遍历链表 绘画之前保存的图 Cline CurLine; while (pos) { CurLine = m_Linelist.GetNext(pos); CPen pen(CurLine.GetPenStyle(),CurLine.GetWidth(),CurLine.GetColor()); hmemdc.SelectObject(pen); hmemdc.MoveTo(CurLine.GetBeginPoint()); hmemdc.LineTo(CurLine.GetEndPoint()); } //绘画当前的图 CPen Curpen(m_nPenStyle,m_nWidth,m_crColor); hmemdc.SelectObject(Curpen); hmemdc.MoveTo(m_BeginPoint); hmemdc.LineTo(m_EndPoint); //一次性将内存DC中的内容全部画到当前DC中 pDC->BitBlt(0,0,rect.right,rect.bottom,&hmemdc,0,0,SRCCOPY); //MFC CMyCADDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); // TODO: add draw code for native data here }