请教各位达人,如何利用boost库,在windows下捕获程序的退出消息(ctrl+c)。
例如:JAVA可以用Runtime.getRuntime().addShutdownHook()注册钩子获得程序退出消息,然后作一些清理操作,用C++在windows下怎么实现?请大家不吝指教,谢谢。
windows c++ boost
------解决方案--------------------------------------------------------
console屏幕处理例子程序。终端窗口屏幕处理相关API使用例子。来自MSVC20\SAMPLES\win32\console\
http://download.csdn.net/detail/zhao4zhong1/3461309
------解决方案--------------------------------------------------------
ctrl+c是信号,不是消息,比如WM_QUIT是消息,用signal
/*
void (__cdecl *signal(
int sig,
void (__cdecl *func ) (int [, int ] )))
(int);
*/
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
void SignalHandler(int signal)
{
printf("Ctrl + C ...\n");
}
int main()
{
typedef void (*SignalHandlerPointer)(int);
SignalHandlerPointer previousHandler;
previousHandler = signal(SIGINT, SignalHandler);
while(true);
return 0;
}
------解决方案--------------------------------------------------------
msdn says:
SIGINT is not supported for any Win32 application. When a CTRL+C interrupt occurs,Win32 operating systems generate a new thread to specifically handle that interrupt. This can cause a single-thread application such as one in UNIX to become multithreaded, resulting in unexpected behavior.
------解决方案--------------------------------------------------------
ctrl+c好办,直接全局对象的析构函数中作清理动作即可。