views:

519

answers:

2

Is there a way to attach an event to a foreign / separate window from an .NET process that when the foreign window is closed or is about to close my application can be notified?

I found this http://msdn.microsoft.com/en-us/library/ms229658.aspx

But that seems to only be for the .NET compact framework. I am looking for something using the .NET 2.0 framework.

Thanks.

A: 

Look into SetWindowsHookEx with the WH_CBT parameter. There will be a HCBT_DESTROYWND entry.

Joel Lucsy
+4  A: 

There's an article on CodeProject that looks at using global hooks to receive windows messages from other applications.

Can you wait for the process to exit?

Or are you stuck needing to poll and check that you can still Find the window?

Hamish Smith