Code quality changes, and added the possibility to set the amount of colors for the Quantizer.

This commit is contained in:
RKrom 2014-05-11 11:23:56 +02:00
commit 77a92d98c3
92 changed files with 690 additions and 653 deletions

View file

@ -117,10 +117,10 @@ namespace GreenshotPlugin.UnmanagedHelpers {
public static extern uint DwmEnableComposition(uint uCompositionAction);
public static void EnableComposition() {
DWM.DwmEnableComposition(DWM.DWM_EC_ENABLECOMPOSITION);
DwmEnableComposition(DWM_EC_ENABLECOMPOSITION);
}
public static void DisableComposition() {
DWM.DwmEnableComposition(DWM.DWM_EC_DISABLECOMPOSITION);
DwmEnableComposition(DWM_EC_DISABLECOMPOSITION);
}
// Key to ColorizationColor for DWM
@ -139,7 +139,7 @@ namespace GreenshotPlugin.UnmanagedHelpers {
}
if (Environment.OSVersion.Version.Major >= 6) {
bool dwmEnabled;
DWM.DwmIsCompositionEnabled(out dwmEnabled);
DwmIsCompositionEnabled(out dwmEnabled);
return dwmEnabled;
}
return false;

View file

@ -22,6 +22,7 @@ using System;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Security;
using log4net;
using Microsoft.Win32.SafeHandles;
using System.Reflection;
using System.Drawing.Drawing2D;
@ -93,7 +94,7 @@ namespace GreenshotPlugin.UnmanagedHelpers {
/// GDIplus Helpers
/// </summary>
public static class GDIplus {
private static log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(GDIplus));
private static ILog LOG = LogManager.GetLogger(typeof(GDIplus));
[DllImport("gdiplus.dll", SetLastError = true, ExactSpelling = true, CharSet = CharSet.Unicode)]
private static extern int GdipBitmapApplyEffect(IntPtr bitmap, IntPtr effect, ref RECT rectOfInterest, bool useAuxData, IntPtr auxData, int auxDataSize);

View file

@ -76,23 +76,23 @@ namespace GreenshotPlugin.UnmanagedHelpers {
// Try the GetModuleFileName method first since it's the fastest.
// May return ACCESS_DENIED (due to VM_READ flag) if the process is not owned by the current user.
// Will fail if we are compiled as x86 and we're trying to open a 64 bit process...not allowed.
IntPtr hprocess = Kernel32.OpenProcess(ProcessAccessFlags.QueryInformation | ProcessAccessFlags.VMRead, false, processid);
IntPtr hprocess = OpenProcess(ProcessAccessFlags.QueryInformation | ProcessAccessFlags.VMRead, false, processid);
if (hprocess != IntPtr.Zero) {
try {
if (PsAPI.GetModuleFileNameEx(hprocess, IntPtr.Zero, _PathBuffer, (uint)_PathBuffer.Capacity) > 0) {
return _PathBuffer.ToString();
}
} finally {
Kernel32.CloseHandle(hprocess);
CloseHandle(hprocess);
}
}
hprocess = Kernel32.OpenProcess(ProcessAccessFlags.QueryInformation, false, processid);
hprocess = OpenProcess(ProcessAccessFlags.QueryInformation, false, processid);
if (hprocess != IntPtr.Zero) {
try {
// Try this method for Vista or higher operating systems
uint size = (uint)_PathBuffer.Capacity;
if ((Environment.OSVersion.Version.Major >= 6) && (Kernel32.QueryFullProcessImageName(hprocess, 0, _PathBuffer, ref size) && (size > 0))) {
if ((Environment.OSVersion.Version.Major >= 6) && (QueryFullProcessImageName(hprocess, 0, _PathBuffer, ref size) && (size > 0))) {
return _PathBuffer.ToString();
}
@ -100,7 +100,7 @@ namespace GreenshotPlugin.UnmanagedHelpers {
if (PsAPI.GetProcessImageFileName(hprocess, _PathBuffer, (uint)_PathBuffer.Capacity) > 0) {
string dospath = _PathBuffer.ToString();
foreach (string drive in Environment.GetLogicalDrives()) {
if (Kernel32.QueryDosDevice(drive.TrimEnd('\\'), _PathBuffer, (uint)_PathBuffer.Capacity) > 0) {
if (QueryDosDevice(drive.TrimEnd('\\'), _PathBuffer, (uint)_PathBuffer.Capacity) > 0) {
if (dospath.StartsWith(_PathBuffer.ToString())) {
return drive + dospath.Remove(0, _PathBuffer.Length);
}
@ -108,7 +108,7 @@ namespace GreenshotPlugin.UnmanagedHelpers {
}
}
} finally {
Kernel32.CloseHandle(hprocess);
CloseHandle(hprocess);
}
}

View file

@ -44,19 +44,19 @@ namespace GreenshotPlugin.UnmanagedHelpers {
public int Y;
public POINT(int x, int y) {
this.X = x;
this.Y = y;
X = x;
Y = y;
}
public POINT(Point point) {
this.X = point.X;
this.Y = point.Y;
X = point.X;
Y = point.Y;
}
public static implicit operator System.Drawing.Point(POINT p) {
return new System.Drawing.Point(p.X, p.Y);
public static implicit operator Point(POINT p) {
return new Point(p.X, p.Y);
}
public static implicit operator POINT(System.Drawing.Point p) {
public static implicit operator POINT(Point p) {
return new POINT(p.X, p.Y);
}

View file

@ -24,7 +24,7 @@ using System.Diagnostics;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Text;
using System.Windows.Forms;
using Microsoft.Win32.SafeHandles;
using System.Security;
using System.Security.Permissions;
@ -136,7 +136,7 @@ namespace GreenshotPlugin.UnmanagedHelpers {
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool ShowScrollBar(IntPtr hwnd, ScrollBarDirection scrollBar, bool show);
[DllImport("user32", SetLastError = true)]
public static extern int SetScrollPos(IntPtr hWnd, System.Windows.Forms.Orientation nBar, int nPos, bool bRedraw);
public static extern int SetScrollPos(IntPtr hWnd, Orientation nBar, int nPos, bool bRedraw);
[DllImport("user32", SetLastError=true, EntryPoint = "PostMessageA")]
public static extern bool PostMessage(IntPtr hWnd, uint msg, int wParam, int lParam);
[DllImport("user32", SetLastError = true)]
@ -295,12 +295,12 @@ namespace GreenshotPlugin.UnmanagedHelpers {
}
public SafeIconHandle(IntPtr hIcon) : base(true) {
this.SetHandle(hIcon);
SetHandle(hIcon);
}
[SecurityPermission(SecurityAction.LinkDemand, UnmanagedCode = true)]
protected override bool ReleaseHandle() {
return User32.DestroyIcon(this.handle);
return User32.DestroyIcon(handle);
}
}

View file

@ -27,9 +27,9 @@ namespace GreenshotPlugin.UnmanagedHelpers {
/// </summary>
public class WinMM {
[DllImport("winmm.dll", SetLastError = true)]
public static extern bool PlaySound(byte[] ptrToSound, System.UIntPtr hmod, uint fdwSound);
public static extern bool PlaySound(byte[] ptrToSound, UIntPtr hmod, uint fdwSound);
[DllImport("winmm.dll", SetLastError = true)]
public static extern bool PlaySound(IntPtr ptrToSound, System.UIntPtr hmod, uint fdwSound);
public static extern bool PlaySound(IntPtr ptrToSound, UIntPtr hmod, uint fdwSound);
}
}