MyApplicationContext()
{
formCount = 0;
Application::ApplicationExit += gcnew EventHandler( this, &MyApplicationContext::OnApplicationExit );
try
{
userData = gcnew FileStream( String::Concat( Application::UserAppDataPath, "\\appdata.txt" ),FileMode::OpenOrCreate );
}
catch ( IOException^ e )
{
MessageBox::Show( "An error occurred while attempting to show the application. The error is: {0}", dynamic_cast<String^>(e) );
ExitThread();
}
form1 = gcnew AppForm1;
form1->Closed += gcnew EventHandler( this, &MyApplicationContext::OnFormClosed );
form1->Closing += gcnew CancelEventHandler( this, &MyApplicationContext::OnFormClosing );
formCount++;
form2 = gcnew AppForm2;
form2->Closed += gcnew EventHandler( this, &MyApplicationContext::OnFormClosed );
form2->Closing += gcnew CancelEventHandler( this, &MyApplicationContext::OnFormClosing );
formCount++;
if ( ReadFormDataFromFile() )
{
form1->StartPosition = FormStartPosition::Manual;
form2->StartPosition = FormStartPosition::Manual;
form1->Bounds = form1Position;
form2->Bounds = form2Position;
}
form1->Show();
form2->Show();
}
void OnApplicationExit( Object^ , EventArgs^ )
{
WriteFormDataToFile();
try
{
userData->Close();
}
catch ( Exception^ )
{
}
}
private: