How can the console notification program be notified when the close button is pressed?

Does the Windows API provide a way to notify a running Delphi application in the console window when the user completes it by pressing the close button (instead of using Ctrl + C)?

Related questions: How to handle Ctrl + C in a Delphi console application?

+4
source share
1 answer

The OS notifies the console programs of various events through "control signals". Call SetConsoleCtrlHandler to configure the function to call the OS to deliver the signals. The signal for the closed window is CTRL_CLOSE_EVENT .

 function ConsoleEventProc(CtrlType: DWORD): BOOL; stdcall; begin if (CtrlType = CTRL_CLOSE_EVENT) then begin // optionally run own code here // ... end; Result := True; end; ... begin SetConsoleCtrlHandler(@ConsoleEventProc, True); // my application code here // ... end. 
+11
source

Source: https://habr.com/ru/post/1389891/


All Articles