Hi!
I have MdiParent Form which hosts multiple MdiChids. I would like to determine why the MidParent is being closed withing the MdiChild-ClosingEvent. The CloseReason in the MdiChild-ClosingEvent only says "MdiFormClosing". But I dont know if the MdiParent is closed due to user operation (eg. pressing X in upper right corner) or Windows is being shutdown.
How can I solve that?
background:
The MdiChild_FormClosing-Event either asks if this or all childs shall be closed. If all are confirmed, the static variable of "bool _ForceClosing" prevents the next child from asking again. So good so far. I would like to skip this confirmation stuff in case, windows is being shutdown. But this CloseReason in MdiChild only has UserClosing or MdiFormClosing.
System::Void
Form_Client::Form_Client_FormClosing(System::Object^ sender, System::Windows::Forms::FormClosingEventArgs^ e)
{
//-----------------------------------------------------------------------------------------------------------------------------
try
{
//-- mdi closing already confirmed --------------------------------------------------------------------
if (this->_ForceClosing == true)
{
e->Cancel = false;
return;
}
//-- windows shutdown ---------------------------------------------------------------------------------
else if (e->CloseReason == System::Windows::Forms::CloseReason::WindowsShutDown) // not working
{
this->_ForceClosing = true;
}
//-- user single closing (ask if connected) -----------------------------------------------------------
else if (e->CloseReason == System::Windows::Forms::CloseReason::UserClosing)
{
// ask if this child shall be closed
if (Result != System::Windows::Forms::DialogResult::OK)
{
e->Cancel = true;
return;
}
}
//-- mdi parent closing initiated ---------------------------------------------------------------------
else if (e->CloseReason == System::Windows::Forms::CloseReason::MdiFormClosing)
{
// ask if all childs shall be closed
if (Result != System::Windows::Forms::DialogResult::Yes)
{
e->Cancel = true;
return;
}
//-------------------------------------------------------------------------------
this->_ForceClosing = true;
}
//-- unknown reason -> just close all -----------------------------------------------------------------
else
{
this->_ForceClosing = true;
}
}
//----------------------------------------------------------------------------------------------------------------------------
catch (System::Exception^ ex)
{
System::Windows::Forms::MessageBox::Show( ex->ToString() );
}
}