How to close the application?
There are three general options:
- Kill him right.
- Assuming that it has a main window and that it behaves traditionally, send a
WM_CLOSE message to that window using P / Invoking SendMessage - Assuming he wants to collaborate, use your own communication channel to tell him to complete himself
How to close the application?
Killing a process is completely difficult and should never be undertaken unless you know that this process will not do anything sensitive when it stops. This is usually used as a last resort.
To close the main window, you first need to find out what exactly this HWND window is; You can do this by going through the list of top-level windows or by asking the process associated with it to somehow inform you about it. It also suggests that another process will decide to cease to exist when you ask to close its main window (in fact, it may decide to do something, including completely ignoring the message). This approach is a reasonable first attempt, and it usually works fine with processes that are not under your control - although you need to find the window yourself.
Using a custom communication channel allows you to fully control what is happening and how it can be implemented in many ways, but this is an approach that involves recording most of the code and requires that you have access to the source for both applications.
Conclusion
It depends on . If you are 1000% sure that killing the process will not harm anything, it will be a quick and dirty decision; otherwise, you need to use one of two βpoliteβ approaches.
Jon
source share