Thread: Inside which part of a WinProgramm ...

  1. #1
    Registered User
    Join Date
    Dec 2001

    Inside which part of a WinProgramm ...

    will I have to place a call to a function that calculates something (for example the next chess move)? Inside the GetMessage Loop? Or will I have to use PeekMessage? Or should I call that chess-function out of WndProc?

  2. #2
    Registered User
    Join Date
    Nov 2002
    >>Or should I call that chess-function out of WndProc?<<

    Yes you should put it there at WndProc That's the function you should use to handle any events (or commands) in your prog.

    LRESULT CALLBACK WndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
      switch(Message) {
        /*...other cases here...*/
        case WM_COMMAND:
          switch(wParam) {
            /*...other cases here too...*/
            case ID_CALCULATE_BUTTON: CalculateMove(/*...etc...*/); return 1;
            /* know what comes next...*/
       /* too...*/
    You're making a Chess game?

  3. #3
    train spotter
    Join Date
    Aug 2001
    near a computer
    A chess move will only occur AFTER the users move. Put it in response to the user moving (ie part of the processing of the users move is the computer move).

    PeekMessage() will return to the message loop (or pump) if there is no message.
    GetMessage() waits until there is a message before returning.

    If writing a game like a FPS you need to do things in between the users actions (ie update the monsters actions) so should use PeekMessage()

    A chess game can wait until the user responds so I would use GetMessage()
    "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. declaring variables inside loops
    By samus250 in forum C Programming
    Replies: 21
    Last Post: 04-30-2008, 01:51 PM
  2. variables when declared inside or outside a function
    By jas_atwal in forum C Programming
    Replies: 6
    Last Post: 12-14-2007, 02:42 PM
  3. Still battling with Copy Control
    By Mario F. in forum C++ Programming
    Replies: 9
    Last Post: 06-23-2006, 08:04 AM
  4. Linked List inside Linked List
    By de4th in forum C++ Programming
    Replies: 1
    Last Post: 05-15-2006, 11:17 AM
  5. Suspicious Pointer Conversion
    By mr_spanky202 in forum C Programming
    Replies: 35
    Last Post: 04-11-2003, 12:35 PM