To finish the program gracefully, you need to know something about how this program expects closure. If closing the main window performs it, then you need to know how to recognize the "main" window.
Programs do not start "in" the notification area. Icons are displayed there. Any notification program should also have a window (since the shell tells the program that the icon was clicked by sending messages to the window). Even if the window is not visible, it should still exist. If you can define a set of properties that identify the window associated with a particular notification icon, then you can close it. However, there is no standard set of attributes to search for; each program can do it differently.
And even if you find the window you are looking for, closing it may not be the same as the program is also waiting for completion. Instead, he can expect a specific command from the notification icon menu or some message sent by the dialog box displayed by the program.
Rob kennedy
source share