Exemplo n.º 1
0
        private void App_OnStartup(object sender, StartupEventArgs e)
        {
            var mode = e.Args.Any() ? e.Args[0] : "/s";

            // Preview mode--display in little window in Screen Saver dialog
            // (Not invoked with Preview button, which runs Screen Saver in
            // normal /s mode).
            if (mode.ToLower().StartsWith("/p"))
            {
                m_winSaver = new MainWindow();

                Int32 previewHandle = Convert.ToInt32(e.Args[1]);
                //WindowInteropHelper interopWin1 = new WindowInteropHelper(win);
                //interopWin1.Owner = new IntPtr(previewHandle);

                var pPreviewHnd = new IntPtr(previewHandle);

                var lpRect = new RECT();
                Win32API.GetClientRect(pPreviewHnd, ref lpRect);

                var sourceParams = new HwndSourceParameters("sourceParams")
                {
                    PositionX = 0,
                    PositionY = 0,
                    Height = lpRect.Bottom - lpRect.Top,
                    Width = lpRect.Right - lpRect.Left,
                    ParentWindow = pPreviewHnd,
                    WindowStyle = (int)(WindowStyles.WS_VISIBLE | WindowStyles.WS_CHILD | WindowStyles.WS_CLIPCHILDREN)
                };

                m_winWpfContent = new HwndSource(sourceParams);
                m_winWpfContent.Disposed += winWPFContent_Disposed;
                m_winWpfContent.RootVisual = m_winSaver.Grid;
                // ReSharper disable once CSharpWarnings::CS4014
                m_winSaver.StartAnimation();
            }

            // Normal screensaver mode.  Either screen saver kicked in normally,
            // or was launched from Preview button
            else if (mode.ToLower().StartsWith("/s"))
            {
                var win = new MainWindow { WindowState = WindowState.Maximized };
                win.Show();
            }

            // Config mode, launched from Settings button in screen saver dialog
            else if (mode.ToLower().StartsWith("/c"))
            {
                var win = new SettingsWindow();
                win.Show();
            }

            // If not running in one of the sanctioned modes, shut down the app
            // immediately (because we don't have a GUI).
            else
            {
                Current.Shutdown();
            }
        }
Exemplo n.º 2
0
 public static extern bool GetClientRect(IntPtr hWnd, ref RECT lpRect);