Signal Close.

O.S.: Windows 7
Language: C

Hiho!. How I can know when my app recive a KILL or CLOSE signal in Windows?

How I can manage this?

I have data on a buffer that need be write on a file before my app ends.

Thanks.

WinAPI ? You get a WM_CLOSE message in your WindowProc function when the program closes.
And you are not notified when it's killed.
Last edited on
closed account (z05DSL3A)
if it is a console process you could look at:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#define WIN32_LEAN_AND_MEAN   
#include <windows.h>
#include <tchar.h>
#include <iostream>
#include <signal.h>


BOOL WINAPI ConsoleHandler(
    DWORD dwCtrlType   //  control signal type
);

int main(int argc, char *argv[])
{
    if (SetConsoleCtrlHandler( (PHANDLER_ROUTINE)ConsoleHandler,TRUE)==FALSE)
    {
        // unable to install handler... 
        // display message to the user
        printf("Unable to install handler!\n");
        return -1;
    }


    while(true)
    {

    }
}

BOOL WINAPI ConsoleHandler(DWORD CEvent)
{
    char mesg[128];

    switch(CEvent)
    {
    case CTRL_C_EVENT:
        MessageBox(NULL,
            _T("CTRL+C received!"),_T("CEvent"),MB_OK);
        break;
    case CTRL_BREAK_EVENT:
        MessageBox(NULL,
            _T("CTRL+BREAK received!"),_T("CEvent"),MB_OK);
        break;
    case CTRL_CLOSE_EVENT:
        MessageBox(NULL,
            _T("Program being closed!"),_T("CEvent"),MB_OK);
        break;
    case CTRL_LOGOFF_EVENT:
        MessageBox(NULL,
            _T("User is logging off!"),_T("CEvent"),MB_OK);
        break;
    case CTRL_SHUTDOWN_EVENT:
        MessageBox(NULL,
            _T("User is logging off!"),_T("CEvent"),MB_OK);
        break;

    }
    return TRUE;
}
Topic archived. No new replies allowed.