Trap Ctrl+C signal
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: Trap Ctrl+C signal

  1. #1
    Join Date
    Nov 2000
    Posts
    66

    Trap Ctrl+C signal

    Hi

    How to trap Ctrl + C signal in Win32 console applications?

    Thanks for your answers

  2. #2
    Join Date
    Apr 2003
    Posts
    1,755

    Smile

    Use SetConsoleCtrlHandler to add Ctrl+C handler to your win32 console app.
    Code:
    BOOL WINAPI HandlerRoutine(DWORD dwCtrlType) {
       if (CTRL_C_EVENT == dwCtrlType) {
          printf("\nCtrl + C is pressed");
          return TRUE;
       }
       return FALSE;
    }
    
    void main()
    {
       char buff[1024];
       SetConsoleCtrlHandler(HandlerRoutine, TRUE);
       _cgets(buff);
       SetConsoleCtrlHandler(HandlerRoutine, FALSE);
    }
    Hope it will help you

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center