By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,257 Members | 925 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,257 IT Pros & Developers. It's quick & easy.

Closing form event

P: n/a
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
Share this Question
Share on Google+
1 Reply


P: n/a
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.