OnPaint()函数中的MemDC [英] MemDC in OnPaint()-function

查看:132
本文介绍了OnPaint()函数中的MemDC的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的OnPaint()函数调用其他几个绘图函数.

My OnPaint() function calls several other drawing functions.

 void CGraph::OnPaint ()
 {
    CPaintDC dc(this);
    // CMemDC DC(&dc);

    dc.SetViewportOrg (0, 400);
    dc.SetMapMode(MM_ISOTROPIC);
    dc.SetWindowExt(1000, 800);
    dc.SetViewportExt(1000, -800);

    ProcessData ();
    DrawCoordinateSystem (&dc);
    DrawGrid (&dc);
    DrawGraph (&dc);
}

DrawCoordianteSystem的示例:

Example of DrawCoordianteSystem:

void CGraph::DrawCoordinateSystem (CDC* pDC)
{
   CPen PenBlack (PS_SOLID, 1, RGB(0, 0, 0));
   pDC->SelectObject (PenBlack);
   // Rectangle round the system
   pDC->Rectangle (0, -400, 1000, 400);
   // Horizontal axis
   pDC->MoveTo (0, 0);
   pDC->LineTo (1000, 0);
   pDC->SetTextColor (RGB(0,0,0));
   pDC->SetBkColor (RGB(240, 240, 240));
   pDC->TextOut (1001, 0, L"0");
   // Vertical axis
   pDC->MoveTo (0, -400);
   pDC->LineTo (0, 400);
}

我现在想避免使用CMemDC闪烁.但是,我无法使其正常工作.有人可以告诉我如何实现CMemDC吗?

I now want to avoid flickering with CMemDC. However, i can't get it to work right. Can somebody show me how to implement CMemDC right?

谢谢

推荐答案

您需要使用位图加载内存DC,然后将BitBlt加载到屏幕DC.

You need to load the memory DC with a bitmap to then BitBlt to the screen DC.

尝试类似的东西:

CDC dcMem;
CBitmap bitmap;

dcMem.CreateCompatibleDC( pDC );
bitmap.CreateCompatibleBitmap(pDC, rect.Width(), rect.Height())
CBitmap* pOldBitmap = dcMem.SelectObject(&bitmap);

... DO ALL YOUR DRAWING TO dcMem ...

pDC->BitBlt(rect.left, rect.top, rect.Width(), rect.Height(), &dcMem, 0, 0, SRCCOPY);

dcMem.SelectObject(pOldBitmap)

这篇关于OnPaint()函数中的MemDC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