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); } }
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); } } }