RT:
比如下面的程序,我如何在点叉结束时,调用postProc函数:
int postProc()
{
printf("结束\n");
return 0;
}
int main()
{
for(;;)
{
printf("进行中\n");
Sleep(1);
}
return 0;
}
#include <stdio.h>
#include <windows.h>
BOOL WINAPI HandlerRoutine(DWORD dwCtrlType)
{
if(dwCtrlType==CTRL_C_EVENT)
{
FILE *f = fopen("c:\\log.txt","a");
fprintf(f,"ctrl-c\n");
fclose(f);
}
if(dwCtrlType==CTRL_CLOSE_EVENT)
{
FILE *f = fopen("c:\\log.txt","a");
fprintf(f,"close\n");
fclose(f);
}
return false;
}
int main()
{
SetConsoleCtrlHandler(HandlerRoutine,true);
int n = 0;
while(true)
{
printf("n=%d\r",n++);
Sleep(1000);
}
}