Inside which part of a WinProgramm ...

This is a discussion on Inside which part of a WinProgramm ... within the Windows Programming forums, part of the Platform Specific Boards category; will I have to place a call to a function that calculates something (for example the next chess move)? Inside ...

  1. #1
    Registered User
    Join Date
    Dec 2001
    Posts
    60

    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
    Rez
    Rez is offline
    Registered User
    Join Date
    Nov 2002
    Posts
    82
    >>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.

    Code:
    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;
            /*...you know what comes next...*/
          }
       /*...here too...*/
       }
    }
    You're making a Chess game?

  3. #3
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,859
    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, 02: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, 09:04 AM
  4. Linked List inside Linked List
    By de4th in forum C++ Programming
    Replies: 1
    Last Post: 05-15-2006, 12:17 PM
  5. Suspicious Pointer Conversion
    By mr_spanky202 in forum C Programming
    Replies: 35
    Last Post: 04-11-2003, 01:35 PM

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