Determining if a window as been closed

May 21, 2009 at 4:25am
I'm having trouble determining if a window has been closed (by the user pressing the "x" button) based on the window's handle. I *can* just try showing the window and checking for a failure, but there's obviously a better way than that.

-Pseudo
May 21, 2009 at 6:27am
When a windows is being closed, windows will send your program a message WM_CLOSE
May 21, 2009 at 10:27pm
you may be able to use windows' synchronization functions. off the top of my head, I don't remember if they work with a window handle but if you are looking to see if a process has terminated they should work, and may work for a window handle as well.

http://msdn.microsoft.com/en-us/library/ms686353(VS.85).aspx

one of the 'waitfor...' functions may do the trick
Last edited on May 21, 2009 at 10:28pm
May 22, 2009 at 10:57am
A Window is not a synchronization object, you cannot "wait" for it.

guestgulkan is correct. You are notified with WM_CLOSE and have the opportunity to allow or disallow the close. That's where some applications display a message box asking for confirmation.
May 22, 2009 at 12:45pm
Use System Notifications to get notified for windows belonging to any process.
May 22, 2009 at 12:54pm
george135, you mean use a COM+ service to determine if a window is closing? I don't think so.
Topic archived. No new replies allowed.