double buffering
-
Hello, I have an owner-draw listBox that while updating its flicks, I tried the solution of treating the event OnEraseBkgnd its didn't work, so I tried the other posibility - double buffering void CIconListBox::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) { pDC = CDC::FromHandle(lpDrawItemStruct->hDC); HDC memDC1 = CreateCompatibleDC(lpDrawItemStruct->hDC); HBITMAP hMemBmp = CreateCompatibleBitmap(lpDrawItemStruct->hDC, scrW, scrH); HBITMAP hOldBmp = (HBITMAP)SelectObject(memDC1, hMemBmp); CDC *memDC=CDC::FromHandle(memDC1); . . if(m_pImgClose) m_pImgClose->Draw(memDC,0,pt1,ILD_NORMAL); . . memDC->DrawText(line.word[1].str, -1, &rText, DT_LEFT); . . SetTextColor(memDC1,oldcolor); . . BitBlt(lpDrawItemStruct->hDC, 0, 0, scrW, scrH, memDC1, 0, 0, SRCCOPY); SelectObject(memDC1, hOldBmp); DeleteObject(hMemBmp); DeleteDC(memDC1); } for some resone its doing the background black instead of white as it was before the double buffer. if anyone know what is my problem ,I would be very greatfull for him.
-
Hello, I have an owner-draw listBox that while updating its flicks, I tried the solution of treating the event OnEraseBkgnd its didn't work, so I tried the other posibility - double buffering void CIconListBox::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) { pDC = CDC::FromHandle(lpDrawItemStruct->hDC); HDC memDC1 = CreateCompatibleDC(lpDrawItemStruct->hDC); HBITMAP hMemBmp = CreateCompatibleBitmap(lpDrawItemStruct->hDC, scrW, scrH); HBITMAP hOldBmp = (HBITMAP)SelectObject(memDC1, hMemBmp); CDC *memDC=CDC::FromHandle(memDC1); . . if(m_pImgClose) m_pImgClose->Draw(memDC,0,pt1,ILD_NORMAL); . . memDC->DrawText(line.word[1].str, -1, &rText, DT_LEFT); . . SetTextColor(memDC1,oldcolor); . . BitBlt(lpDrawItemStruct->hDC, 0, 0, scrW, scrH, memDC1, 0, 0, SRCCOPY); SelectObject(memDC1, hOldBmp); DeleteObject(hMemBmp); DeleteDC(memDC1); } for some resone its doing the background black instead of white as it was before the double buffer. if anyone know what is my problem ,I would be very greatfull for him.
Before drawing on your memory device context, have you ever filled its background color? The
CreateCompatibleBitmap
produce a bitmap initially black, then you need to fill it with the color you want, e.g. using the CDC::FillSolidRect (MFC)[^] API. -
Before drawing on your memory device context, have you ever filled its background color? The
CreateCompatibleBitmap
produce a bitmap initially black, then you need to fill it with the color you want, e.g. using the CDC::FillSolidRect (MFC)[^] API.