Thread: WM_Paint not updating using GDI

  1. #1
    Registered User
    Join Date
    Jan 2008
    Posts
    17

    WM_Paint not updating using GDI

    well I've made a simple program. It draws some shapes onto the screen. I have also made a timer which increases the x of the shapes every 5 seconds so it appears that its moving.

    The issue is its repainting the window as you can see the new shapes but you can also see the old shapes unless you resize the window (and thus updating it).

    I am using DC instead of begin paint so any ideas of what I may be doing wrong?

    http://img150.imageshack.us/img150/4544/example1id6.jpg


    http://img292.imageshack.us/img292/5414/example2ya3.jpg

    Ignore the cicrcle not moving I done that on purpose
    Last edited by zidsal; 07-24-2008 at 04:00 AM.

  2. #2
    Registered User
    Join Date
    Mar 2005
    Location
    Juneda
    Posts
    291
    Try invalidating the area under the previous position: sure you know that the walker is at position x,y and have some width,height, so fill up a RECT struct that defines the previous area and use it with the InvalidateRect function:

    Code:
    RECT prev={walker.x,walker.y,walker.x+walker.width,walker.y+walker.height};
    InvalidateRect(hwnd,&prev,TRUE);//'hwnd' is the window where you're drawing
    //redraw in new position
    Hope that helps
    Niara

  3. #3
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    Quote Originally Posted by zidsal View Post
    I am using DC instead of begin paint so any ideas of what I may be doing wrong?
    If you use InvaidateRect() you need to call BeginPaint() (which requires an EndPaint()) to validate the paint region.

    As stated it looks like you have not updated the previous position.

    For GDI apps I use two DCs; the Screen buffer and the Back buffer (Double Buffering).

    When the image changes I;
    assemble the new image on the Back buffer.
    Copy the whole Back buffer to the Screen buffer.
    Call for a paint of the whole screen with InvalidateRect() and UpdateWindow() (the area can be optimised if the app requires it).

    In the paint handler,
    BeginPaint() [The PAINTSTRUCT now contains the DC and area (rect)]
    BitBlt() the Screen buffer to the paint DC using the paint rect.
    EndPaint()
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  4. #4
    Registered User
    Join Date
    Mar 2005
    Location
    Juneda
    Posts
    291
    I was assuming that zidsal processes the WM_PAINT on the main proc and have a drawing function beside it.

    Niara

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Windows GDI vs. Java Graphics
    By Perspective in forum Windows Programming
    Replies: 7
    Last Post: 05-07-2007, 10:05 AM
  2. GDI object lifetime and C++ object lifetime
    By VirtualAce in forum Windows Programming
    Replies: 4
    Last Post: 06-16-2006, 05:26 AM
  3. opengl, or gdi?
    By n3v in forum Game Programming
    Replies: 25
    Last Post: 05-21-2006, 05:02 PM
  4. Whats Peoples Problem With the GDI?
    By MicroFiend in forum Game Programming
    Replies: 6
    Last Post: 07-28-2003, 07:52 PM
  5. Double buffering in GDI -- easy?
    By fusikon in forum Game Programming
    Replies: 17
    Last Post: 02-15-2003, 10:03 PM