Code cleanup, already made some changes (which are not active) for the next release so I can work on them without having multiple changed files which might cause check in conflicts.

git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@2359 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4
This commit is contained in:
RKrom 2012-12-06 13:47:17 +00:00
commit 82eddefe4e
5 changed files with 435 additions and 318 deletions

View file

@ -55,7 +55,6 @@ namespace Greenshot.Helpers {
/// </summary> /// </summary>
/// <typeparam name="T">Type for the animation, like Point/Rectangle/Size</typeparam> /// <typeparam name="T">Type for the animation, like Point/Rectangle/Size</typeparam>
public abstract class AnimatorBase<T> : IAnimator { public abstract class AnimatorBase<T> : IAnimator {
private static readonly log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(AnimatorBase<T>));
protected T first; protected T first;
protected T last; protected T last;
protected T current; protected T current;

View file

@ -567,9 +567,7 @@ namespace GreenshotPlugin.Core {
public string ClassName { public string ClassName {
get { get {
if (className == null) { if (className == null) {
StringBuilder classNameBuilder = new StringBuilder(260, 260); className = GetClassName(this.hWnd);
User32.GetClassName(this.hWnd, classNameBuilder, classNameBuilder.Capacity);
className = classNameBuilder.ToString();
} }
return className; return className;
} }
@ -1395,6 +1393,17 @@ namespace GreenshotPlugin.Core {
return this; return this;
} }
/// <summary>
/// Retrieves the classname for a hWnd
/// </summary>
/// <param name="hWnd">IntPtr with the windows handle</param>
/// <returns>String with ClassName</returns>
public static String GetClassName(IntPtr hWnd) {
StringBuilder classNameBuilder = new StringBuilder(260, 260);
User32.GetClassName(hWnd, classNameBuilder, classNameBuilder.Capacity);
return classNameBuilder.ToString();
}
/// <summary> /// <summary>
/// Get all the visible top level windows /// Get all the visible top level windows
/// </summary> /// </summary>

View file

@ -962,6 +962,10 @@ namespace GreenshotPlugin.UnmanagedHelpers {
SND_FILENAME = 0x00020000, // name is file name SND_FILENAME = 0x00020000, // name is file name
} }
/// <summary>
/// Used by GDI32.GetDeviceCaps
/// See: http://msdn.microsoft.com/en-us/library/windows/desktop/dd144877%28v=vs.85%29.aspx
/// </summary>
public enum DeviceCaps { public enum DeviceCaps {
/// <summary> /// <summary>
/// Device driver version /// Device driver version
@ -1125,4 +1129,83 @@ namespace GreenshotPlugin.UnmanagedHelpers {
/// </summary> /// </summary>
BLTALIGNMENT = 119 BLTALIGNMENT = 119
} }
/// <summary>
/// Used for User32.SetWinEventHook
/// See: http://msdn.microsoft.com/en-us/library/windows/desktop/dd373640%28v=vs.85%29.aspx
/// </summary>
public enum WinEventHookFlags : int {
WINEVENT_SKIPOWNTHREAD = 1,
WINEVENT_SKIPOWNPROCESS = 2,
WINEVENT_OUTOFCONTEXT = 0,
WINEVENT_INCONTEXT = 4
}
/// <summary>
/// Used for User32.SetWinEventHook
/// See MSDN: http://msdn.microsoft.com/en-us/library/windows/desktop/dd318066%28v=vs.85%29.aspx
/// </summary>
public enum WinEvent : uint {
EVENT_OBJECT_ACCELERATORCHANGE = 32786,
EVENT_OBJECT_CREATE = 32768,
EVENT_OBJECT_DESTROY = 32769,
EVENT_OBJECT_DEFACTIONCHANGE = 32785,
EVENT_OBJECT_DESCRIPTIONCHANGE = 32781,
EVENT_OBJECT_FOCUS = 32773,
EVENT_OBJECT_HELPCHANGE = 32784,
EVENT_OBJECT_SHOW = 32770,
EVENT_OBJECT_HIDE = 32771,
EVENT_OBJECT_LOCATIONCHANGE = 32779,
EVENT_OBJECT_NAMECHANGE = 32780,
EVENT_OBJECT_PARENTCHANGE = 32783,
EVENT_OBJECT_REORDER = 32772,
EVENT_OBJECT_SELECTION = 32774,
EVENT_OBJECT_SELECTIONADD = 32775,
EVENT_OBJECT_SELECTIONREMOVE = 32776,
EVENT_OBJECT_SELECTIONWITHIN = 32777,
EVENT_OBJECT_STATECHANGE = 32778,
EVENT_OBJECT_VALUECHANGE = 32782,
EVENT_SYSTEM_ALERT = 2,
EVENT_SYSTEM_CAPTUREEND = 9,
EVENT_SYSTEM_CAPTURESTART = 8,
EVENT_SYSTEM_CONTEXTHELPEND = 13,
EVENT_SYSTEM_CONTEXTHELPSTART = 12,
EVENT_SYSTEM_DIALOGEND = 17,
EVENT_SYSTEM_DIALOGSTART = 16,
EVENT_SYSTEM_DRAGDROPEND = 15,
EVENT_SYSTEM_DRAGDROPSTART = 14,
EVENT_SYSTEM_FOREGROUND = 3,
EVENT_SYSTEM_MENUEND = 5,
EVENT_SYSTEM_MENUPOPUPEND = 7,
EVENT_SYSTEM_MENUPOPUPSTART = 6,
EVENT_SYSTEM_MENUSTART = 4,
EVENT_SYSTEM_MINIMIZEEND = 23,
EVENT_SYSTEM_MINIMIZESTART = 22,
EVENT_SYSTEM_MOVESIZEEND = 11,
EVENT_SYSTEM_MOVESIZESTART = 10,
EVENT_SYSTEM_SCROLLINGEND = 19,
EVENT_SYSTEM_SCROLLINGSTART = 18,
EVENT_SYSTEM_SOUND = 1,
EVENT_SYSTEM_SWITCHEND = 21,
EVENT_SYSTEM_SWITCHSTART = 20
}
/// <summary>
/// Used for User32.SetWinEventHook
/// See: http://msdn.microsoft.com/en-us/library/windows/desktop/dd373606%28v=vs.85%29.aspx#OBJID_WINDOW
/// </summary>
public enum EventObjects : int {
OBJID_ALERT = -10,
OBJID_CARET = -8,
OBJID_CLIENT = -4,
OBJID_CURSOR = -9,
OBJID_HSCROLL = -6,
OBJID_MENU = -3,
OBJID_SIZEGRIP = -7,
OBJID_SOUND = -11,
OBJID_SYSMENU = -1,
OBJID_TITLEBAR = -2,
OBJID_VSCROLL = -5,
OBJID_WINDOW = 0
}
} }

View file

@ -38,5 +38,274 @@ namespace GreenshotPlugin.UnmanagedHelpers {
return new Size(width, height); return new Size(width, height);
} }
} }
[StructLayout(LayoutKind.Sequential), Serializable()]
public struct POINT {
public int X;
public int Y;
public POINT(int x, int y) {
this.X = x;
this.Y = y;
}
public POINT(Point point) {
this.X = point.X;
this.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(System.Drawing.Point p) {
return new POINT(p.X, p.Y);
}
public Point ToPoint() {
return new Point(X, Y);
}
override public string ToString() {
return X + "," + Y;
}
}
[StructLayout(LayoutKind.Sequential), Serializable()]
public struct RECT {
private int _Left;
private int _Top;
private int _Right;
private int _Bottom;
public RECT(RECT rectangle)
: this(rectangle.Left, rectangle.Top, rectangle.Right, rectangle.Bottom) {
}
public RECT(Rectangle rectangle)
: this(rectangle.Left, rectangle.Top, rectangle.Right, rectangle.Bottom) {
}
public RECT(int Left, int Top, int Right, int Bottom) {
_Left = Left;
_Top = Top;
_Right = Right;
_Bottom = Bottom;
}
public int X {
get {
return _Left;
}
set {
_Left = value;
}
}
public int Y {
get {
return _Top;
}
set {
_Top = value;
}
}
public int Left {
get {
return _Left;
}
set {
_Left = value;
}
}
public int Top {
get {
return _Top;
}
set {
_Top = value;
}
}
public int Right {
get {
return _Right;
}
set {
_Right = value;
}
}
public int Bottom {
get {
return _Bottom;
}
set {
_Bottom = value;
}
}
public int Height {
get {
return _Bottom - _Top;
}
set {
_Bottom = value - _Top;
}
}
public int Width {
get {
return _Right - _Left;
}
set {
_Right = value + _Left;
}
}
public Point Location {
get {
return new Point(Left, Top);
}
set {
_Left = value.X;
_Top = value.Y;
}
}
public Size Size {
get {
return new Size(Width, Height);
}
set {
_Right = value.Width + _Left;
_Bottom = value.Height + _Top;
}
}
public static implicit operator Rectangle(RECT Rectangle) {
return new Rectangle(Rectangle.Left, Rectangle.Top, Rectangle.Width, Rectangle.Height);
}
public static implicit operator RECT(Rectangle Rectangle) {
return new RECT(Rectangle.Left, Rectangle.Top, Rectangle.Right, Rectangle.Bottom);
}
public static bool operator ==(RECT Rectangle1, RECT Rectangle2) {
return Rectangle1.Equals(Rectangle2);
}
public static bool operator !=(RECT Rectangle1, RECT Rectangle2) {
return !Rectangle1.Equals(Rectangle2);
}
public override string ToString() {
return "{Left: " + _Left + "; " + "Top: " + _Top + "; Right: " + _Right + "; Bottom: " + _Bottom + "}";
}
public override int GetHashCode() {
return ToString().GetHashCode();
}
public bool Equals(RECT Rectangle) {
return Rectangle.Left == _Left && Rectangle.Top == _Top && Rectangle.Right == _Right && Rectangle.Bottom == _Bottom;
}
public Rectangle ToRectangle() {
return new Rectangle(Left, Top, Width, Height);
}
public override bool Equals(object Object) {
if (Object is RECT) {
return Equals((RECT)Object);
} else if (Object is Rectangle) {
return Equals(new RECT((Rectangle)Object));
}
return false;
}
}
[StructLayout(LayoutKind.Sequential), Serializable()]
public struct WindowInfo {
public uint cbSize;
public RECT rcWindow;
public RECT rcClient;
public uint dwStyle;
public uint dwExStyle;
public uint dwWindowStatus;
public uint cxWindowBorders;
public uint cyWindowBorders;
public ushort atomWindowType;
public ushort wCreatorVersion;
// Allows automatic initialization of "cbSize" with "new WINDOWINFO(null/true/false)".
public WindowInfo(Boolean? filler)
: this() {
cbSize = (UInt32)(Marshal.SizeOf(typeof(WindowInfo)));
}
}
/// <summary>
/// Contains information about the placement of a window on the screen.
/// </summary>
[StructLayout(LayoutKind.Sequential), Serializable()]
public struct WindowPlacement {
/// <summary>
/// The length of the structure, in bytes. Before calling the GetWindowPlacement or SetWindowPlacement functions, set this member to sizeof(WINDOWPLACEMENT).
/// <para>
/// GetWindowPlacement and SetWindowPlacement fail if this member is not set correctly.
/// </para>
/// </summary>
public int Length;
/// <summary>
/// Specifies flags that control the position of the minimized window and the method by which the window is restored.
/// </summary>
public WindowPlacementFlags Flags;
/// <summary>
/// The current show state of the window.
/// </summary>
public ShowWindowCommand ShowCmd;
/// <summary>
/// The coordinates of the window's upper-left corner when the window is minimized.
/// </summary>
public POINT MinPosition;
/// <summary>
/// The coordinates of the window's upper-left corner when the window is maximized.
/// </summary>
public POINT MaxPosition;
/// <summary>
/// The window's coordinates when the window is in the restored position.
/// </summary>
public RECT NormalPosition;
/// <summary>
/// Gets the default (empty) value.
/// </summary>
public static WindowPlacement Default {
get {
WindowPlacement result = new WindowPlacement();
result.Length = Marshal.SizeOf(result);
return result;
}
}
}
[StructLayout(LayoutKind.Sequential)]
public struct CursorInfo {
public Int32 cbSize;
public Int32 flags;
public IntPtr hCursor;
public POINT ptScreenPos;
}
[StructLayout(LayoutKind.Sequential)]
public struct IconInfo {
public bool fIcon;
public Int32 xHotspot;
public Int32 yHotspot;
public IntPtr hbmMask;
public IntPtr hbmColor;
}
[Serializable, StructLayout(LayoutKind.Sequential)]
public struct SCROLLINFO {
public int cbSize;
public int fMask;
public int nMin;
public int nMax;
public int nPage;
public int nPos;
public int nTrackPos;
}
} }

