Click here to Skip to main content
15,902,817 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Handling a process termination. Pin
Michel Godfroid29-Apr-10 20:47
Michel Godfroid29-Apr-10 20:47 
GeneralRe: Handling a process termination. Pin
progDes29-Apr-10 21:32
progDes29-Apr-10 21:32 
GeneralRe: Handling a process termination. Pin
Michel Godfroid29-Apr-10 21:42
Michel Godfroid29-Apr-10 21:42 
AnswerRe: Handling a process termination. [modified] Pin
Software_Developer29-Apr-10 20:53
Software_Developer29-Apr-10 20:53 
GeneralRe: Handling a process termination. Pin
progDes29-Apr-10 21:35
progDes29-Apr-10 21:35 
GeneralRe: Handling a process termination. Pin
Software_Developer29-Apr-10 22:36
Software_Developer29-Apr-10 22:36 
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 
How to execute some code when process terminated normal or abnormal?

Answer:

WinAPI (Win32) specific only.
If you close the window from Taskmanager's "End Task", then you get the WM_CLOSE notification.
The WM_CLOSE message is sent as a signal that a window or an 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.

You better hope that the end user clicks on Taskmanager's "End Task" and not on "End Process" .
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
   switch(message)
   {
   
      case WM_CLOSE:
				
			// !!!!!!!!!!! Insert code here.
                        // this only works if you close the window from Taskmanager's "End Task"
                        
                        MessageBox(NULL, "closed the window from Taskmanager!", "abnormal exit" , MB_OK);
         
      break;
     
      default:
         return DefWindowProc(hWnd, message, wParam, lParam);
   }


modified on Friday, April 30, 2010 11:01 AM

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 
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 

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.