Problem with owner drawn listbox and double buffering
-
Hello, I created owner drawn listbox and I used double buffering for preventing flickering because I have a lot of data , the problem is that its don't present all the items and , whan I scroll it down and up its erases part of the items, the code is:
void HistDlg::OnDrawItem(int nIDCtl, LPDRAWITEMSTRUCT lpDrawItemStruct)
{
if(IDC_LIST1 ==nIDCtl)
{
int width=lpDrawItemStruct->rcItem.right-lpDrawItemStruct->rcItem.left;
int height=lpDrawItemStruct->rcItem.bottom-lpDrawItemStruct->rcItem.top;
HDC memDC1 = CreateCompatibleDC(lpDrawItemStruct->hDC);
HBITMAP hMemBmp = CreateCompatibleBitmap(lpDrawItemStruct->hDC,width , height);
HBITMAP hOldBmp = (HBITMAP)SelectObject(memDC1, hMemBmp);
CDC *memDC=CDC::FromHandle(memDC1);
memDC->FillSolidRect(0,0, width, height,RGB(255,255,255));int ODI\_length = 1 + SendDlgItemMessage(IDC\_LIST1, LB\_GETTEXTLEN, lpDrawItemStruct->itemID, 0); if (ODI\_length) { wchar\_t \*ODI\_wstr = NULL; ODI\_wstr = new wchar\_t\[ODI\_length\]; if (ODI\_wstr) { COLORREF ODI\_old\_text\_color; //get the string SendDlgItemMessage(IDC\_LIST1, LB\_GETTEXT, lpDrawItemStruct->itemID, (LPARAM)ODI\_wstr); memDC->DrawText(ODI\_wstr, ODI\_length - 1, &lpDrawItemStruct->rcItem, DT\_RIGHT); } } BitBlt(lpDrawItemStruct->hDC, 0, 0, width,height, memDC1, 0, 0, SRCCOPY); SelectObject(memDC1, hOldBmp); DeleteObject(hMemBmp); DeleteDC(memDC1); }
}
What doe's I'm doing wrong? thanks
-
Hello, I created owner drawn listbox and I used double buffering for preventing flickering because I have a lot of data , the problem is that its don't present all the items and , whan I scroll it down and up its erases part of the items, the code is:
void HistDlg::OnDrawItem(int nIDCtl, LPDRAWITEMSTRUCT lpDrawItemStruct)
{
if(IDC_LIST1 ==nIDCtl)
{
int width=lpDrawItemStruct->rcItem.right-lpDrawItemStruct->rcItem.left;
int height=lpDrawItemStruct->rcItem.bottom-lpDrawItemStruct->rcItem.top;
HDC memDC1 = CreateCompatibleDC(lpDrawItemStruct->hDC);
HBITMAP hMemBmp = CreateCompatibleBitmap(lpDrawItemStruct->hDC,width , height);
HBITMAP hOldBmp = (HBITMAP)SelectObject(memDC1, hMemBmp);
CDC *memDC=CDC::FromHandle(memDC1);
memDC->FillSolidRect(0,0, width, height,RGB(255,255,255));int ODI\_length = 1 + SendDlgItemMessage(IDC\_LIST1, LB\_GETTEXTLEN, lpDrawItemStruct->itemID, 0); if (ODI\_length) { wchar\_t \*ODI\_wstr = NULL; ODI\_wstr = new wchar\_t\[ODI\_length\]; if (ODI\_wstr) { COLORREF ODI\_old\_text\_color; //get the string SendDlgItemMessage(IDC\_LIST1, LB\_GETTEXT, lpDrawItemStruct->itemID, (LPARAM)ODI\_wstr); memDC->DrawText(ODI\_wstr, ODI\_length - 1, &lpDrawItemStruct->rcItem, DT\_RIGHT); } } BitBlt(lpDrawItemStruct->hDC, 0, 0, width,height, memDC1, 0, 0, SRCCOPY); SelectObject(memDC1, hOldBmp); DeleteObject(hMemBmp); DeleteDC(memDC1); }
}
What doe's I'm doing wrong? thanks
aangerma wrote:
BitBlt(lpDrawItemStruct->hDC, 0, 0, width,height, memDC1, 0, 0, SRCCOPY);
Shouldn't this be:
LONG left = lpDrawItemStruct->rcItem.left;
LONG top = lpDrawItemStruct->rcItem.top;
BitBlt(lpDrawItemStruct->hDC, left, top, width,height, memDC1, 0, 0, SRCCOPY);?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles]