一些关于Console的API函数

SetConsoleCtrlHandler
GenerateConsoleCtrlEvent
SetConsoleMode
ReadConsole
WriteConsole
SetConsoleCP
SetConsoleOutputCP
GetConsoleScreenBufferInfo
SetConsoleTextAttribute

MSDN上有详细说明,并有其它相关函数可供参考

Console主程序执行前加一句
SetConsoleCtrlHandler(@Handler, True);
就能判断出对Console程序外部传来的命令比如“Ctrl+C”,自己可根据信息采取相应的处置。

function Handler(dwCtrlType: DWORD): BOOL; stdcall;
begin
Result := True;
case dwCtrlType of
CTRL_C_EVENT: ShowMessage('Ctrl-C');
CTRL_BREAK_EVENT: ShowMessage('Break');
CTRL_CLOSE_EVENT: ShowMessage('Close');
CTRL_LOGOFF_EVENT: ShowMessage('Logoff');
CTRL_SHUTDOWN_EVENT: ShowMessage('Shutdown');
else MessageBeep(0);
end;
end;

http://bbs.2ccc.com/topic.asp?topicid=506402

上一篇:xamarin IOS 报错处理: an error occurred on client Build420719 while


下一篇:phpstorm 实用快捷键 和 注释