public InitAndShowMainWindow ( |
||
fwMainWindow | The new main window. | |
wndCopyFrom | Form to copy from, or |
|
Résultat | void |
public void InitAndShowMainWindow(Form fwMainWindow, Form wndCopyFrom)
{
CheckDisposed();
IFwMainWnd fwMainWnd = fwMainWindow as IFwMainWnd;
Debug.Assert(fwMainWnd != null);
fwMainWindow.Closing += OnClosingWindow;
fwMainWindow.Closed += OnWindowClosed;
m_rgMainWindows.Add(fwMainWnd);
fwMainWindow.Activated += fwMainWindow_Activated;
if (fwMainWindow == Form.ActiveForm)
m_activeMainWindow = fwMainWindow;
fwMainWindow.HandleDestroyed += fwMainWindow_HandleDestroyed;
// finalize and show the new window
if (fwMainWindow is IxWindow)
{
// Moved here due to FWNX-213
// OnHandleCreated must get called before the BroadcastPendingItems.
// Unfortunately, OnHandleCreated changes the window size, so we need to store
// the persisted size and restore it later.
var persistedSize = fwMainWindow.Size;
((IxWindow)fwMainWindow).SuspendWindowSizePersistence();
IntPtr dummy = fwMainWindow.Handle;
((IxWindow)fwMainWindow).ResumeWindowSizePersistence();
fwMainWindow.Size = persistedSize;
((IxWindow)fwMainWindow).Mediator.BroadcastPendingItems();
}
fwMainWindow.Show(); // Show method loads persisted settings for window & controls
fwMainWindow.Activate(); // This makes main window come to front after splash screen closes
if (fwMainWindow is FwMainWnd)
((FwMainWnd)fwMainWindow).HandleActivation();
// adjust position if this is an additional window
if (wndCopyFrom != null)
{
AdjustNewWindowPosition(fwMainWindow, wndCopyFrom);
// TODO BryanW: see AfMdiMainWnd::CmdWndNew() for other items that need to be
// coordinated
}
else if (fwMainWindow.WindowState != FormWindowState.Maximized)
{
// Fix the stored position in case it is off the screen. This can happen if the
// user has removed a second monitor, or changed the screen resolution downward,
// since the last time he ran the program. (See LT-1083.)
Rectangle rcNewWnd = fwMainWindow.DesktopBounds;
// Rectangle rcScrn = Screen.FromRectangle(rcNewWnd).WorkingArea;
ScreenUtils.EnsureVisibleRect(ref rcNewWnd);
fwMainWindow.DesktopBounds = rcNewWnd;
fwMainWindow.StartPosition = FormStartPosition.Manual;
}
((IFwMainWnd)fwMainWindow).InitAndShowClient();
m_fInitialized = true;
}
/// ------------------------------------------------------------------------------------ /// <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; }