コード例 #1
0
        private void FormMain_Shown(object sender, EventArgs e)
        {
            try
            {
                if (shown_done == false)
                {
                    //In Form_Load it seems to work not always (without DWM)
                    if (Program.IsProtected)
                    {
                        WndProtect.Protect(this.Handle);
                        timerProtection.Enabled = true;
                    }

                    if (toggleAfterShow)
                    {
                        ToggleFullscreen();
                    }

                    //ugly trick to make sure our window is in foreground!
                    this.TopMost = true;
                    this.BringToFront();
                    this.TopMost = false;
                    shown_done   = true;
                }
            }
            catch (System.Exception ex)
            {
                LogFile.Warn("Exception in FormMain_Shown(): " + ex.ToString());
            }
        }
コード例 #2
0
        public XpsViewer()
        {
            InitializeComponent();

            /* Reduce quality, has no huge impact on performance
             * System.Windows.Media.RenderOptions.SetBitmapScalingMode(this.documentViewer, System.Windows.Media.BitmapScalingMode.NearestNeighbor);
             * System.Windows.Media.RenderOptions.SetEdgeMode(this.documentViewer, System.Windows.Media.EdgeMode.Aliased);
             * System.Windows.Media.RenderOptions.SetCachingHint(this.documentViewer, System.Windows.Media.CachingHint.Unspecified);
             * this.documentViewer.SnapsToDevicePixels = true;
             */
            try
            {
                if (Program.IsProtected && (WndProtect.IsDWMEnabled() == false)) //Only needed if DWM is not enabled
                {
                    //Fix for redraw bug if window is protected (http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/6f88715b-b9ca-4d4f-974b-97b334d26347/)
                    this.Loaded += delegate
                    {
                        var source     = PresentationSource.FromVisual(this);
                        var hwndTarget = source.CompositionTarget as System.Windows.Interop.HwndTarget;
                        if (hwndTarget != null)
                        {
                            hwndTarget.RenderMode = RenderMode.SoftwareOnly;
                        }
                    };
                }
            }
            catch (System.Exception ex)
            {
                LogFile.Error("exception wile setting software rendering ", ex);
            }
        }
コード例 #3
0
 private void timerProtection_Tick(object sender, EventArgs e)
 {
     if (Program.IsProtected)
     {
         //There are redraw bugs, after switching to Skin without DWM, but who cares...
         WndProtect.ChangeProtection(this.Handle);
     }
 }
コード例 #4
0
 private void FormMain_FormClosing(object sender, FormClosingEventArgs e)
 {
     if (Program.IsProtected)
     {
         WndProtect.UnProtect(this.Handle);
         WndProtect.Free();
     }
 }
コード例 #5
0
        private void FormMain_Load(object sender, EventArgs e)
        {
            try
            {
                if (System.IO.File.Exists(Application.ExecutablePath + ".ico"))
                {
                    this.Icon = new System.Drawing.Icon(Application.ExecutablePath + ".ico");
                }
            }
            catch (System.Exception ex)
            {
                LogFile.Warn("Exception while setting icon: " + ex.ToString());
            }

            if (Program.IsProtected)
            {
                WndProtect.Init();
            }
        }
コード例 #6
0
        static void Main()
        {
            bool showDWMError = false;
            bool stopLoading  = false;

            Application.SetCompatibleTextRenderingDefault(false);
            Application.EnableVisualStyles();
            InitParameters();

            try
            {
                if (fileToLoad == "")
                {
                    Microsoft.Win32.OpenFileDialog dialog = new Microsoft.Win32.OpenFileDialog();
                    dialog.CheckFileExists  = true;
                    dialog.Filter           = Lang.translate("XPS documents|*.xps|All Files|*.*", "XPS Dokumente|*.xps|Alle Dateien|*.*", "XPS papiers|*.xps|Tous les fichiers|*.*");
                    dialog.RestoreDirectory = true;
                    dialog.AddExtension     = true;
                    dialog.FilterIndex      = 0;
                    dialog.Multiselect      = false;
                    dialog.Title            = Lang.translate("Choose an XPS file...", "Wählen Sie eine XPS-Datei aus...", "Choisissez un fichier XPS...");
                    dialog.ShowDialog();
                    if (File.Exists(dialog.FileName))
                    {
                        fileToLoad = dialog.FileName;
                    }
                    else
                    {
                        stopLoading = true;
                    }
                }
            }
            catch (System.Exception ex)
            {
                LogFile.Error("Error while opening open file dialog:\n", ex);
            }



            if (Environment.OSVersion.Version.Major == 6 && Environment.OSVersion.Version.Minor == 2) //Windows 8
            {
                LogFile.Debug("Win 8 detected");
                if (Program.IsProtected)
                {
                    if (WndProtect.IsDWMEnabled() == false)
                    {
                        LogFile.Debug("Win 8 + no DWM + Protected....");
                        //Stop running the program under windows 8 without DWM -> no protection
                        stopLoading  = true;
                        showDWMError = true;
                    }
                }
            }


            if (stopLoading == false)
            {
                if (noProgress == false)
                {
                    try
                    {
                        thrdWait = new Thread(new ThreadStart(WaitWindow));
                        thrdWait.SetApartmentState(ApartmentState.STA);
                        thrdWait.Start();
                    }
                    catch (System.Exception ex)
                    {
                        LogFile.Error("Error while starting wait thread:\n", ex);
                    }
                }

                mainFrm = new FormMain();

                mainFrm.SetPlacement(windowTop, windowLeft, windowWidth, windowHeight, windowActivate);

                bool run = mainFrm.LoadFileSync();
                thrdWaitRunning = false;
                try
                {
                    if (title != "")
                    {
                        mainFrm.Text = title;
                    }
                    else
                    {
                        if (fileToLoad != "")
                        {
                            mainFrm.Text = System.IO.Path.GetFileName(fileToLoad);
                        }
                    }
                    if (toggle)
                    {
                        mainFrm.SetFullscreenFlag();
                    }
                }
                catch (System.Exception ex)
                {
                    LogFile.Error("Error while modifiying main form:\n", ex);
                }

                if (run)
                {
                    Application.Run(mainFrm);
                }
                else
                {
                    MessageBox.Show(Lang.translate("The document cannot be opened!", "Das Dokument konnte nicht geöffnet werden!", "Le document ne peut pas être ouvert!"), "XPS Viewer", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly);
                }
            }
            else
            {
                if (showDWMError)
                {
                    LogFile.Error("Cannot continue, Win8 need DWM!");
                    MessageBox.Show(Lang.translate("This document cannot be shown when the Desktop Window Manager (DWM) is not active. To continue please activate it.", "Dieses Dokument kann nicht angezeigt werden, wenn der Desktop Window Manager (DWM) nicht aktiv ist. Um fortzufahren aktivieren Sie diesen bitte.", "Ce programme ne pas fonctionner lorsque le Desktop Window Manager (DWM) n'est pas actif. Pour continuer s'il vous plaît activer le Desktop Window Manager."), "XPS Viewer", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly);
                }
            }
        }