# vb6 close application



## bill.beckett (Nov 27, 2003)

I have an application that seems to close, however the process is still running.

A way around I thought would be to launch the app from within another vb app using the shell or CreateProcess command.

I already know what the handle id is of the App, so I thought I could wait until the app window closes, then terminate the process.

However, I have got as far as launching the program using a shell command. I have never done any API programming before.

Does anyone know how to do this?


----------



## Mosaic1 (Aug 17, 2001)

What have you done to troubleshoot your application? Terminating a process is not a good idea unless you absolutely have no choice.


----------



## coderitr (Oct 12, 2003)

The program is not ending because something did not get closed in the program when the screen dismissed. I've seen this happen with ADO database connections, Crystal Reports, and additional forms. If your main form loads any other forms, make sure they are unloaded (not just hidden) before issuing the Unload Me statement in the main form. You can also use End to terminate the application but if you are doing any database work then you shouldn't because the database connection doesn't get closed properly and you could end up with corrupt data.

Post some more information about the application and I'll be happy to help answer this question.


----------



## bill.beckett (Nov 27, 2003)

The app that is not closing is a thrid party piece of software. I am not concerned as to why it sometimes does not close the process. What I need to know is, having launched the app from within my application, and knowing the handle of the app window, how do I find out when the window closes, thus enabling me to end the process.


----------



## coderitr (Oct 12, 2003)

Since it's not your code, I would be cautious about terminating the process since you don't really know what is going on the in application at that point. It may be writing to the registry or the disk and if you just kill it you could have major problems.

That said, assuming you have the window handle (different that a handle to the process) you can sub-class that window which will allow your application to see all the messages that go to that window before they get there. You can then choose which messages you allow that window to receive. Specifically, you can trap on the WM_CLOSE or WM_DESTROY messages and once those have been received and processed by the window in question you can be relatively sure that the window is gone. If the application is throwing up a message box like "are you sure?"
in that message's event procedure then the complete processing of the message will be delayed until the user clicks on a choice. In that case, it may not be safe to just kill the window.

If I were you, I would try to find out why the application appears to end (the window is dismissed) but the process is still running. Does it eventually end after a period of time or does it just hang. The safest method is to monitor the process id of the application and once it has ended, continue with your program.


----------

