/// ------------------------------------------------------------------------------------
/// <summary>
/// Creates a new main window and initializes it. The specified App is responsible for
/// creating the proper main window type.
/// </summary>
/// <param name="app">The app</param>
/// <param name="fNewCache"><c>true</c> if we didn't reuse an existing cache</param>
/// <param name="wndCopyFrom">The window to copy from (optional).</param>
/// <param name="fOpeningNewProject"><c>true</c> if opening a new project</param>
/// <returns>True if the main window was create and initialized successfully</returns>
/// ------------------------------------------------------------------------------------
internal static bool CreateAndInitNewMainWindow(FwApp app, bool fNewCache, Form wndCopyFrom,
bool fOpeningNewProject)
{
Debug.Assert(app == s_flexApp || app == s_teApp);
WriteSplashScreen(app.GetResourceString("kstidInitWindow"));
Form fwMainWindow;
try
{
// Construct the new window, of the proper derived type
fwMainWindow = app.NewMainAppWnd(s_splashScreen, fNewCache, wndCopyFrom, fOpeningNewProject);
// Let the application do its initialization of the new window
using (new DataUpdateMonitor(fwMainWindow, "Creating new main window"))
app.InitAndShowMainWindow(fwMainWindow, wndCopyFrom);
// It seems to get activated before we connect the Activate event. But it IS active by now;
// so just record it now as the active one.
s_activeMainWnd = (IFwMainWnd)fwMainWindow;
}
catch (StartupException ex)
{
// REVIEW: Can this actually happen when just creating a new main window?
CloseSplashScreen();
MessageBox.Show(ex.Message, Properties.Resources.ksErrorCaption,
MessageBoxButtons.OK, MessageBoxIcon.Error);
return false;
}
CloseSplashScreen();
if (!((IFwMainWnd)fwMainWindow).OnFinishedInit())
return false; // did not initialize properly!
fwMainWindow.Activated += FwMainWindowActivated;
fwMainWindow.Closing += FwMainWindowClosing;
return true;
}