Updating Window

This is a discussion on Updating Window within the Windows Programming forums, part of the Platform Specific Boards category; I've managed to cobble together my first Windows program. It implements the Game Of Life. It's all well and good ...

  1. #1
    Budding Synth Programmer samGwilliam's Avatar
    Join Date
    Feb 2002
    Location
    Trefforest
    Posts
    368

    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?
    MSVC++ 6.0

  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
    Budding Synth Programmer samGwilliam's Avatar
    Join Date
    Feb 2002
    Location
    Trefforest
    Posts
    368
    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.
    MSVC++ 6.0

  4. #4
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,859
    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, 09: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, 03:33 PM
  4. Pong is completed!!!
    By Shamino in forum Game Programming
    Replies: 11
    Last Post: 05-26-2005, 11:50 AM
  5. OpenGL Window
    By Morgul in forum Game Programming
    Replies: 1
    Last Post: 05-15-2005, 01:34 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21