Thread: Console app termination

  1. #1
    Registered User
    Join Date
    Dec 2006

    Console app termination

    Hello, I'd like to know how I can cleanly terminate my C++ console application under windows.

    I have a while(true) loop in my code, that keeps polling and Sleep()'ing forever. When I click the close button of the console window, it takes a while before the app closes. How can I detect in the console program that the close button was clicked?

    If that's difficult, how can I detect a keypress (like esc) without using a blocking form of input. The polling must be able to continue.

  2. #2
    Registered User
    Join Date
    Jan 2005
    Perhaps make the sleep time shorter? You might be able to use kbhit() to wait for a keypress.

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    In particular, "Console WinEvents"
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Console App w/ Threads and Events?
    By sean in forum C# Programming
    Replies: 1
    Last Post: 07-02-2004, 12:16 AM
  2. Need help migrating console app to windows app
    By DelphiGuy in forum C++ Programming
    Replies: 1
    Last Post: 03-14-2004, 07:05 PM
  3. MSVC Console app - two enters?
    By LuckY in forum Windows Programming
    Replies: 4
    Last Post: 12-30-2003, 02:13 PM
  4. Project Builder console app
    By Luigi in forum C++ Programming
    Replies: 0
    Last Post: 12-28-2002, 07:57 PM
  5. Turning a Console APP into Windows.
    By Darkflame in forum C++ Programming
    Replies: 3
    Last Post: 09-14-2001, 03:10 AM