Thread: Moving windows

  1. #1
    Politics&Cpp geek Da-Nuka's Avatar
    Join Date
    Oct 2004
    Posts
    104

    Moving windows

    Hi.
    I have added OpenGL to a window.
    Now, if i move the window, the OpenGL animation and such, stops for a while, untill i release my window again.

    This is not good in a game, where time should not be stopped. How to fix?

  2. #2
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    Handle the WM_MOVING message and call your drawing function from there.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  3. #3
    Politics&Cpp geek Da-Nuka's Avatar
    Join Date
    Oct 2004
    Posts
    104
    It worked..allmost..
    But if I click it, and not move it, the propblem still occurs.
    The same if i rightclick on the program-icon down in the taskbar.

  4. #4
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    Its to do with the PeekMessage() loop.

    When there is a constant stream of messages the DrawGL function will not get called (unless DrawGL is called in one of the messages ie your WM_PAINT handler).

    Write a handler for those that you think need it.
    "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

  5. #5
    Politics&Cpp geek Da-Nuka's Avatar
    Join Date
    Oct 2004
    Posts
    104
    Wow, is that the only way?
    It sounds resource-demanding... What if I include, for example program or game-logic as well.. It will be very big for so little...

  6. #6
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    Another way is to limit frame rate. This will cause other issues though.

    Check if another frame is needed after each message has been processed and while idle (no messages). If sufficent time has passed call DrawGL.

    Depending on speed you may need to use QueryPerformanceCounter() (and Frequency) as WM_TIMER msg's are very low accuracy (low priority in the msg que) or use GetTickCount()
    "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

  7. #7
    Politics&Cpp geek Da-Nuka's Avatar
    Join Date
    Oct 2004
    Posts
    104
    Hmm..I think it is something else which is the problem... Maybe some windows related stuff...
    Cuz I can solve that problem, by adding a loop OVER my MessageLoop, and end that loop if the messageloop contains WM_QUIT. Then I add the Game-Logic over there, so the game logic should be ran for every single message, without any more coding.

    I did, and it worked, but still, when I GRAB the window, og clicks in its menu, the game stops. Why? and how to solve?

  8. #8
    Handy Andy andyhunter's Avatar
    Join Date
    Dec 2004
    Posts
    540
    Well, it is kind of hard to answer specific program problems without seeing any code.

    It sounds like the game is stopping for the same reason everyone has been stating on this post previously. AKA your render functions are not getting called when windows is handling a message. Understand that if your windows callback procedure is passing all unhandled messages to DefWindowProc then WINDOWS is actually doing something and while that is going on your game "stops".

    You could try to put a call to your render function right before your
    Code:
    return DefWindowProc(..)
    statement at the end of your windows callback function.

    However like I said it is hard to help without code

  9. #9
    Politics&Cpp geek Da-Nuka's Avatar
    Join Date
    Oct 2004
    Posts
    104
    while(!done) {
    DrawGL();
    if(PeekMessage(&msg,NULL,0,0,PM_REMOVE)) {
    if(msg.message==WM_QUIT) {
    done=true;
    } else {
    TranslateMessage(&msg);
    DispatchMessage(&msg);
    }
    }
    }
    return msg.wParam;
    }


    -wont that work as well?
    (well, I tried, and it dont)

  10. #10
    Handy Andy andyhunter's Avatar
    Join Date
    Dec 2004
    Posts
    540
    OK this loop only calls DrawGL() at the beginning prior to checking to see if there is a message. What about if there is a message? You need to call DrawGL() from within your window callback procedure to handle these things. Such as using the WM_MOVING message as suggested earlier. I would also use the WM_PAINT message as well.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Moving Lapack++ dependent code to windows
    By confuted in forum C++ Programming
    Replies: 1
    Last Post: 10-16-2007, 10:47 AM
  2. how to make a windows application
    By crvenkapa in forum C++ Programming
    Replies: 3
    Last Post: 03-26-2007, 09:59 AM
  3. Windows moving together.
    By bigdan43 in forum C++ Programming
    Replies: 4
    Last Post: 03-28-2005, 06:20 PM
  4. SDL and Windows
    By nickname_changed in forum Windows Programming
    Replies: 14
    Last Post: 10-24-2003, 12:19 AM
  5. IE 6 status bar
    By DavidP in forum Tech Board
    Replies: 15
    Last Post: 10-23-2002, 05:31 PM