diff --git a/Greenshot/Helpers/CaptureHelper.cs b/Greenshot/Helpers/CaptureHelper.cs index 860f6a1e7..3d6dd4883 100644 --- a/Greenshot/Helpers/CaptureHelper.cs +++ b/Greenshot/Helpers/CaptureHelper.cs @@ -694,7 +694,7 @@ namespace Greenshot.Helpers { windowCaptureMode = WindowCaptureMode.Screen; // Change to GDI, if allowed - if (conf.isGDIAllowed(process)) { + if (WindowCapture.isGDIAllowed(process)) { if (!dwmEnabled && isWPF(process)) { // do not use GDI, as DWM is not enabled and the application uses PresentationFramework.dll -> isWPF LOG.InfoFormat("Not using GDI for windows of process {0}, as the process uses WPF", process.ProcessName); @@ -705,20 +705,20 @@ namespace Greenshot.Helpers { // Change to DWM, if enabled and allowed if (dwmEnabled) { - if (conf.isDWMAllowed(process)) { + if (WindowCapture.isDWMAllowed(process)) { windowCaptureMode = WindowCaptureMode.Aero; } } } else if (windowCaptureMode == WindowCaptureMode.Aero || windowCaptureMode == WindowCaptureMode.AeroTransparent) { - if (!dwmEnabled || !conf.isDWMAllowed(process)) { + if (!dwmEnabled || !WindowCapture.isDWMAllowed(process)) { // Take default screen windowCaptureMode = WindowCaptureMode.Screen; // Change to GDI, if allowed - if (conf.isGDIAllowed(process)) { + if (WindowCapture.isGDIAllowed(process)) { windowCaptureMode = WindowCaptureMode.GDI; } } - } else if (windowCaptureMode == WindowCaptureMode.GDI && !conf.isGDIAllowed(process)) { + } else if (windowCaptureMode == WindowCaptureMode.GDI && !WindowCapture.isGDIAllowed(process)) { // GDI not allowed, take screen windowCaptureMode = WindowCaptureMode.Screen; } @@ -729,7 +729,7 @@ namespace Greenshot.Helpers { while (!captureTaken) { if (windowCaptureMode == WindowCaptureMode.GDI) { ICapture tmpCapture = null; - if (conf.isGDIAllowed(process)) { + if (WindowCapture.isGDIAllowed(process)) { tmpCapture = windowToCapture.CaptureWindow(captureForWindow); } if (tmpCapture != null) { @@ -741,7 +741,7 @@ namespace Greenshot.Helpers { } } else if (windowCaptureMode == WindowCaptureMode.Aero || windowCaptureMode == WindowCaptureMode.AeroTransparent) { ICapture tmpCapture = null; - if (conf.isDWMAllowed(process)) { + if (WindowCapture.isDWMAllowed(process)) { tmpCapture = windowToCapture.CaptureDWMWindow(captureForWindow, windowCaptureMode, isAutoMode); } if (tmpCapture != null) { diff --git a/Greenshot/Helpers/IECaptureHelper.cs b/Greenshot/Helpers/IECaptureHelper.cs index 14431b83f..3e1883b85 100644 --- a/Greenshot/Helpers/IECaptureHelper.cs +++ b/Greenshot/Helpers/IECaptureHelper.cs @@ -153,7 +153,7 @@ namespace Greenshot.Helpers { } LOG.DebugFormat("Trying WM_HTML_GETOBJECT on {0}", ieServer.ClassName); UIntPtr response; - User32.SendMessageTimeout(ieServer.Handle, windowMessage, IntPtr.Zero, IntPtr.Zero, SendMessageTimeoutFlags.SMTO_NORMAL, 1000, out response); + User32.SendMessageTimeout(ieServer.Handle, windowMessage, IntPtr.Zero, IntPtr.Zero, SendMessageTimeoutFlags.SMTO_NORMAL, 5000, out response); if (response != UIntPtr.Zero) { document2 = (IHTMLDocument2)Accessible.ObjectFromLresult(response, typeof(IHTMLDocument).GUID, IntPtr.Zero); if (document2 == null) { diff --git a/GreenshotPlugin/Core/CoreConfiguration.cs b/GreenshotPlugin/Core/CoreConfiguration.cs index d8d019d28..f5a179bd1 100644 --- a/GreenshotPlugin/Core/CoreConfiguration.cs +++ b/GreenshotPlugin/Core/CoreConfiguration.cs @@ -200,49 +200,6 @@ namespace GreenshotPlugin.Core { return (ExperimentalFeatures != null && ExperimentalFeatures.Contains(experimentalFeature)); } - /// - /// Helper method to check if it is allowed to capture the process using DWM - /// - /// Process owning the window - /// true if it's allowed - public bool isDWMAllowed(Process process) { - if (process != null) { - if (NoDWMCaptureForProduct != null && NoDWMCaptureForProduct.Count > 0) { - try { - string productName = process.MainModule.FileVersionInfo.ProductName; - if (productName != null && NoDWMCaptureForProduct.Contains(productName.ToLower())) { - return false; - } - } catch (Exception ex) { - LOG.Warn(ex); - } - } - } - return true; - } - - /// - /// Helper method to check if it is allowed to capture the process using GDI - /// - /// Process owning the window - /// true if it's allowed - public bool isGDIAllowed(Process process) { - if (process != null) { - if (NoGDICaptureForProduct != null && NoGDICaptureForProduct.Count > 0) { - try { - string productName = process.MainModule.FileVersionInfo.ProductName; - if (productName != null && NoGDICaptureForProduct.Contains(productName.ToLower())) { - return false; - } - } catch (Exception ex) { - LOG.Warn(ex); - } - } - } - return true; - } - - /// /// Supply values we can't put as defaults /// diff --git a/GreenshotPlugin/Core/WindowCapture.cs b/GreenshotPlugin/Core/WindowCapture.cs index e74f77a50..fc7371e29 100644 --- a/GreenshotPlugin/Core/WindowCapture.cs +++ b/GreenshotPlugin/Core/WindowCapture.cs @@ -27,6 +27,8 @@ using System.Windows.Forms; using Greenshot.Plugin; using GreenshotPlugin.UnmanagedHelpers; +using System.Diagnostics; +using Greenshot.IniFile; namespace GreenshotPlugin.Core { /// @@ -444,6 +446,7 @@ namespace GreenshotPlugin.Core { /// public class WindowCapture { private static readonly log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(WindowCapture)); + private static CoreConfiguration conf = IniConfig.GetIniSection(); private WindowCapture() { } @@ -550,6 +553,48 @@ namespace GreenshotPlugin.Core { return exceptionToThrow; } + /// + /// Helper method to check if it is allowed to capture the process using DWM + /// + /// Process owning the window + /// true if it's allowed + public static bool isDWMAllowed(Process process) { + if (process != null) { + if (conf.NoDWMCaptureForProduct != null && conf.NoDWMCaptureForProduct.Count > 0) { + try { + string productName = process.MainModule.FileVersionInfo.ProductName; + if (productName != null && conf.NoDWMCaptureForProduct.Contains(productName.ToLower())) { + return false; + } + } catch (Exception ex) { + LOG.Warn(ex.Message); + } + } + } + return true; + } + + /// + /// Helper method to check if it is allowed to capture the process using GDI + /// + /// Process owning the window + /// true if it's allowed + public static bool isGDIAllowed(Process process) { + if (process != null) { + if (conf.NoGDICaptureForProduct != null && conf.NoGDICaptureForProduct.Count > 0) { + try { + string productName = process.MainModule.FileVersionInfo.ProductName; + if (productName != null && conf.NoGDICaptureForProduct.Contains(productName.ToLower())) { + return false; + } + } catch (Exception ex) { + LOG.Warn(ex.Message); + } + } + } + return true; + } + /// /// This method will use User32 code to capture the specified captureBounds from the screen /// diff --git a/GreenshotPlugin/Core/WindowsHelper.cs b/GreenshotPlugin/Core/WindowsHelper.cs index 7241212a2..4b7587e1b 100644 --- a/GreenshotPlugin/Core/WindowsHelper.cs +++ b/GreenshotPlugin/Core/WindowsHelper.cs @@ -818,7 +818,7 @@ namespace GreenshotPlugin.Core { // check if the capture fits if (!capture.ScreenBounds.Contains(captureRectangle)) { // if GDI is allowed.. - if (conf.isGDIAllowed(Process)) { + if (WindowCapture.isGDIAllowed(Process)) { // we return null which causes the capturing code to try another method. return null; }