mirror of
https://github.com/greenshot/greenshot
synced 2025-08-14 02:37:03 -07:00
Refactored code location of the isGDIAllowed/isDWMAllowed, also changed the timeout for getting the HTML object from a window to 5 Seconds (instead of 1).
git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@1877 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4
This commit is contained in:
parent
efd2861e35
commit
cac99fbaf3
5 changed files with 54 additions and 52 deletions
|
@ -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) {
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -200,49 +200,6 @@ namespace GreenshotPlugin.Core {
|
|||
return (ExperimentalFeatures != null && ExperimentalFeatures.Contains(experimentalFeature));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Helper method to check if it is allowed to capture the process using DWM
|
||||
/// </summary>
|
||||
/// <param name="process">Process owning the window</param>
|
||||
/// <returns>true if it's allowed</returns>
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Helper method to check if it is allowed to capture the process using GDI
|
||||
/// </summary>
|
||||
/// <param name="processName">Process owning the window</param>
|
||||
/// <returns>true if it's allowed</returns>
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Supply values we can't put as defaults
|
||||
/// </summary>
|
||||
|
|
|
@ -27,6 +27,8 @@ using System.Windows.Forms;
|
|||
|
||||
using Greenshot.Plugin;
|
||||
using GreenshotPlugin.UnmanagedHelpers;
|
||||
using System.Diagnostics;
|
||||
using Greenshot.IniFile;
|
||||
|
||||
namespace GreenshotPlugin.Core {
|
||||
/// <summary>
|
||||
|
@ -444,6 +446,7 @@ namespace GreenshotPlugin.Core {
|
|||
/// </summary>
|
||||
public class WindowCapture {
|
||||
private static readonly log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(WindowCapture));
|
||||
private static CoreConfiguration conf = IniConfig.GetIniSection<CoreConfiguration>();
|
||||
|
||||
private WindowCapture() {
|
||||
}
|
||||
|
@ -550,6 +553,48 @@ namespace GreenshotPlugin.Core {
|
|||
return exceptionToThrow;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Helper method to check if it is allowed to capture the process using DWM
|
||||
/// </summary>
|
||||
/// <param name="process">Process owning the window</param>
|
||||
/// <returns>true if it's allowed</returns>
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Helper method to check if it is allowed to capture the process using GDI
|
||||
/// </summary>
|
||||
/// <param name="processName">Process owning the window</param>
|
||||
/// <returns>true if it's allowed</returns>
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This method will use User32 code to capture the specified captureBounds from the screen
|
||||
/// </summary>
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue