Display Splash Screen for VSTO Applications

OUTSIDE OF GFW:http://aritrasaha.wordpress.com/2009/05/06/display-splash-screen-for-vsto-applications/

While developing an Office Add In using VSTO, we found out when some of the operations takes up very long time – it would be helpful to the end-user if we could display a Splash screen (with a progress bar / wait message), so that the user does not think the application has hung.

The following example from MSDN Forum shows how to implement a Splash Screen for VSTO Applications. The approach is quite simple – display a modal form on a background thread.

 

public delegate void InvokeClose();

 

private void ThisAddIn_Startup(object sender, System.EventArgs e)

{

      // MLSplashScreen is the custome splash screen, inherited from System.Windows.Forms.Form

      private MLSplashScreen splashScreen = new MLSplashScreen(); 

     

      IntPtr hwndWin = System.Diagnostics.Process.GetCurrentProcess().MainWindowHandle;

      NativeWindow parent = new NativeWindow();

      parent.AssignHandle(hwndWin);

 

      try

      {            

            System.Threading.Thread t = new System.Threading.Thread(SplashScreenProc);

            t.Start(parent);

 

            // Do the Long Operation, here

 

            InvokeClose invokeClose = new InvokeClose(splashScreen.Close);

            splashScreen.Invoke(invokeClose);

      }

      catch (Exception ex)

      {

      }

      finally

      {

            parent.ReleaseHandle();

      }

}

 

// Display the splash screen.

private void SplashScreenProc(object param)

        {

            IWin32Window parent = (IWin32Window)param;

            splashScreen.ShowDialog(parent);

        }

posted @ 2012-03-26 20:47  BinSys  阅读(554)  评论(0编辑  收藏  举报