#ifdef _MSC_VER
BOOL WINAPI console_handler(DWORD cevent)
{
    
switch(cevent)
    {
    
case CTRL_C_EVENT:
    
case CTRL_BREAK_EVENT:
    
case CTRL_CLOSE_EVENT:
    
case CTRL_LOGOFF_EVENT:
    
case CTRL_SHUTDOWN_EVENT:
        {
                        
//your code here
            exit(0);
            
break;
        }
    
default:
        {
        }
    }
    
return TRUE;
};
#else
void sig_proc(int sig)
{
    signal(SIGINT, SIG_DFL);
    cout 
<< "Shut down the console application ... \n";
        
//your code here
    exit(0);
};
#endif

int main(int argc, char* argv[])
{
#ifdef _MSC_VER
    
if (SetConsoleCtrlHandler( (PHANDLER_ROUTINE)console_handler,TRUE)==FALSE)
    {
        
return -1;
    }
#else
    signal(SIGINT, sig_proc);
#endif
        
//your code here
}

相关文章:

  • 2022-12-23
  • 2021-09-28
  • 2022-02-09
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-06
猜你喜欢
  • 2021-11-20
  • 2021-12-19
  • 2022-12-23
  • 2022-01-12
  • 2021-12-29
  • 2021-08-06
  • 2021-11-16
相关资源
相似解决方案