Example #1
0
        private void ActivateMainWindow()
        {
            var mainWindow = new MainWindow();

            // registers a callback to intercept WM_SHOWFIRSTINSTANCE messages so that when a second
            // instance broadcasts that message, original instance will be able to receive it and respond
            // by activating itself and making sure it isn't hidden.
            mainWindow.SourceInitialized += ( sender, e ) =>
            {
                HwndSource source = HwndSource.FromHwnd( new WindowInteropHelper( mainWindow ).Handle );
                source.AddHook( new HwndSourceHook( ShowFirstInstanceWinHook ) );
            };

            mainWindow.Show();
        }