Display Splash Screen for VSTO Applications
May 6, 2009 Leave a comment
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);
}