Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Problem with owner drawn listbox and double buffering

Problem with owner drawn listbox and double buffering

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    aangerma
    wrote on last edited by
    #1

    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

    C 1 Reply Last reply
    0
    • A aangerma

      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

      C Offline
      C Offline
      CPallini
      wrote on last edited by
      #2

      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]

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups