Is there such event as "Closing console" in C++?

c++, console, windows

Solution

My guess is that you want to get the Event when clicking the [X]

BOOL WINAPI HandlerRoutine( DWORD eventCode )
{
  switch( eventCode )
  {
      case CTRL_CLOSE_EVENT:
      // do your thing
      return FALSE;
      break;
   }

  return TRUE;
}

Is that what you're looking for?

You also need to enable the Handler:

int main()
{
    SetConsoleCtrlHandler( HandlerRoutine , TRUE );
    getch();
}

More Info

Problem

Is there any event like in C# "FormClosing" but in C++ as Console closing where I can execute some code before the Console close? (In my case, I'd like to create a directory with the input of the user before the console is closed completely).

Original source

Related problems