这里贴上代码:
void CMyDlg::OnPaint() 
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0); // Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2; // Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CPaintDC dc(this); // device context for paintingBITMAP bm;
CBitmap bmp;//定义CBitmap 类的对象
bmp.LoadBitmap(IDB_BITMAP2);//装入ID号为IDB_BITMAP1的位图
CDC memdc;//定义CDC类的对象
CRect rect;
memdc.CreateCompatibleDC(NULL);//创建与显示DC相兼容的内存DC
bmp.GetBitmap(&bm);
CBitmap *bmpold=memdc.SelectObject(&bmp);//将选定的位图选入内存DC
this->GetClientRect(&rect);
//从内存DC向显示DC复制,rect.left,rect.top为图像左上角的坐标,SRCCOPY表示直接将源位图拷贝到目的位图,不作修改
dc.BitBlt(rect.left+x,rect.top+y,bm.bmWidth,bm.bmHeight,&memdc,0,0,SRCCOPY);
memdc.SelectObject(bmpold);
memdc.DeleteDC();
bmp.DeleteObject(); 
CDialog::OnPaint();
}
}
void CMyDlg::OnLButtonDown(UINT nFlags, CPoint point) 
{
// TODO: Add your message handler code here and/or call default
a=1;
m_point=point;
CDialog::OnLButtonDown(nFlags, point);
}
void CMyDlg::OnLButtonUp(UINT nFlags, CPoint point) 
{
// TODO: Add your message handler code here and/or call default

a=0;
InvalidateRect(NULL,true);
CDialog::OnLButtonUp(nFlags, point);
}
void CMyDlg::OnMouseMove(UINT nFlags, CPoint point) 
{
if(a==1){
x=x+point.x-m_point.x;
y=y+point.y-m_point.y;

m_point=point;
                  RedrawWindow();
}
CDialog::OnMouseMove(nFlags, point);
}

解决方案 »

  1.   

    建议你整个背景做成白色的。也就是临时的DC做成DLG一样的大小,然后在上面画,画完再整个贴到对话框上。
      

  2.   

    WM_ERASEBKGND函数return TRUE了,就不会刷新背景了。而只要刷新背景肯定会闪。所以,必须不能刷新背景。。这样,就只能在你的缓冲DC里手动刷背景,也就是先刷成想要的背景色。
      

  3.   

    最简单用CDC的函数FillSolidRect可以实现。还有很多其他方法。
      

  4.   

    你要不闪,就在OnEraseBkgnd中刷新,不要在onpaint中。
      

  5.   

    memdc.FillSolidRect(rect,RGB(255,255,255));,这样用对吗?,可是还是会有拖动痕迹啊
      

  6.   

    你应该做一个大的DC。
    CDC tempDC;
    使用GetClientRect获取客户区大小,也就是对话框内部大小。
    CBitmap bmp;
    bmp.CreateCompatibleBitmap(DC*, width, height)。
    刷新tempDC后把你加载的BMP的DC,BitBlt到这个tempDC。也就是在tempDC上画。
    画完后(除了画你的图片,你还可以画很多其他东西),最后再将tempDC直接画到dc上。这才算是双缓冲。你原来的画法是把自己的图片直接画到DC上,实际上没有缓冲的。
      

  7.   

    我一般是这样做: RECT rtClt;
    GetClientRect(&rtClt);
    long h = (rtClt.bottom - rtClt.top);
    long w = (rtClt.right - rtClt.left); CDC tempDC;
    CBitmap tempBmp, *pTmpBmp;
    tempDC.CreateCompatibleDC(&dc);
    tempBmp.CreateCompatibleBitmap(&dc, w, h);
    pTmpBmp = tempDC.SelectObject(&tempBmp); // 刷新tempDC背景
    // .. 这时在tempDC上绘制 dc.BitBlt(0, 0, w, h, &tempDC, 0, 0, SRCCOPY); tempDC.SelectObject(pTmpBmp);
    tempBmp.DeleteObject();
    tempDC.DeleteDC();
      

  8.   

    最后,我一般用Invalidate(FALSE)刷新对话框。这样,不用改WM_ERASEBKGND。
    WM_ERASEBKGND还是按原来的做,因为有时的确需要刷新整个对话框背景。
      

  9.   

    还是搞不出来啊,我弄了两个CDC,出不了图
      

  10.   

    你要不闪,就在OnEraseBkgnd中绘制,不要在onpaint中。