Mega Code Archive

 
Categories / Delphi / System
 

Baska uygulamanin kapatilmasi

{ !************************************** ! Name: Closing other applications from ! your application ! Description:RazorBlade (yes, this is a ! nickname) sent me an e-mail explaining h ! ow to close other applications from your ! Delphi application. I then digged in the ! Delphi help files to be able to give you ! some additional information. ! By: Emiel Hollander ! !This code is copyrighted and has ! limited warranties.Please see http://w ! ww.Planet-Source-Code.com/vb/scripts/Sho ! wCode.asp?txtCodeId=52&lngWId=7 !for details. !************************************** To close an application, you have to send the message WM_QUIT to that application. Messages were introduced because Windows is completely event-driven. Messages are being sent between Windows and applications and between applications themselves all the time. Windows generates a message every time, for example, the mouse passes over one of the application's windows. A message identifier is a named constant that identifies the purpose of a message. When a window procedure receives a message, it uses a message identifier to determine how to process the message. For example, the WM_QUIT message tells the application to terminate. Search in the Win32 Programmer's Reference for "WM_" without the quotes and you'll find all the messages possible. First you have to find the termination status of an application. Most of the times, when the application hasn't terminated, this will be STILL_ACTIVE. Use the function GetExitCodeProcess for this. I'll put the termination status in the integer intExitCode. I have the handle of the application I want to close ready in the variable AppHandle. } GetExitCodeProcess(AppHandle, intExitCode); { Now that you have the termination status, you can post a WM_QUIT message to the application. Posting a WM_QUIT message requires that you also send the termination status. } PostMessage(AppHandle, WM_QUIT, intExitCode, 0); { The last parameter has to be 0 (zero) because there is room for two parameters in the PostMessage function. When posting a WM_QUIT message only one of them is used, so the other one should be zero. <p>Now the application should terminate. }