用directx画底图后,在ondraw中画其他东西,底图不见,why?
我现在用 directx 画一个 bmp 图,在画一些gdi的图形,但现在的现象是gdi的图形在,而底图没有出现,但拖动scrollbar,底图出现,gdi的图形没有了。
why ?
onpaint(),ondraw如下:
void CView::OnPaint()
{
CDoc * pDoc = GetDocument();
pDoc->DrawGraph(this); //画底图
CPaintDC dc(this); // device context for painting
OnPrepareDC(&dc,NULL);
OnDraw(&dc);
}
void CView::OnDraw(CDC* pDC)
{
CDoc* 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);
}
}
}
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);
}
}