| 
			Author: Jonas Bilinkevicius 
How to close another application
Answer:
1   library KillGUI;
2   
3   uses
4     Windows, Messages;
5   
6   function PostQM(nCode: Integer; wParam: WParam; lparam: LParam): Lparam; stdcall;
7   begin
8     PostQuitMessage(1);
9     Result := 0;
10  end;
11  
12  function ExitRP(nCode: Integer; wParam: WParam; lparam: LParam): Lparam; stdcall;
13  begin
14    ExitProcess(1);
15    Result := 0;
16  end;
17  
18  procedure PostQuit(AHandle: THandle; Level: DWord); stdcall;
19  var
20    tid: DWord;
21    pid: DWord;
22    hProcess: THandle;
23  begin
24    tid := GetWindowThreadProcessId(AHandle, @pid);
25    case Level of
26      0:
27        PostMessage(AHandle, WM_CLOSE, 0, 0);
28      1:
29        SetWindowsHookEx(WH_GETMESSAGE, PostQM, Hinstance, tid);
30      2:
31        SetWindowsHookEx(WH_GETMESSAGE, ExitRP, Hinstance, tid);
32      3:
33        begin
34          hProcess := OpenProcess(PROCESS_TERMINATE, False, pid);
35          TerminateProcess(hProcess, 1);
36        end;
37    end;
38    PostThreadMessage(tid, 0, 0, 0);
39  end;
40  
41  exports
42    PostQuit name 'PostQuit';
43  
44  begin
45  end.
			 |