CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Jul 2009
    Posts
    14

    Unhappy double buffering

    hi! i'm trying to make a double buffering to avoid the slow refresh
    my code looks like this:
    Code:
    void draw(HDC hdc)
    {
    	HDC dc = CreateCompatibleDC(hdc);
    	HBITMAP hBitmap = CreateCompatibleBitmap (hdc, 400, 240);
    	SelectObject(dc, hBitmap);
    
    	/*draw all the stuff on dc*/
    
    	BitBlt(hdc, 0, 0, 400, 240, dc, 0, 0, SRCCOPY);
    
    	ReleaseDC(0, dc);
    	DeleteObject(hBitmap);
    	DeleteDC(dc);
    
    	return;
    }
    where the hdc passed is the main hdc.
    it draws but the refresh is slow. i know that is a working method because if i comment out BitBlt(hdc, 0, 0, 400, 240, dc, 0, 0, SRCCOPY); i get a black screen...

  2. #2
    Join Date
    Feb 2005
    Posts
    2,160

    Re: double buffering

    Your missing the part where "/*draw all the stuff on dc*/" is. That's probably where you're bogging down.

  3. #3
    Join Date
    Jul 2009
    Posts
    14

    Re: double buffering

    wooo! solved!
    good double buffering script bad asking-to-refresh!
    i was
    Code:
    InvalidateRect(hWnd, NULL, TRUE);
    instead
    Code:
    InvalidateRect(hWnd, NULL, FALSE);
    UpdateWindow(hWnd);
    well... i think is a good code... feel free to use and give suggestion! (i didn't find something that do this elsewhere o.o)
    thanks for reply

    p.s. i'm working on windows mobile so this code runs over it too!

  4. #4
    Join Date
    Apr 2009
    Posts
    598

    Re: double buffering

    get a black screen[...]feel free to use and give suggestion!
    Just a little suggestion: If you have a message loop, and if you repaint the entire client area of your window, then you don't need Windows to paint a (black in your case) background. So you could write:
    Code:
          case WM_ERASEBKGND:
             return(1); // Prevent erasing the background to reduce flickering
             break;

  5. #5
    Join Date
    Jul 2009
    Posts
    14

    Re: double buffering

    I read on msdn to pass FALSE as last parameter when I do:
    Code:
    InvalidateRect(hWnd, NULL, FALSE);
    shouldn't this avoid the WM_ERASEBKGND message queuing?

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured