Procházet zdrojové kódy

set windows `SIGINT` handler

blueloveTH před 1 rokem
rodič
revize
2ef24dd1d9
1 změnil soubory, kde provedl 10 přidání a 0 odebrání
  1. 10 0
      src2/main.c

+ 10 - 0
src2/main.c

@@ -8,6 +8,15 @@
 #ifdef _WIN32
 #ifdef _WIN32
 #define WIN32_LEAN_AND_MEAN
 #define WIN32_LEAN_AND_MEAN
 #include <windows.h>
 #include <windows.h>
+
+static BOOL WINAPI sigint_handler(DWORD dwCtrlType) {
+    if(dwCtrlType == CTRL_C_EVENT) {
+        py_interrupt();
+        return TRUE;
+    }
+    return FALSE;
+}
+
 #else
 #else
 
 
 // set ctrl+c handler
 // set ctrl+c handler
@@ -39,6 +48,7 @@ int main(int argc, char** argv) {
 #if _WIN32
 #if _WIN32
     SetConsoleCP(CP_UTF8);
     SetConsoleCP(CP_UTF8);
     SetConsoleOutputCP(CP_UTF8);
     SetConsoleOutputCP(CP_UTF8);
+    SetConsoleCtrlHandler((PHANDLER_ROUTINE)sigint_handler, TRUE);
 #else
 #else
     signal(SIGINT, sigint_handler);
     signal(SIGINT, sigint_handler);
 #endif
 #endif