Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How to close another application Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
04-Oct-02
Category
Win API
Language
Delphi 2.x
Views
127
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			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.


			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC