Click here to Skip to main content
15,888,351 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Handling a process termination. Pin
progDes29-Apr-10 23:04
progDes29-Apr-10 23:04 
GeneralRe: Handling a process termination. [modified] Pin
Software_Developer30-Apr-10 0:26
Software_Developer30-Apr-10 0:26 
GeneralRe: Handling a process termination. Pin
progDes30-Apr-10 0:49
progDes30-Apr-10 0:49 
GeneralRe: Handling a process termination. Pin
enhzflep30-Apr-10 1:12
enhzflep30-Apr-10 1:12 
GeneralRe: Handling a process termination. Pin
progDes30-Apr-10 1:42
progDes30-Apr-10 1:42 
GeneralRe: Handling a process termination. Pin
progDes30-Apr-10 1:53
progDes30-Apr-10 1:53 
GeneralRe: Handling a process termination. Pin
enhzflep30-Apr-10 2:23
enhzflep30-Apr-10 2:23 
GeneralRe: Handling a process termination. [modified] Pin
Software_Developer30-Apr-10 2:21
Software_Developer30-Apr-10 2:21 
For console:

CTRL_CLOSE_EVENT or the Console process termination message.

If you close the console from Taskmanager's "End Task", then you get the CTRL_CLOSE_EVENT notification.
The CTRL_CLOSE_EVENT message is sent as a signal that a console application should terminate.
BUT
If you click on "End Process" from task manager, then there's no way to handle it, in .NET or Win32.

The code below displays the message "Signal to quit was received" once you click on "End Task" from task manager.
<code></code>
#define STRICT 1
#include <windows.h>
#include <ctime>
#include <iostream>
using namespace std;

bool GlobalQuit = false;

BOOL WINAPI CtrlHandler(DWORD fdwCtrlType) {
switch (fdwCtrlType) {
    case CTRL_C_EVENT:
        Beep(1000, 1000);
    case CTRL_CLOSE_EVENT:
    case CTRL_BREAK_EVENT:
    case CTRL_LOGOFF_EVENT:
    case CTRL_SHUTDOWN_EVENT:
                    // put your code here

		system("Color 1A");
        cout << "Signal to quit was received\n";
        GlobalQuit = true;
        return TRUE;
    default:
        return FALSE;
    }
}

int main(int argc, char *argv[], char *envp[]) {
    struct tm *today;
    time_t ltime;
    char *p;
SetConsoleCtrlHandler(CtrlHandler, TRUE);
while (!GlobalQuit) {
    time(&ltime);
    today = localtime(&ltime);
    p = asctime(today);
    Sleep(2000);
    }
return 0;
}


modified on Friday, April 30, 2010 12:01 PM

GeneralRe: Handling a process termination. Pin
Michel Godfroid29-Apr-10 23:09
Michel Godfroid29-Apr-10 23:09 
GeneralRe: Handling a process termination. Pin
Michel Godfroid29-Apr-10 21:40
Michel Godfroid29-Apr-10 21:40 
AnswerRe: Handling a process termination. Pin
David Crow30-Apr-10 3:21
David Crow30-Apr-10 3:21 
AnswerRe: Handling a process termination. Pin
Michel Godfroid30-Apr-10 4:49
Michel Godfroid30-Apr-10 4:49 
AnswerRe: Handling a process termination. Pin
Randor 30-Apr-10 4:57
professional Randor 30-Apr-10 4:57 
AnswerRe: Handling a process termination. Pin
kawayi30-Apr-10 6:31
kawayi30-Apr-10 6:31 
AnswerRe: Handling a process termination. Pin
«_Superman_»30-Apr-10 6:54
professional«_Superman_»30-Apr-10 6:54 
QuestionSub menu Item Check and uncheck in Win 32 Pin
arun_pk29-Apr-10 19:56
arun_pk29-Apr-10 19:56 
AnswerRe: Sub menu Item Check and uncheck in Win 32 Pin
PrafullaShirke2729-Apr-10 21:24
professionalPrafullaShirke2729-Apr-10 21:24 
GeneralRe: Sub menu Item Check and uncheck in Win 32 Pin
arun_pk30-Apr-10 0:51
arun_pk30-Apr-10 0:51 
JokeRe: Sub menu Item Check and uncheck in Win 32 Pin
Code-o-mat30-Apr-10 1:08
Code-o-mat30-Apr-10 1:08 
GeneralRe: Sub menu Item Check and uncheck in Win 32 Pin
enhzflep30-Apr-10 1:14
enhzflep30-Apr-10 1:14 
Questionfstream read and write [modified] Pin
varsha_vm29-Apr-10 18:45
varsha_vm29-Apr-10 18:45 
AnswerRe: fstream read and write Pin
Saurabh.Garg29-Apr-10 19:00
Saurabh.Garg29-Apr-10 19:00 
GeneralRe: fstream read and write Pin
varsha_vm29-Apr-10 20:17
varsha_vm29-Apr-10 20:17 
QuestionRe: fstream read and write Pin
David Crow30-Apr-10 3:25
David Crow30-Apr-10 3:25 
AnswerRe: fstream read and write Pin
varsha_vm2-May-10 18:54
varsha_vm2-May-10 18:54 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.