怎么改写这个OnDraw()使单文档客户区绘图时不闪?
vc_xx 2008-04-17 10:35:01 在一个单文档工程中,这是我的Ondraw();
void CSTUView::OnDraw(CDC* pDC)
{
// CSTUDoc* pDoc = GetDocument();
// ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
CDocument* pDoc = GetDocument();
if(lpData==NULL)
return;
BITMAP myBITMAP;
myBITMAP.bmBits=btm.bmBits;//////////btm相当于一个全局的变量,为BITMAP btm;
myBITMAP.bmBitsPixel=btm.bmBitsPixel;
myBITMAP.bmHeight=btm.bmHeight;
myBITMAP.bmPlanes=btm.bmPlanes;
myBITMAP.bmType=btm.bmType;
myBITMAP.bmWidth=btm.bmWidth;
myBITMAP.bmWidthBytes=btm.bmWidthBytes;
BITMAPINFOHEADER bih;
bih.biBitCount=myBITMAP.bmBitsPixel;
bih.biClrImportant=0;
bih.biClrUsed=0;
bih.biCompression=0;
bih.biHeight=myBITMAP.bmHeight;
bih.biPlanes=1;
bih.biSize=sizeof(BITMAPINFOHEADER);
bih.biSizeImage=myBITMAP.bmWidthBytes*myBITMAP.bmHeight;
bih.biWidth=myBITMAP.bmWidth;
bih.biXPelsPerMeter=0;
bih.biYPelsPerMeter=0;
/////////////////////////
CBitmap tbitmap;
if(tbitmap.CreateBitmapIndirect(&myBITMAP)==NULL)
MessageBox("b mull");
if(tbitmap.m_hObject==NULL)
MessageBox("NULL");
CDC tmemdc;
tmemdc.CreateCompatibleDC(pDC);
SetDIBits(tmemdc.m_hDC,tbitmap,0,btm.bmHeight,lpData,(BITMAPINFO*)&bih,DIB_RGB_COLORS);
CRect trect;
GetClientRect(&trect);
CBitmap* lpOldbit=tmemdc.SelectObject(&tbitmap);
pDC->StretchBlt(0,0,trect.Width(),trect.Height(),&tmemdc,0,0,myBITMAP.bmWidth,myBITMAP.bmHeight,SRCCOPY);
}
这样客户显示图片时很闪烁,怎样才能把它改写成双缓冲的,也就是让它不闪烁?我试了很多次总是不成功,谢谢了