Thread: winsock chat

  1. #16
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    Code:
    bool keyHit(void)
    {
      /* Get a handle to console input buffer */
      HANDLE  stdIn = GetStdHandle(STD_INPUT_HANDLE);
    
      /* Save the console mode so we can restore it later */
      DWORD   saveMode;
      GetConsoleMode(stdIn, &saveMode);
    
      /* Set the console mode. The primary purpose of this is
       * to make sure ENABLE_LINE_INPUT is disabled. As its name 
       * suggests ENABLE_LINE_INPUT will not return until the end of
       * the line while we are interested in individual characters. */ 
      SetConsoleMode(stdIn, ENABLE_PROCESSED_INPUT);
    
      bool  ret = false;
    
      /* This waits 1 millisecond for the input buffer to be signalled
       * The input buffer enters the signalled state when one or more characters
       * are available. If the input buffer is signalled WaitForSingleObject()
       * will return WAIT_OBJECT_0 and we set ret to true to indicate that there
       * is character(s) in the input buffer. If the input buffer does not become
       * signalled in the timeout period it will return WAIT_TIMEOUT. */
      if (WaitForSingleObject(stdIn, 1) == WAIT_OBJECT_0) ret = true;
    
      /* We restore the console mode that we saved at the start of the function. */
      SetConsoleMode(stdIn, saveMode);
    
      /* We return the value of ret */
      return(ret);
    }
    getChar() is very similar, except that it uses ReadConsole() to actually read a character from the console input buffer.

  2. #17
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    > and i never put code in my programs that i dont understand..
    Highlight functions you don't know about and press F1
    We're not going to spoon-feed the whole program for you.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #18
    Registered User
    Join Date
    Apr 2004
    Posts
    102
    i cant press f1, i dont have msdn installed

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Winsock issues
    By tjpanda in forum Windows Programming
    Replies: 3
    Last Post: 12-04-2008, 08:32 AM
  2. Where do I initialize Winsock and catch messages for it?
    By Lithorien in forum Windows Programming
    Replies: 10
    Last Post: 12-30-2004, 12:11 PM
  3. Requesting Java Chat Client Maintenence
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 6
    Last Post: 04-02-2003, 01:57 PM
  4. SO close to finishing chat program...!
    By Nakeerb in forum C++ Programming
    Replies: 13
    Last Post: 10-26-2002, 12:24 PM
  5. Rough Portable Chat Design Sketch
    By ggs in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 08-27-2001, 07:44 AM