Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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).

like image 267
user2699298 Avatar asked Jan 08 '14 22:01

user2699298


1 Answers

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

like image 101
deW1 Avatar answered Nov 01 '22 10:11

deW1