Thread: Updating Window

  1. #1
    Registered User samGwilliam's Avatar
    Join Date
    Feb 2002
    Location
    Newport
    Posts
    382

    Updating Window

    I've managed to cobble together my first Windows program. It implements the Game Of Life. It's all well and good - it starts off with an R-pentomino and animates correctly. Question is, it only animates when the mouse is moved over the window. How do I get it to always animate?
    Current Setup: Win 10 with Code::Blocks 17.12 (GNU GCC)

  2. #2
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    You can use the SetTimer function to create a timer. When the timer is triggered, you can call the InvalidateRect function. This will prompt Windows to post a WM_PAINT message to the window.

    Code:
    // At application startup, set up a function to fire once a second...
    SetTimer(hwnd, ID_MYANIMATION, 1000, NULL);
    
    // In your window procedure, handle WM_TIMER
    case WM_TIMER:
        InvalidateRect(hwnd, NULL, TRUE);
        return 0;

  3. #3
    Registered User samGwilliam's Avatar
    Join Date
    Feb 2002
    Location
    Newport
    Posts
    382
    Cheers! One more thing - all my variables pertinent to the window (including the two image buffers) are declared as static members in the window procedure. That doesn't seem right to me, but I can't see where else to do it.
    Current Setup: Win 10 with Code::Blocks 17.12 (GNU GCC)

  4. #4
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    I suggest you use UpdateWindow() as well.
    It posts the paint msg (generated by InvalidateRect() ) directly to the apps msg que (not the OS msg que).


    IMHO statics are acceptable as are globals (though globals can be confusing with many windows).
    In C I define a structure to hold all the details of my windows. Keep then in a global array or linked list (and pass to functions a reference/pointer to the element I want).
    "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

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. WM_CAPTION causing CreateWindowEx() to fail.
    By Necrofear in forum Windows Programming
    Replies: 8
    Last Post: 04-06-2007, 08:23 AM
  2. 6 measly errors
    By beene in forum Game Programming
    Replies: 11
    Last Post: 11-14-2006, 11:06 AM
  3. My Window Class
    By Epo in forum Game Programming
    Replies: 2
    Last Post: 07-10-2005, 02:33 PM
  4. Pong is completed!!!
    By Shamino in forum Game Programming
    Replies: 11
    Last Post: 05-26-2005, 10:50 AM
  5. OpenGL Window
    By Morgul in forum Game Programming
    Replies: 1
    Last Post: 05-15-2005, 12:34 PM