Solved

MDI closing override (urgent)

Posted on 2004-09-06
4
228 Views
Last Modified: 2008-03-06
Hi Experts!  I'm on a tight deadline, so thanks for your help in advance!

I have an MDI (frmParent) with about 20 child windows.

When I close frmParent, it closed the children first.  The children have Closing events I want to check to see if the parent is closing, and if so, NOT to execute the code in the event.

The problem is I can't create a flag for the children to check because when the parent closes it closed the children first, and then it executes the Closing code in the parent.

I have not really worked with user32.dll overrides, but if someone could show me what code to put in the frmParent that would be absolutley awesome!  The goal is to have a flag the children could check before executing the Closing event.

Thanks

0
Comment
Question by:OptionsMM
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 5

Expert Comment

by:jjacksn
ID: 11993869
I don't think this is true.  

If you capture the Form_Closing Event, it has to fire before the children, because you can cancel it.  Otherwise, there would be no way to warn the user to save data or something when the X is clicked without first closing all child windows.  Are you sure you are thinking about this correctly?

(you can just set a boolean in the Form_Closing Event)
0
 
LVL 12

Accepted Solution

by:
sumix earned 500 total points
ID: 11993898
Hi,

You can override WndProc method of the parent form to check if it'is closing. This function is called whenever the window receives a system message.

private const int WM_CLOSE = 0x10;
....

protected override void WndProc(ref Message m)
{
      if (m.Msg==WM_CLOSE)
      {
            MessageBox.Show("Closing...");
            // set same flag that the children can check
      }
      base.WndProc (ref m);
}


0
 

Author Comment

by:OptionsMM
ID: 11997189
jjacksn,

I am correct, the parent closing even is definitely after the child, not before

"Otherwise, there would be no way to warn the user to save data or something when the X is clicked without first closing all child windows."

that is why i need the override.

thanks sumix worked beautifully!
0
 
LVL 5

Expert Comment

by:jjacksn
ID: 11998758
OptionsMM, hmm, that's very very strange.  At any rate, glad you found a solution
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

710 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question