Console app termination

This is a discussion on Console app termination within the C++ Programming forums, part of the General Programming Boards category; Hello, I'd like to know how I can cleanly terminate my C++ console application under windows. I have a while(true) ...

  1. #1
    Registered User
    Join Date
    Dec 2006
    Posts
    69

    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
    Posts
    7,317
    Perhaps make the sleep time shorter? You might be able to use kbhit() to wait for a keypress.

  3. #3
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,452
    http://msdn.microsoft.com/en-us/libr...87(VS.85).aspx
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

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, 06:05 PM
  3. MSVC Console app - two enters?
    By LuckY in forum Windows Programming
    Replies: 4
    Last Post: 12-30-2003, 01:13 PM
  4. Project Builder console app
    By Luigi in forum C++ Programming
    Replies: 0
    Last Post: 12-28-2002, 06: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

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