Solved

MDI closing override (urgent)

Posted on 2004-09-06
4
220 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
  • 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

776 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