1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Repainting erases the drawing

Discussion in 'Win32' started by jigar_bhatt16183, Feb 19, 2008.

  1. jigar_bhatt16183

    jigar_bhatt16183 New Member

    Joined:
    Feb 18, 2008
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    Hi friends.

    I m new in this forum as well as in win32

    I am creating a small application for my knowledge. But i m facing problem.

    When i move or minimize or maximize the window, the drawing above it erases. So plz help me to solve this matter
    Thanx in adv.

    Bye
     
  2. NewsBot

    NewsBot New Member

    Joined:
    Dec 2, 2008
    Messages:
    1,267
    Likes Received:
    1
    Trophy Points:
    0
    Handle the paint event to draw the things again.
     
  3. jigar_bhatt16183

    jigar_bhatt16183 New Member

    Joined:
    Feb 18, 2008
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    How it is possible? All drawing work done in paint or any saving and retrieving technique is available?

    Please tell me.
     
  4. johny10151981

    johny10151981 New Member

    Joined:
    Jul 7, 2010
    Messages:
    15
    Likes Received:
    0
    Trophy Points:
    0
    do your all Drawing under WM_PAINT message. your painting wont loose again. you can try another way. is CreateCompatibleDC() func by using this you can create a DC, which is virtual and resident in mem, than you can save it to hard disk as bitmap and restore it or directly can paint on your woindow what ever you like
     
  5. imported_xpi0t0s

    imported_xpi0t0s New Member

    Joined:
    Jul 18, 2008
    Messages:
    101
    Likes Received:
    0
    Trophy Points:
    0
    Alternatively (to solve the original problem directly), don't specify CS_HREDRAW or CS_VREDRAW in your window class style.

    However you would still lose everything (unless you specify CS_SAVEBITS, I think; I've never used this) if some other window appeared in front of yours.

    So Shabbir's answer is the best; draw everything in the WM_PAINT response function, and if you do any drawing outside that for some reason, make sure the WM_PAINT code will also draw that same stuff should it be called on.

    Drawing everything in WM_PAINT is really advantageous because you can make use of Windows' clipping functionality automatically; it's more or less transparent. If you want to make a small change in the display, update the data that the drawing depends on, then InvalidateRect just the rectangle that contains the change. Then call UpdateWindow, specifying bErase=FALSE, will then invoke WM_PAINT with the invalidated rectangle specified in the clipping region, and any drawing that occurs in WM_PAINT will be clipped to that rectangle, so the update will occur really quickly.

    Calling UpdateWindow with bErase=TRUE should be avoided wherever possible. Blanking everything before you start means you're guaranteed to get screen flicker. It may be valid in some cases, but instead of using bErase=TRUE use double buffering, where you draw everything to an initially blank memory bitmap, then blat that straight onto the screen.

    For an example of extremely crappy erase-before-redraw, have a look at FreeCommander (a Windows Commander clone, an otherwise quite good program); go to a directory with lots of files in, then use Shift-cursor keys to select a whole bunch of files; watch it flicker like a bad 1960's B-movie. Repeat the same selection in Windows Explorer and you'll see it's stacks nicer, because they don't erase the whole rectangle first.
     

Share This Page