View file

@ -26,239 +26,25 @@ using System.Runtime.InteropServices;
using System.Text; using System.Text;
namespace GreenshotPlugin.UnmanagedHelpers { namespace GreenshotPlugin.UnmanagedHelpers {
/// <summary>
/// Used with EnumWindows or EnumChildWindows
/// </summary>
/// <param name="hwnd"></param>
/// <param name="lParam"></param>
/// <returns></returns>
public delegate int EnumWindowsProc(IntPtr hwnd, int lParam); public delegate int EnumWindowsProc(IntPtr hwnd, int lParam);
[StructLayout(LayoutKind.Sequential), Serializable()]
public struct POINT {
public int X;
public int Y;
public POINT(int x, int y) {
this.X = x;
this.Y = y;
}
public POINT(Point point) {
this.X = point.X;
this.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(System.Drawing.Point p) {
return new POINT(p.X, p.Y);
}
public Point ToPoint() {
return new Point(X, Y);
}
override public string ToString() {
return X +","+Y;
}
}
[StructLayout(LayoutKind.Sequential), Serializable()]
public struct RECT {
private int _Left;
private int _Top;
private int _Right;
private int _Bottom;
public RECT(RECT rectangle) : this(rectangle.Left, rectangle.Top, rectangle.Right, rectangle.Bottom) {
}
public RECT(Rectangle rectangle) : this(rectangle.Left, rectangle.Top, rectangle.Right, rectangle.Bottom) {
}
public RECT(int Left, int Top, int Right, int Bottom) {
_Left = Left;
_Top = Top;
_Right = Right;
_Bottom = Bottom;
}
public int X {
get { return _Left; }
set { _Left = value; }
}
public int Y {
get { return _Top; }
set { _Top = value; }
}
public int Left {
get { return _Left; }
set { _Left = value; }
}
public int Top {
get { return _Top; }
set { _Top = value; }
}
public int Right {
get { return _Right; }
set { _Right = value; }
}
public int Bottom {
get { return _Bottom; }
set { _Bottom = value; }
}
public int Height {
get { return _Bottom - _Top; }
set { _Bottom = value - _Top; }
}
public int Width {
get { return _Right - _Left; }
set { _Right = value + _Left; }
}
public Point Location {
get { return new Point(Left, Top); }
set {
_Left = value.X;
_Top = value.Y;
}
}
public Size Size {
get { return new Size(Width, Height); }
set {
_Right = value.Width + _Left;
_Bottom = value.Height + _Top;
}
}
public static implicit operator Rectangle(RECT Rectangle) {
return new Rectangle(Rectangle.Left, Rectangle.Top, Rectangle.Width, Rectangle.Height);
}
public static implicit operator RECT(Rectangle Rectangle) {
return new RECT(Rectangle.Left, Rectangle.Top, Rectangle.Right, Rectangle.Bottom);
}
public static bool operator ==(RECT Rectangle1, RECT Rectangle2)
{
return Rectangle1.Equals(Rectangle2);
}
public static bool operator !=(RECT Rectangle1, RECT Rectangle2) {
return !Rectangle1.Equals(Rectangle2);
}
public override string ToString() {
return "{Left: " + _Left + "; " + "Top: " + _Top + "; Right: " + _Right + "; Bottom: " + _Bottom + "}";
}
public override int GetHashCode() {
return ToString().GetHashCode();
}
public bool Equals(RECT Rectangle) {
return Rectangle.Left == _Left && Rectangle.Top == _Top && Rectangle.Right == _Right && Rectangle.Bottom == _Bottom;
}
public Rectangle ToRectangle() {
return new Rectangle(Left, Top, Width, Height);
}
public override bool Equals(object Object) {
if (Object is RECT) {
return Equals((RECT)Object);
} else if (Object is Rectangle) {
return Equals(new RECT((Rectangle)Object));
}
return false;
}
}
[StructLayout(LayoutKind.Sequential), Serializable()]
public struct WindowInfo {
public uint cbSize;
public RECT rcWindow;
public RECT rcClient;
public uint dwStyle;
public uint dwExStyle;
public uint dwWindowStatus;
public uint cxWindowBorders;
public uint cyWindowBorders;
public ushort atomWindowType;
public ushort wCreatorVersion;
// Allows automatic initialization of "cbSize" with "new WINDOWINFO(null/true/false)".
public WindowInfo(Boolean ? filler) : this() {
cbSize = (UInt32)(Marshal.SizeOf(typeof( WindowInfo )));
}
}
/// <summary> /// <summary>
/// Contains information about the placement of a window on the screen. /// Used with SetWinEventHook
/// </summary> /// </summary>
[StructLayout(LayoutKind.Sequential), Serializable()] /// <param name="hWinEventHook"></param>
public struct WindowPlacement { /// <param name="eventType"></param>
/// <summary> /// <param name="hwnd"></param>
/// The length of the structure, in bytes. Before calling the GetWindowPlacement or SetWindowPlacement functions, set this member to sizeof(WINDOWPLACEMENT). /// <param name="idObject"></param>
/// <para> /// <param name="idChild"></param>
/// GetWindowPlacement and SetWindowPlacement fail if this member is not set correctly. /// <param name="dwEventThread"></param>
/// </para> /// <param name="dwmsEventTime"></param>
/// </summary> public delegate void WinEventDelegate(IntPtr hWinEventHook, WinEvent eventType, IntPtr hwnd, EventObjects idObject, int idChild, uint dwEventThread, uint dwmsEventTime);
public int Length;
/// <summary>
/// Specifies flags that control the position of the minimized window and the method by which the window is restored.
/// </summary>
public WindowPlacementFlags Flags;
/// <summary>
/// The current show state of the window.
/// </summary>
public ShowWindowCommand ShowCmd;
/// <summary>
/// The coordinates of the window's upper-left corner when the window is minimized.
/// </summary>
public POINT MinPosition;
/// <summary>
/// The coordinates of the window's upper-left corner when the window is maximized.
/// </summary>
public POINT MaxPosition;
/// <summary>
/// The window's coordinates when the window is in the restored position.
/// </summary>
public RECT NormalPosition;
/// <summary>
/// Gets the default (empty) value.
/// </summary>
public static WindowPlacement Default {
get {
WindowPlacement result = new WindowPlacement();
result.Length = Marshal.SizeOf( result );
return result;
}
}
}
[StructLayout(LayoutKind.Sequential)]
public struct CursorInfo {
public Int32 cbSize;
public Int32 flags;
public IntPtr hCursor;
public POINT ptScreenPos;
}
[StructLayout(LayoutKind.Sequential)]
public struct IconInfo {
public bool fIcon;
public Int32 xHotspot;
public Int32 yHotspot;
public IntPtr hbmMask;
public IntPtr hbmColor;
}
[Serializable, StructLayout(LayoutKind.Sequential)]
public struct SCROLLINFO {
public int cbSize;
public int fMask;
public int nMin;
public int nMax;
public int nPage;
public int nPos;
public int nTrackPos;
}
/// <summary> /// <summary>
/// User32 Wrappers /// User32 Wrappers
@ -276,32 +62,6 @@ namespace GreenshotPlugin.UnmanagedHelpers {
public const int MONITOR_DEFAULTTONULL = 0; public const int MONITOR_DEFAULTTONULL = 0;
public const int MONITOR_DEFAULTTOPRIMARY = 1; public const int MONITOR_DEFAULTTOPRIMARY = 1;
public const int MONITOR_DEFAULTTONEAREST = 2; public const int MONITOR_DEFAULTTONEAREST = 2;
/// <summary>
/// Stop flashing. The system restores the window to its original state.
/// </summary>
public const int FLASHW_STOP = 0;
/// <summary>
/// Flash the window caption.
/// </summary>
public const int FLASHW_CAPTION = 0x00000001;
/// <summary>
/// Flash the taskbar button.
/// </summary>
public const int FLASHW_TRAY = 0x00000002;
/// <summary>
/// Flash both the window caption and taskbar button.
/// </summary>
public const int FLASHW_ALL = (FLASHW_CAPTION | FLASHW_TRAY);
/// <summary>
/// Flash continuously, until the FLASHW_STOP flag is set.
/// </summary>
public const int FLASHW_TIMER = 0x00000004;
/// <summary>
/// Flash continuously until the window comes to the foreground.
/// </summary>
public const int FLASHW_TIMERNOFG = 0x0000000C;
public const Int32 CURSOR_SHOWING = 0x00000001; public const Int32 CURSOR_SHOWING = 0x00000001;
[DllImport("user32", SetLastError = true)] [DllImport("user32", SetLastError = true)]
@ -364,20 +124,6 @@ namespace GreenshotPlugin.UnmanagedHelpers {
public static extern IntPtr MonitorFromWindow(IntPtr hwnd, uint dwFlags); public static extern IntPtr MonitorFromWindow(IntPtr hwnd, uint dwFlags);
[DllImport("user32", SetLastError = true)] [DllImport("user32", SetLastError = true)]
public static extern IntPtr MonitorFromRect([In] ref RECT lprc, uint dwFlags); public static extern IntPtr MonitorFromRect([In] ref RECT lprc, uint dwFlags);
/// <summary>
/// Wrapper for the GetWindowLong which decides if the system is 64-bit or not and calls the right one.
/// </summary>
/// <param name="hwnd"></param>
/// <param name="nIndex"></param>
/// <returns></returns>
public static uint GetWindowLongWrapper(IntPtr hwnd, int nIndex) {
if (IntPtr.Size == 8) {
return GetWindowLongPtr(hwnd, nIndex);
} else {
return GetWindowLong(hwnd, nIndex);
}
}
[DllImport("user32", SetLastError = true)] [DllImport("user32", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)] [return: MarshalAs(UnmanagedType.Bool)]
public static extern bool GetWindowInfo(IntPtr hwnd, ref WindowInfo pwi); public static extern bool GetWindowInfo(IntPtr hwnd, ref WindowInfo pwi);
@ -420,7 +166,13 @@ namespace GreenshotPlugin.UnmanagedHelpers {
[DllImport("user32", SetLastError = true, CharSet = CharSet.Auto)] [DllImport("user32", SetLastError = true, CharSet = CharSet.Auto)]
public static extern bool ChangeClipboardChain(IntPtr hWndRemove, IntPtr hWndNewNext); public static extern bool ChangeClipboardChain(IntPtr hWndRemove, IntPtr hWndNewNext);
// Added for finding Metro apps // Added for WinEventHook logic, Greenshot 1.2
[DllImport("user32", SetLastError = true)]
public static extern bool UnhookWinEvent(IntPtr hWinEventHook);
[DllImport("user32", SetLastError = true)]
public static extern IntPtr SetWinEventHook(WinEvent eventMin, WinEvent eventMax, IntPtr hmodWinEventProc, WinEventDelegate lpfnWinEventProc, int idProcess, int idThread, WinEventHookFlags dwFlags);
// Added for finding Metro apps, Greenshot 1.1
[DllImport("user32", SetLastError = true)] [DllImport("user32", SetLastError = true)]
public static extern IntPtr FindWindow(string lpClassName, string lpWindowName); public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
[DllImport("user32", SetLastError = true)] [DllImport("user32", SetLastError = true)]
@ -435,6 +187,53 @@ namespace GreenshotPlugin.UnmanagedHelpers {
/// ///
[DllImport("user32", SetLastError = true)] [DllImport("user32", SetLastError = true)]
public static extern uint GetGuiResources(IntPtr hProcess, uint uiFlags); public static extern uint GetGuiResources(IntPtr hProcess, uint uiFlags);
[DllImport("user32", EntryPoint = "RegisterWindowMessageA", SetLastError = true)]
public static extern uint RegisterWindowMessage(string lpString);
[DllImport("user32", SetLastError=true, CharSet=CharSet.Auto)]
public static extern IntPtr SendMessageTimeout(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam, SendMessageTimeoutFlags fuFlags, uint uTimeout, out UIntPtr lpdwResult);
[DllImport("user32", SetLastError = true)]
public static extern bool GetPhysicalCursorPos(out POINT cursorLocation);
[DllImport("user32", SetLastError=true)]
public static extern int MapWindowPoints(IntPtr hwndFrom, IntPtr hwndTo, ref POINT lpPoints, [MarshalAs(UnmanagedType.U4)] int cPoints);
[DllImport("user32", SetLastError = true)]
public static extern int GetSystemMetrics(SystemMetric index);
/// <summary>
/// The following is used for Icon handling
/// </summary>
/// <param name="hIcon"></param>
/// <returns></returns>
[DllImport("user32", SetLastError = true)]
public static extern IntPtr CopyIcon(IntPtr hIcon);
[DllImport("user32", SetLastError = true)]
public static extern bool DestroyIcon(IntPtr hIcon);
[DllImport("user32", SetLastError = true)]
public static extern bool GetCursorInfo(out CursorInfo cursorInfo);
[DllImport("user32", SetLastError = true)]
public static extern bool GetIconInfo(IntPtr hIcon, out IconInfo iconInfo);
[DllImport("user32", SetLastError = true)]
public static extern bool DrawIcon(IntPtr hDC, int X, int Y, IntPtr hIcon);
[DllImport("user32", SetLastError = true)]
public static extern IntPtr SetCapture(IntPtr hWnd);
[DllImport("user32", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool ReleaseCapture();
[DllImport("user32", SetLastError = true)]
public static extern IntPtr CreateIconIndirect(ref IconInfo icon);
/// <summary>
/// Wrapper for the GetWindowLong which decides if the system is 64-bit or not and calls the right one.
/// </summary>
/// <param name="hwnd"></param>
/// <param name="nIndex"></param>
/// <returns></returns>
public static uint GetWindowLongWrapper(IntPtr hwnd, int nIndex) {
if (IntPtr.Size == 8) {
return GetWindowLongPtr(hwnd, nIndex);
} else {
return GetWindowLong(hwnd, nIndex);
}
}
public static uint GetGuiResourcesGDICount() { public static uint GetGuiResourcesGDICount() {
return GetGuiResources(Process.GetCurrentProcess().Handle, 0); return GetGuiResources(Process.GetCurrentProcess().Handle, 0);
@ -444,11 +243,6 @@ namespace GreenshotPlugin.UnmanagedHelpers {
return GetGuiResources(Process.GetCurrentProcess().Handle, 1); return GetGuiResources(Process.GetCurrentProcess().Handle, 1);
} }
[DllImport("user32", EntryPoint = "RegisterWindowMessageA", SetLastError = true)]
public static extern uint RegisterWindowMessage(string lpString);
[DllImport("user32", SetLastError=true, CharSet=CharSet.Auto)]
public static extern IntPtr SendMessageTimeout(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam, SendMessageTimeoutFlags fuFlags, uint uTimeout, out UIntPtr lpdwResult);
/// <summary> /// <summary>
/// Helper method to create a Win32 exception with the windows message in it /// Helper method to create a Win32 exception with the windows message in it
/// </summary> /// </summary>
@ -459,42 +253,5 @@ namespace GreenshotPlugin.UnmanagedHelpers {
exceptionToThrow.Data.Add("Method", method); exceptionToThrow.Data.Add("Method", method);
return exceptionToThrow; return exceptionToThrow;
} }
[DllImport("user32", SetLastError = true)]
public static extern bool GetPhysicalCursorPos(out POINT cursorLocation);
[DllImport("user32", SetLastError=true)]
public static extern int MapWindowPoints(IntPtr hwndFrom, IntPtr hwndTo, ref POINT lpPoints, [MarshalAs(UnmanagedType.U4)] int cPoints);
#region icon
[DllImport("user32", SetLastError = true)]
public static extern IntPtr CopyIcon(IntPtr hIcon);
[DllImport("user32", SetLastError = true)]
public static extern bool DestroyIcon(IntPtr hIcon);
[DllImport("user32", SetLastError = true)]
public static extern bool GetCursorInfo(out CursorInfo cursorInfo);
[DllImport("user32", SetLastError = true)]
public static extern bool GetIconInfo(IntPtr hIcon, out IconInfo iconInfo);
[DllImport("user32", SetLastError = true)]
public static extern bool DrawIcon(IntPtr hDC, int X, int Y, IntPtr hIcon);
[DllImport("user32", SetLastError = true)]
public static extern IntPtr SetCapture(IntPtr hWnd);
[DllImport("user32", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool ReleaseCapture();
[DllImport("user32", SetLastError = true)]
public static extern int GetSystemMetrics(SystemMetric index);
[DllImport("user32", SetLastError = true)]
public static extern IntPtr CreateIconIndirect(ref IconInfo icon);
#endregion
} }
} }