469,623 Members | 1,534 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,623 developers. It's quick & easy.

Closing form event

In my application I need a way to distiguish between the following events:

1. When a user closes an MDI child window.
2. When the user closes the MDI parent window which subsequently closes
the MDI child window.

My application does certain logic when the user actually closes the MDI
child form by clicking the "X" in the upper right hand. My application,
however, should not execute this logic if the user closes the MDI parent. I
tried handling the Form.Closing event on the child window. The problem is,
that in both of the cases above, the sender is the MDI child
window--therefore the event handler doesn't know who actually closed the
form. More bad news for me: the MDI child Form.Closing event occurs before
the Parent Form.Closing event (so I can't set a flag or something on the
parent closing event to let the child closing events know that they should
not execute the application logic.)

What trick do I need to know about?

Thanks!
Nov 15 '05 #1
1 5394
Chris Bruce wrote:
In my application I need a way to distiguish between the following events:

1. When a user closes an MDI child window.
2. When the user closes the MDI parent window which subsequently closes
the MDI child window.

My application does certain logic when the user actually closes the MDI
child form by clicking the "X" in the upper right hand. My application,
however, should not execute this logic if the user closes the MDI parent. I
tried handling the Form.Closing event on the child window. The problem is,
that in both of the cases above, the sender is the MDI child
window--therefore the event handler doesn't know who actually closed the
form. More bad news for me: the MDI child Form.Closing event occurs before
the Parent Form.Closing event (so I can't set a flag or something on the
parent closing event to let the child closing events know that they should
not execute the application logic.)

What trick do I need to know about?


I see a way to set both handlers, Closing, and Close and utilize some
kind of global flag.

Child_Closing() {
_applicationQuit = false;
}
MainForm_Closing() {
_applicationQuit = true;
}
Child_Close() {
if (!_applicationQuit)
DoThis();
}

As soon as main form Closing event is called after any child Closing,
but before any child Close, you have a chance here to know either this
is application exit or child window close.

Probably it is also possible to achive by overriding main form's WndProc
and setting the flag if WM_QUIT has been passed.

Vadim Chekan.

Nov 15 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by HANG LAM | last post: by
14 posts views Thread by =?Utf-8?B?UHVjY2E=?= | last post: by
19 posts views Thread by zacks | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.