locked
HELP ME! Double buffer RRS feed

  • Question

  • Hi, i need help with double buffering to load bitmap. How to use it in OnPaint() function? When i load it, my CPU gets like 15-20% CPU usage which is not normal because i use 3-4 bitmap images only. So i think my way of doing double buffer is wrong. I don't know if i have to use DeleteDC() and if i need to, where?

    Please give a simple MFC program that loads bitmap using double buffer, or just type me the buffer code.

    Thank you in advance.

     

    Tuesday, April 6, 2010 7:45 PM

Answers

  • If all you really want is some sample code, and you don't really care about how or why it is done that way, then I suggest doing a search, here or google.  I'm sure there will be more hits on this that you would know what to do with.

     Here is one such thread:

    http://social.msdn.microsoft.com/Forums/en-US/vcgeneral/thread/cda9d9c2-dd29-42e7-aa21-52425f611364

     

    Otherwise, what have you done so far?

     


    Ali
    • Marked as answer by Yi Feng Li Wednesday, April 14, 2010 10:05 AM
    Tuesday, April 6, 2010 8:09 PM
  • The answer to the memory DC deletion question is, no you don't have to delete the memory dc if you are using CDC. The CDC destructor will take care of it.  but if you call memDC.DeleteDC() nothing bad happens either.

    That is basically not an issue when it comes to double buffering, unless you are deleting and recreating a memory dc over and over in one paint routine.

     


    Ali
    • Marked as answer by Yi Feng Li Wednesday, April 14, 2010 10:04 AM
    Tuesday, April 6, 2010 8:28 PM
  • If you like to learn about double buffering, here is a good article:

    http://www.catch22.net/tuts/flicker


    Ali
    • Proposed as answer by Yi Feng Li Wednesday, April 14, 2010 10:04 AM
    • Marked as answer by Yi Feng Li Wednesday, April 14, 2010 10:04 AM
    Tuesday, April 6, 2010 9:24 PM

All replies

  • If all you really want is some sample code, and you don't really care about how or why it is done that way, then I suggest doing a search, here or google.  I'm sure there will be more hits on this that you would know what to do with.

     Here is one such thread:

    http://social.msdn.microsoft.com/Forums/en-US/vcgeneral/thread/cda9d9c2-dd29-42e7-aa21-52425f611364

     

    Otherwise, what have you done so far?

     


    Ali
    • Marked as answer by Yi Feng Li Wednesday, April 14, 2010 10:05 AM
    Tuesday, April 6, 2010 8:09 PM
  • I've been searching but i can't get the way how to do it. Except CDC memDC; memDC.CreateCompatibleDC(......); and so on, i don't know if I have to DELETE the DC using DeleteDC and if I HAVE TO, how to do it. If i was able to find it out, i wouldn't be posting here my problem.

     

    Tuesday, April 6, 2010 8:12 PM
  • The answer to the memory DC deletion question is, no you don't have to delete the memory dc if you are using CDC. The CDC destructor will take care of it.  but if you call memDC.DeleteDC() nothing bad happens either.

    That is basically not an issue when it comes to double buffering, unless you are deleting and recreating a memory dc over and over in one paint routine.

     


    Ali
    • Marked as answer by Yi Feng Li Wednesday, April 14, 2010 10:04 AM
    Tuesday, April 6, 2010 8:28 PM
  • If you like to learn about double buffering, here is a good article:

    http://www.catch22.net/tuts/flicker


    Ali
    • Proposed as answer by Yi Feng Li Wednesday, April 14, 2010 10:04 AM
    • Marked as answer by Yi Feng Li Wednesday, April 14, 2010 10:04 AM
    Tuesday, April 6, 2010 9:24 PM
  • Thank you, guys!
    Wednesday, April 7, 2010 12:10 PM