在程序运行后,当有其他窗体在上面移动时,不能正常显示。请高手赐教!
void CDrawView::OnDraw(CDC* pDC)
{
CDrawDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);

CDC dc;
CDC* pDrawDC = pDC;
CBitmap bitmap;
CBitmap* pOldBitmap; // only paint the rect that needs repainting
CRect client;
pDC->GetClipBox(client);
CRect rect = client;
DocToClient(rect); if (!pDC->IsPrinting())
{
// draw to offscreen bitmap for fast looking repaints
if (dc.CreateCompatibleDC(pDC))
{
if (bitmap.CreateCompatibleBitmap(pDC, rect.Width(), rect.Height()))
{
OnPrepareDC(&dc, NULL);
pDrawDC = &dc; // offset origin more because bitmap is just piece of the whole drawing
dc.OffsetViewportOrg(-rect.left, -rect.top);
pOldBitmap = dc.SelectObject(&bitmap);
dc.SetBrushOrg(rect.left % 8, rect.top % 8); // might as well clip to the same rectangle
dc.IntersectClipRect(client);
}
}
} // paint background
CBrush brush;
if (!brush.CreateSolidBrush(pDoc->GetPaperColor()))
return; brush.UnrealizeObject();
FillOutsideRect(pDrawDC,&brush,client);//在后面 pDoc->Draw(pDrawDC, this); if (pDrawDC != pDC)
{
pDC->SetViewportOrg(0, 0);
pDC->SetWindowOrg(0,0);
pDC->SetMapMode(MM_TEXT);
dc.SetViewportOrg(0, 0);
dc.SetWindowOrg(0,0);
dc.SetMapMode(MM_TEXT);
pDC->BitBlt(rect.left, rect.top, rect.Width(), rect.Height(),
&dc, 0, 0, SRCCOPY);
dc.SelectObject(pOldBitmap);
}}
void CDrawView::FillOutsideRect(CDC* pDC, CBrush* pBrush,CRect rect)
{
CRect rectClient;
rectClient = rect;

pDC->SaveDC(); // draw the document background
CRect PaperRect(CPoint(0,0),PaperSize);
DocToClient(PaperRect);
CRect rectDoc = PaperRect;
CRect ClientRect = rectClient;
rectDoc.OffsetRect((ClientRect.Width() - PaperRect.Width())/2,PageTopMargin);
pDC->FillRect(rectDoc, pBrush); // draw the client area
CRect draw;
CBrush SideBrush(RGB(128,128,128));
//CBrush SideBrush(::GetSysColor(COLOR_APPWORKSPACE));
draw.SetRect(rectClient.left, rectClient.top, rectDoc.left, rectClient.bottom);
if (!draw.IsRectEmpty()) pDC->FillRect(draw, &SideBrush);
draw.SetRect(rectDoc.right, rectClient.top, rectClient.right, rectClient.bottom);
if (!draw.IsRectEmpty()) pDC->FillRect(draw, &SideBrush);
draw.SetRect(rectClient.left, rectClient.top, rectClient.right, rectDoc.top);
if (!draw.IsRectEmpty()) pDC->FillRect(draw, &SideBrush);
draw.SetRect(rectClient.left, rectDoc.bottom, rectClient.right, rectClient.bottom);
if (!draw.IsRectEmpty()) pDC->FillRect(draw, &SideBrush); // draw the document frame (from ViewScrl.cpp)
CPen rectPen, shadowPen;
rectPen.CreatePen(PS_SOLID, 2, ::GetSysColor(COLOR_WINDOWFRAME));
shadowPen.CreatePen(PS_SOLID, 3, ::GetSysColor(COLOR_BTNSHADOW)); pDC->SelectStockObject(HOLLOW_BRUSH);
pDC->SelectObject(&rectPen);
rectDoc.InflateRect(1, 1, 2, 2);
pDC->Rectangle(rectDoc);
    
pDC->SelectObject(&shadowPen);
pDC->MoveTo(rectDoc.right + 1, rectDoc.top    + 2);
pDC->LineTo(rectDoc.right + 1, rectDoc.bottom + 1);
pDC->MoveTo(rectDoc.left  + 2, rectDoc.bottom + 1);
pDC->LineTo(rectDoc.right + 1, rectDoc.bottom + 1); rectPen.DeleteObject();
shadowPen.DeleteObject(); pDC->RestoreDC(-1);
}