refactor Interop classes
This commit is contained in:
1 parent
de5c2e7a6e
commit
a3dd633a66
28 files changed
+948
-976
No files matched your search
@@ -1,54 +0,0 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security;
|
||||
|
||||
namespace HandyControl.Tools.Interop
|
||||
{
|
||||
[StructLayout(LayoutKind.Sequential, Pack = 2)]
|
||||
[SuppressMessage("ReSharper", "InconsistentNaming")]
|
||||
internal struct BITMAPINFO
|
||||
{
|
||||
public int bmiHeader_biSize;
|
||||
|
||||
public int bmiHeader_biWidth;
|
||||
|
||||
public int bmiHeader_biHeight;
|
||||
|
||||
public short bmiHeader_biPlanes;
|
||||
|
||||
public short bmiHeader_biBitCount;
|
||||
|
||||
public int bmiHeader_biCompression;
|
||||
|
||||
public int bmiHeader_biSizeImage;
|
||||
|
||||
public int bmiHeader_biXPelsPerMeter;
|
||||
|
||||
public int bmiHeader_biYPelsPerMeter;
|
||||
|
||||
public int bmiHeader_biClrUsed;
|
||||
|
||||
public int bmiHeader_biClrImportant;
|
||||
|
||||
public BITMAPINFO(int width, int height, short bpp)
|
||||
{
|
||||
bmiHeader_biSize = SizeOf();
|
||||
bmiHeader_biWidth = width;
|
||||
bmiHeader_biHeight = height;
|
||||
bmiHeader_biPlanes = 1;
|
||||
bmiHeader_biBitCount = bpp;
|
||||
bmiHeader_biCompression = 0;
|
||||
bmiHeader_biSizeImage = 0;
|
||||
bmiHeader_biXPelsPerMeter = 0;
|
||||
bmiHeader_biYPelsPerMeter = 0;
|
||||
bmiHeader_biClrUsed = 0;
|
||||
bmiHeader_biClrImportant = 0;
|
||||
}
|
||||
|
||||
[SecuritySafeCritical]
|
||||
private static int SizeOf()
|
||||
{
|
||||
return Marshal.SizeOf(typeof(BITMAPINFO));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
namespace HandyControl.Tools.Interop
|
||||
{
|
||||
internal static class ExternDll
|
||||
{
|
||||
public const string
|
||||
User32 = "user32.dll",
|
||||
Gdi32 = "gdi32.dll",
|
||||
Kernel32 = "kernel32.dll",
|
||||
Shell32 = "shell32.dll";
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -24,7 +24,7 @@ namespace HandyControl.Tools.Interop
|
||||
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
|
||||
protected override bool ReleaseHandle()
|
||||
{
|
||||
return UnsafeNativeMethods.DeleteObject(handle);
|
||||
return InteropMethods.DeleteObject(handle);
|
||||
}
|
||||
|
||||
[SecurityCritical]
|
||||
File renamed without changes.
File renamed without changes.
+1
-1
@@ -15,7 +15,7 @@ namespace HandyControl.Tools.Interop
|
||||
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
|
||||
protected override bool ReleaseHandle()
|
||||
{
|
||||
return UnsafeNativeMethods.DestroyIcon(handle);
|
||||
return InteropMethods.DestroyIcon(handle);
|
||||
}
|
||||
|
||||
[SecurityCritical, SecuritySafeCritical]
|
||||
+1
-1
@@ -43,7 +43,7 @@ namespace HandyControl.Tools.Interop
|
||||
public static bool CloseHandleNoThrow(HandleRef handle)
|
||||
{
|
||||
HandleCollector.Remove((IntPtr)handle, CommonHandles.Kernel);
|
||||
var result = UnsafeNativeMethods.IntCloseHandle(handle);
|
||||
var result = InteropMethods.IntCloseHandle(handle);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
File renamed without changes.
@@ -1,16 +0,0 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace HandyControl.Tools.Interop
|
||||
{
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
[SuppressMessage("ReSharper", "InconsistentNaming")]
|
||||
internal class ICONINFO
|
||||
{
|
||||
public bool fIcon = false;
|
||||
public int xHotspot = 0;
|
||||
public int yHotspot = 0;
|
||||
public BitmapHandle hbmMask = null;
|
||||
public BitmapHandle hbmColor = null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,281 @@
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Runtime.Versioning;
|
||||
using System.Security;
|
||||
using System.Text;
|
||||
|
||||
namespace HandyControl.Tools.Interop
|
||||
{
|
||||
internal class InteropMethods
|
||||
{
|
||||
[DllImport(InteropValues.ExternDll.User32, CharSet = CharSet.Auto)]
|
||||
[ResourceExposure(ResourceScope.None)]
|
||||
public static extern int RegisterWindowMessage(string msg);
|
||||
|
||||
[DllImport(InteropValues.ExternDll.User32, SetLastError = true, CharSet = CharSet.Auto)]
|
||||
public static extern int MapWindowPoints(IntPtr hWndFrom, IntPtr hWndTo, ref InteropValues.RECT lpPoints, uint cPoints);
|
||||
|
||||
[DllImport(InteropValues.ExternDll.Kernel32, SetLastError = true, CharSet = CharSet.Auto)]
|
||||
public static extern bool ReadProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, out InteropValues.TBBUTTON lpBuffer,
|
||||
int dwSize, out int lpNumberOfBytesRead);
|
||||
|
||||
[DllImport(InteropValues.ExternDll.Kernel32, SetLastError = true)]
|
||||
public static extern bool ReadProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, out InteropValues.RECT lpBuffer,
|
||||
int dwSize, out int lpNumberOfBytesRead);
|
||||
|
||||
[DllImport(InteropValues.ExternDll.Kernel32, SetLastError = true)]
|
||||
public static extern bool ReadProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, out InteropValues.TRAYDATA lpBuffer,
|
||||
int dwSize, out int lpNumberOfBytesRead);
|
||||
|
||||
[DllImport(InteropValues.ExternDll.User32, CharSet = CharSet.Auto)]
|
||||
public static extern uint SendMessage(IntPtr hWnd, uint Msg, uint wParam, IntPtr lParam);
|
||||
|
||||
[DllImport(InteropValues.ExternDll.User32, SetLastError = true, CharSet = CharSet.Auto)]
|
||||
public static extern uint GetWindowThreadProcessId(IntPtr hWnd, out uint lpdwProcessId);
|
||||
|
||||
[DllImport(InteropValues.ExternDll.Kernel32, SetLastError = true, CharSet = CharSet.Auto)]
|
||||
public static extern IntPtr OpenProcess(InteropValues.ProcessAccess dwDesiredAccess,
|
||||
[MarshalAs(UnmanagedType.Bool)] bool bInheritHandle, uint dwProcessId);
|
||||
|
||||
[DllImport(InteropValues.ExternDll.Kernel32, SetLastError = true, CharSet = CharSet.Auto)]
|
||||
public static extern IntPtr VirtualAllocEx(IntPtr hProcess, IntPtr lpAddress, int dwSize,
|
||||
InteropValues.AllocationType flAllocationType, InteropValues.MemoryProtection flProtect);
|
||||
|
||||
[DllImport(InteropValues.ExternDll.Kernel32, SetLastError = true, CharSet = CharSet.Auto)]
|
||||
public static extern int CloseHandle(IntPtr hObject);
|
||||
|
||||
[DllImport(InteropValues.ExternDll.Kernel32, SetLastError = true, CharSet = CharSet.Auto)]
|
||||
public static extern bool VirtualFreeEx(IntPtr hProcess, IntPtr lpAddress, int dwSize, InteropValues.FreeType dwFreeType);
|
||||
|
||||
[DllImport(InteropValues.ExternDll.User32, SetLastError = true)]
|
||||
public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
|
||||
|
||||
[DllImport(InteropValues.ExternDll.User32, SetLastError = true)]
|
||||
public static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass,
|
||||
string lpszWindow);
|
||||
|
||||
[DllImport(InteropValues.ExternDll.User32)]
|
||||
public static extern int GetWindowRect(IntPtr hwnd, out InteropValues.RECT lpRect);
|
||||
|
||||
[DllImport(InteropValues.ExternDll.User32, CharSet = CharSet.Auto)]
|
||||
public static extern bool GetCursorPos(out InteropValues.POINT pt);
|
||||
|
||||
[DllImport(InteropValues.ExternDll.User32)]
|
||||
public static extern IntPtr GetDesktopWindow();
|
||||
|
||||
[DllImport(InteropValues.ExternDll.User32, SetLastError = true)]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
public static extern bool AddClipboardFormatListener(IntPtr hwnd);
|
||||
|
||||
[DllImport(InteropValues.ExternDll.User32, SetLastError = true)]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
public static extern bool RemoveClipboardFormatListener(IntPtr hwnd);
|
||||
|
||||
[DllImport(InteropValues.ExternDll.User32)]
|
||||
public static extern IntPtr GetSystemMenu(IntPtr hWnd, bool bRevert);
|
||||
|
||||
[DllImport(InteropValues.ExternDll.User32)]
|
||||
public static extern bool InsertMenu(IntPtr hMenu, int wPosition, int wFlags, int wIDNewItem, string lpNewItem);
|
||||
|
||||
[SecurityCritical]
|
||||
[SuppressUnmanagedCodeSecurity]
|
||||
[DllImport(InteropValues.ExternDll.User32, SetLastError = true, ExactSpelling = true, EntryPoint = nameof(GetDC),
|
||||
CharSet = CharSet.Auto)]
|
||||
public static extern IntPtr IntGetDC(HandleRef hWnd);
|
||||
|
||||
[SecurityCritical]
|
||||
public static IntPtr GetDC(HandleRef hWnd)
|
||||
{
|
||||
var hDc = IntGetDC(hWnd);
|
||||
if (hDc == IntPtr.Zero) throw new Win32Exception();
|
||||
|
||||
return HandleCollector.Add(hDc, CommonHandles.HDC);
|
||||
}
|
||||
|
||||
[SecurityCritical]
|
||||
[SuppressUnmanagedCodeSecurity]
|
||||
[DllImport(InteropValues.ExternDll.User32, ExactSpelling = true, EntryPoint = nameof(ReleaseDC), CharSet = CharSet.Auto)]
|
||||
public static extern int IntReleaseDC(HandleRef hWnd, HandleRef hDC);
|
||||
|
||||
[SecurityCritical]
|
||||
public static int ReleaseDC(HandleRef hWnd, HandleRef hDC)
|
||||
{
|
||||
HandleCollector.Remove((IntPtr) hDC, CommonHandles.HDC);
|
||||
return IntReleaseDC(hWnd, hDC);
|
||||
}
|
||||
|
||||
[SecurityCritical]
|
||||
[SuppressUnmanagedCodeSecurity]
|
||||
[DllImport(InteropValues.ExternDll.Gdi32, SetLastError = true, ExactSpelling = true, CharSet = CharSet.Auto)]
|
||||
public static extern int GetDeviceCaps(HandleRef hDC, int nIndex);
|
||||
|
||||
[SecurityCritical]
|
||||
[SuppressUnmanagedCodeSecurity]
|
||||
[DllImport(InteropValues.ExternDll.User32)]
|
||||
public static extern int GetSystemMetrics(InteropValues.SM nIndex);
|
||||
|
||||
[SecurityCritical]
|
||||
[SuppressUnmanagedCodeSecurity]
|
||||
[DllImport(InteropValues.ExternDll.User32, EntryPoint = nameof(DestroyIcon), CharSet = CharSet.Auto, SetLastError = true)]
|
||||
private static extern bool IntDestroyIcon(IntPtr hIcon);
|
||||
|
||||
[SecurityCritical]
|
||||
public static bool DestroyIcon(IntPtr hIcon)
|
||||
{
|
||||
var result = IntDestroyIcon(hIcon);
|
||||
return result;
|
||||
}
|
||||
|
||||
[SecurityCritical]
|
||||
[SuppressUnmanagedCodeSecurity]
|
||||
[DllImport(InteropValues.ExternDll.Gdi32, EntryPoint = nameof(DeleteObject), CharSet = CharSet.Auto, SetLastError = true)]
|
||||
private static extern bool IntDeleteObject(IntPtr hObject);
|
||||
|
||||
[SecurityCritical]
|
||||
public static bool DeleteObject(IntPtr hObject)
|
||||
{
|
||||
var result = IntDeleteObject(hObject);
|
||||
return result;
|
||||
}
|
||||
|
||||
[SecurityCritical]
|
||||
public static BitmapHandle CreateDIBSection(HandleRef hdc, ref InteropValues.BITMAPINFO bitmapInfo, int iUsage,
|
||||
ref IntPtr ppvBits, SafeFileMappingHandle hSection, int dwOffset)
|
||||
{
|
||||
if (hSection == null) hSection = new SafeFileMappingHandle(IntPtr.Zero);
|
||||
|
||||
var hBitmap = PrivateCreateDIBSection(hdc, ref bitmapInfo, iUsage, ref ppvBits, hSection, dwOffset);
|
||||
return hBitmap;
|
||||
}
|
||||
|
||||
[DllImport(InteropValues.ExternDll.Kernel32, EntryPoint = "CloseHandle", CharSet = CharSet.Auto, SetLastError = true)]
|
||||
public static extern bool IntCloseHandle(HandleRef handle);
|
||||
|
||||
[SecurityCritical]
|
||||
[SuppressUnmanagedCodeSecurity]
|
||||
[DllImport(InteropValues.ExternDll.Gdi32, SetLastError = true, ExactSpelling = true, CharSet = CharSet.Auto,
|
||||
EntryPoint = nameof(CreateDIBSection))]
|
||||
private static extern BitmapHandle PrivateCreateDIBSection(HandleRef hdc, ref InteropValues.BITMAPINFO bitmapInfo, int iUsage,
|
||||
ref IntPtr ppvBits, SafeFileMappingHandle hSection, int dwOffset);
|
||||
|
||||
[SecurityCritical]
|
||||
[SuppressUnmanagedCodeSecurity]
|
||||
[DllImport(InteropValues.ExternDll.User32, SetLastError = true, ExactSpelling = true, CharSet = CharSet.Auto,
|
||||
EntryPoint = nameof(CreateIconIndirect))]
|
||||
private static extern IconHandle PrivateCreateIconIndirect([In] [MarshalAs(UnmanagedType.LPStruct)]
|
||||
InteropValues.ICONINFO iconInfo);
|
||||
|
||||
[SecurityCritical]
|
||||
public static IconHandle CreateIconIndirect([In] [MarshalAs(UnmanagedType.LPStruct)]
|
||||
InteropValues.ICONINFO iconInfo)
|
||||
{
|
||||
var hIcon = PrivateCreateIconIndirect(iconInfo);
|
||||
return hIcon;
|
||||
}
|
||||
|
||||
[SecurityCritical]
|
||||
[SuppressUnmanagedCodeSecurity]
|
||||
[DllImport(InteropValues.ExternDll.Gdi32, SetLastError = true, ExactSpelling = true, CharSet = CharSet.Auto,
|
||||
EntryPoint = nameof(CreateBitmap))]
|
||||
private static extern BitmapHandle PrivateCreateBitmap(int width, int height, int planes, int bitsPerPixel,
|
||||
byte[] lpvBits);
|
||||
|
||||
[SecurityCritical]
|
||||
internal static BitmapHandle CreateBitmap(int width, int height, int planes, int bitsPerPixel, byte[] lpvBits)
|
||||
{
|
||||
var hBitmap = PrivateCreateBitmap(width, height, planes, bitsPerPixel, lpvBits);
|
||||
return hBitmap;
|
||||
}
|
||||
|
||||
[SecurityCritical]
|
||||
[SuppressUnmanagedCodeSecurity]
|
||||
[DllImport(InteropValues.ExternDll.Kernel32, EntryPoint = "GetModuleFileName", CharSet = CharSet.Unicode,
|
||||
SetLastError = true)]
|
||||
private static extern int IntGetModuleFileName(HandleRef hModule, StringBuilder buffer, int length);
|
||||
|
||||
[SecurityCritical]
|
||||
internal static string GetModuleFileName(HandleRef hModule)
|
||||
{
|
||||
var buffer = new StringBuilder(InteropValues.Win32Constant.MAX_PATH);
|
||||
while (true)
|
||||
{
|
||||
var size = IntGetModuleFileName(hModule, buffer, buffer.Capacity);
|
||||
if (size == 0) throw new Win32Exception();
|
||||
|
||||
if (size == buffer.Capacity)
|
||||
{
|
||||
buffer.EnsureCapacity(buffer.Capacity * 2);
|
||||
continue;
|
||||
}
|
||||
|
||||
return buffer.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
[SecurityCritical]
|
||||
[SuppressUnmanagedCodeSecurity]
|
||||
[DllImport(InteropValues.ExternDll.Shell32, CharSet = CharSet.Auto, BestFitMapping = false, ThrowOnUnmappableChar = true)]
|
||||
internal static extern int ExtractIconEx(string szExeFileName, int nIconIndex, out IconHandle phiconLarge,
|
||||
out IconHandle phiconSmall, int nIcons);
|
||||
|
||||
[DllImport(InteropValues.ExternDll.Shell32, CharSet = CharSet.Auto)]
|
||||
public static extern int Shell_NotifyIcon(int message, InteropValues.NOTIFYICONDATA pnid);
|
||||
|
||||
[SecurityCritical]
|
||||
[SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
|
||||
[DllImport(InteropValues.ExternDll.User32, SetLastError = true, CharSet = CharSet.Unicode, EntryPoint = "CreateWindowExW")]
|
||||
public static extern IntPtr CreateWindowEx(
|
||||
int dwExStyle,
|
||||
[MarshalAs(UnmanagedType.LPWStr)] string lpClassName,
|
||||
[MarshalAs(UnmanagedType.LPWStr)] string lpWindowName,
|
||||
int dwStyle,
|
||||
int x,
|
||||
int y,
|
||||
int nWidth,
|
||||
int nHeight,
|
||||
IntPtr hWndParent,
|
||||
IntPtr hMenu,
|
||||
IntPtr hInstance,
|
||||
IntPtr lpParam);
|
||||
|
||||
[SecurityCritical]
|
||||
[SuppressUnmanagedCodeSecurity]
|
||||
[DllImport(InteropValues.ExternDll.User32, CharSet = CharSet.Unicode, SetLastError = true, BestFitMapping = false)]
|
||||
public static extern short RegisterClass(InteropValues.WNDCLASS wc);
|
||||
|
||||
[DllImport(InteropValues.ExternDll.User32, CharSet = CharSet.Auto)]
|
||||
public static extern IntPtr DefWindowProc(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam);
|
||||
|
||||
[DllImport(InteropValues.ExternDll.User32, ExactSpelling = true, CharSet = CharSet.Auto)]
|
||||
public static extern bool SetForegroundWindow(IntPtr hWnd);
|
||||
|
||||
[DllImport(InteropValues.ExternDll.User32, CharSet = CharSet.Auto, SetLastError = true)]
|
||||
public static extern IntPtr CallNextHookEx(IntPtr hhk, int nCode, IntPtr wParam, IntPtr lParam);
|
||||
|
||||
[DllImport(InteropValues.ExternDll.Kernel32, CharSet = CharSet.Auto, SetLastError = true)]
|
||||
public static extern IntPtr GetModuleHandle(string lpModuleName);
|
||||
|
||||
[DllImport(InteropValues.ExternDll.User32, CharSet = CharSet.Auto, SetLastError = true)]
|
||||
public static extern bool UnhookWindowsHookEx(IntPtr hhk);
|
||||
|
||||
[DllImport(InteropValues.ExternDll.User32, CharSet = CharSet.Auto, SetLastError = true)]
|
||||
public static extern IntPtr SetWindowsHookEx(int idHook, InteropValues.HookProc lpfn, IntPtr hMod, uint dwThreadId);
|
||||
|
||||
[DllImport(InteropValues.ExternDll.User32, SetLastError = true)]
|
||||
public static extern IntPtr GetWindowDC(IntPtr window);
|
||||
|
||||
[DllImport(InteropValues.ExternDll.Gdi32, SetLastError = true)]
|
||||
public static extern uint GetPixel(IntPtr dc, int x, int y);
|
||||
|
||||
[DllImport(InteropValues.ExternDll.User32, SetLastError = true)]
|
||||
public static extern int ReleaseDC(IntPtr window, IntPtr dc);
|
||||
|
||||
[DllImport(InteropValues.ExternDll.Gdi32, SetLastError = true, ExactSpelling = true, CharSet = CharSet.Auto)]
|
||||
public static extern int GetDeviceCaps(IntPtr hdc, int nIndex);
|
||||
|
||||
[DllImport(InteropValues.ExternDll.User32, CharSet = CharSet.Auto)]
|
||||
public static extern IntPtr GetDC(IntPtr ptr);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,532 @@
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security;
|
||||
|
||||
namespace HandyControl.Tools.Interop
|
||||
{
|
||||
public class InteropValues
|
||||
{
|
||||
#region public
|
||||
|
||||
public delegate IntPtr HookProc(int code, IntPtr wParam, IntPtr lParam);
|
||||
|
||||
public delegate IntPtr WndProc(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam);
|
||||
|
||||
public const int
|
||||
WS_CHILD = 0x40000000,
|
||||
BITSPIXEL = 12,
|
||||
PLANES = 14,
|
||||
BI_RGB = 0,
|
||||
DIB_RGB_COLORS = 0,
|
||||
NIF_MESSAGE = 0x00000001,
|
||||
NIF_ICON = 0x00000002,
|
||||
NIF_TIP = 0x00000004,
|
||||
NIF_INFO = 0x00000010,
|
||||
NIN_BALLOONSHOW = WM_USER + 2,
|
||||
NIN_BALLOONHIDE = WM_USER + 3,
|
||||
NIN_BALLOONTIMEOUT = WM_USER + 4,
|
||||
NIM_ADD = 0x00000000,
|
||||
NIM_MODIFY = 0x00000001,
|
||||
NIM_DELETE = 0x00000002,
|
||||
NIIF_NONE = 0x00000000,
|
||||
NIIF_INFO = 0x00000001,
|
||||
NIIF_WARNING = 0x00000002,
|
||||
NIIF_ERROR = 0x00000003,
|
||||
NIIF_LARGE_ICON = 0x00000020,
|
||||
WM_KEYDOWN = 0x0100,
|
||||
WM_KEYUP = 0x0101,
|
||||
WM_SYSKEYDOWN = 0x0104,
|
||||
WM_SYSKEYUP = 0x0105,
|
||||
WM_SYSCOMMAND = 0x112,
|
||||
WM_MOUSEMOVE = 0x0200,
|
||||
WM_LBUTTONDOWN = 0x0201,
|
||||
WM_LBUTTONUP = 0x0202,
|
||||
WM_LBUTTONDBLCLK = 0x0203,
|
||||
WM_RBUTTONDOWN = 0x0204,
|
||||
WM_RBUTTONUP = 0x0205,
|
||||
WM_RBUTTONDBLCLK = 0x0206,
|
||||
WM_MBUTTONDOWN = 0x0207,
|
||||
WM_MBUTTONUP = 0x0208,
|
||||
WM_MBUTTONDBLCLK = 0x0209,
|
||||
WM_CLIPBOARDUPDATE = 0x031D,
|
||||
WM_USER = 0x0400,
|
||||
MF_BYPOSITION = 0x400,
|
||||
MF_SEPARATOR = 0x800,
|
||||
TB_GETBUTTON = WM_USER + 23,
|
||||
TB_BUTTONCOUNT = WM_USER + 24,
|
||||
TB_GETITEMRECT = WM_USER + 29,
|
||||
STANDARD_RIGHTS_REQUIRED = 0x000F0000,
|
||||
SYNCHRONIZE = 0x00100000,
|
||||
PROCESS_ALL_ACCESS = STANDARD_RIGHTS_REQUIRED | SYNCHRONIZE | 0xFFF,
|
||||
MEM_COMMIT = 0x1000,
|
||||
MEM_RELEASE = 0x8000,
|
||||
PAGE_READWRITE = 0x04,
|
||||
TBSTATE_HIDDEN = 0x08,
|
||||
VERTRES = 10,
|
||||
HORZRES = 8,
|
||||
DESKTOPVERTRES = 117,
|
||||
DESKTOPHORZRES = 118,
|
||||
LOGPIXELSX = 88,
|
||||
LOGPIXELSY = 90,
|
||||
CXFRAME = 32,
|
||||
CXSIZEFRAME = CXFRAME,
|
||||
SW_HIDE = 0;
|
||||
|
||||
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
|
||||
public class NOTIFYICONDATA
|
||||
{
|
||||
public int cbSize = Marshal.SizeOf(typeof(NOTIFYICONDATA));
|
||||
public IntPtr hWnd;
|
||||
public int uID;
|
||||
public int uFlags;
|
||||
public int uCallbackMessage;
|
||||
public IntPtr hIcon;
|
||||
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)]
|
||||
public string szTip = string.Empty;
|
||||
public int dwState = 0x01;
|
||||
public int dwStateMask = 0x01;
|
||||
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)]
|
||||
public string szInfo = string.Empty;
|
||||
public int uTimeoutOrVersion;
|
||||
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 64)]
|
||||
public string szInfoTitle = string.Empty;
|
||||
public int dwInfoFlags;
|
||||
}
|
||||
|
||||
[Flags]
|
||||
public enum ProcessAccess
|
||||
{
|
||||
AllAccess = CreateThread | DuplicateHandle | QueryInformation | SetInformation | Terminate | VMOperation | VMRead | VMWrite | Synchronize,
|
||||
CreateThread = 0x2,
|
||||
DuplicateHandle = 0x40,
|
||||
QueryInformation = 0x400,
|
||||
SetInformation = 0x200,
|
||||
Terminate = 0x1,
|
||||
VMOperation = 0x8,
|
||||
VMRead = 0x10,
|
||||
VMWrite = 0x20,
|
||||
Synchronize = 0x100000
|
||||
}
|
||||
|
||||
[Serializable, StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
|
||||
public struct RECT
|
||||
{
|
||||
public int Left;
|
||||
public int Top;
|
||||
public int Right;
|
||||
public int Bottom;
|
||||
|
||||
public RECT(int left, int top, int right, int bottom)
|
||||
{
|
||||
Left = left;
|
||||
Top = top;
|
||||
Right = right;
|
||||
Bottom = bottom;
|
||||
}
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
||||
public struct TBBUTTON
|
||||
{
|
||||
public int iBitmap;
|
||||
public int idCommand;
|
||||
public IntPtr fsStateStylePadding;
|
||||
public IntPtr dwData;
|
||||
public IntPtr iString;
|
||||
}
|
||||
|
||||
[Flags]
|
||||
public enum AllocationType
|
||||
{
|
||||
Commit = 0x1000,
|
||||
Reserve = 0x2000,
|
||||
Decommit = 0x4000,
|
||||
Release = 0x8000,
|
||||
Reset = 0x80000,
|
||||
Physical = 0x400000,
|
||||
TopDown = 0x100000,
|
||||
WriteWatch = 0x200000,
|
||||
LargePages = 0x20000000
|
||||
}
|
||||
|
||||
[Flags]
|
||||
public enum MemoryProtection
|
||||
{
|
||||
Execute = 0x10,
|
||||
ExecuteRead = 0x20,
|
||||
ExecuteReadWrite = 0x40,
|
||||
ExecuteWriteCopy = 0x80,
|
||||
NoAccess = 0x01,
|
||||
ReadOnly = 0x02,
|
||||
ReadWrite = 0x04,
|
||||
WriteCopy = 0x08,
|
||||
GuardModifierflag = 0x100,
|
||||
NoCacheModifierflag = 0x200,
|
||||
WriteCombineModifierflag = 0x400
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct TRAYDATA
|
||||
{
|
||||
public IntPtr hwnd;
|
||||
public uint uID;
|
||||
public uint uCallbackMessage;
|
||||
public uint bReserved0;
|
||||
public uint bReserved1;
|
||||
public IntPtr hIcon;
|
||||
}
|
||||
|
||||
[Flags]
|
||||
public enum FreeType
|
||||
{
|
||||
Decommit = 0x4000,
|
||||
Release = 0x8000,
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct POINT
|
||||
{
|
||||
public int X;
|
||||
public int Y;
|
||||
|
||||
public POINT(int x, int y)
|
||||
{
|
||||
X = x;
|
||||
Y = y;
|
||||
}
|
||||
}
|
||||
|
||||
public enum HookType
|
||||
{
|
||||
WH_KEYBOARD_LL = 13,
|
||||
WH_MOUSE_LL = 14
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct MOUSEHOOKSTRUCT
|
||||
{
|
||||
public POINT pt;
|
||||
public IntPtr hwnd;
|
||||
public uint wHitTestCode;
|
||||
public IntPtr dwExtraInfo;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region internal
|
||||
|
||||
internal static class ExternDll
|
||||
{
|
||||
public const string
|
||||
User32 = "user32.dll",
|
||||
Gdi32 = "gdi32.dll",
|
||||
Kernel32 = "kernel32.dll",
|
||||
Shell32 = "shell32.dll";
|
||||
}
|
||||
|
||||
internal enum SM
|
||||
{
|
||||
CXSCREEN = 0,
|
||||
CYSCREEN = 1,
|
||||
CXVSCROLL = 2,
|
||||
CYHSCROLL = 3,
|
||||
CYCAPTION = 4,
|
||||
CXBORDER = 5,
|
||||
CYBORDER = 6,
|
||||
CXFIXEDFRAME = 7,
|
||||
CYFIXEDFRAME = 8,
|
||||
CYVTHUMB = 9,
|
||||
CXHTHUMB = 10,
|
||||
CXICON = 11,
|
||||
CYICON = 12,
|
||||
CXCURSOR = 13,
|
||||
CYCURSOR = 14,
|
||||
CYMENU = 15,
|
||||
CXFULLSCREEN = 16,
|
||||
CYFULLSCREEN = 17,
|
||||
CYKANJIWINDOW = 18,
|
||||
MOUSEPRESENT = 19,
|
||||
CYVSCROLL = 20,
|
||||
CXHSCROLL = 21,
|
||||
DEBUG = 22,
|
||||
SWAPBUTTON = 23,
|
||||
CXMIN = 28,
|
||||
CYMIN = 29,
|
||||
CXSIZE = 30,
|
||||
CYSIZE = 31,
|
||||
CXFRAME = 32,
|
||||
CXSIZEFRAME = CXFRAME,
|
||||
CYFRAME = 33,
|
||||
CYSIZEFRAME = CYFRAME,
|
||||
CXMINTRACK = 34,
|
||||
CYMINTRACK = 35,
|
||||
CXDOUBLECLK = 36,
|
||||
CYDOUBLECLK = 37,
|
||||
CXICONSPACING = 38,
|
||||
CYICONSPACING = 39,
|
||||
MENUDROPALIGNMENT = 40,
|
||||
PENWINDOWS = 41,
|
||||
DBCSENABLED = 42,
|
||||
CMOUSEBUTTONS = 43,
|
||||
SECURE = 44,
|
||||
CXEDGE = 45,
|
||||
CYEDGE = 46,
|
||||
CXMINSPACING = 47,
|
||||
CYMINSPACING = 48,
|
||||
CXSMICON = 49,
|
||||
CYSMICON = 50,
|
||||
CYSMCAPTION = 51,
|
||||
CXSMSIZE = 52,
|
||||
CYSMSIZE = 53,
|
||||
CXMENUSIZE = 54,
|
||||
CYMENUSIZE = 55,
|
||||
ARRANGE = 56,
|
||||
CXMINIMIZED = 57,
|
||||
CYMINIMIZED = 58,
|
||||
CXMAXTRACK = 59,
|
||||
CYMAXTRACK = 60,
|
||||
CXMAXIMIZED = 61,
|
||||
CYMAXIMIZED = 62,
|
||||
NETWORK = 63,
|
||||
CLEANBOOT = 67,
|
||||
CXDRAG = 68,
|
||||
CYDRAG = 69,
|
||||
SHOWSOUNDS = 70,
|
||||
CXMENUCHECK = 71,
|
||||
CYMENUCHECK = 72,
|
||||
SLOWMACHINE = 73,
|
||||
MIDEASTENABLED = 74,
|
||||
MOUSEWHEELPRESENT = 75,
|
||||
XVIRTUALSCREEN = 76,
|
||||
YVIRTUALSCREEN = 77,
|
||||
CXVIRTUALSCREEN = 78,
|
||||
CYVIRTUALSCREEN = 79,
|
||||
CMONITORS = 80,
|
||||
SAMEDISPLAYFORMAT = 81,
|
||||
IMMENABLED = 82,
|
||||
CXFOCUSBORDER = 83,
|
||||
CYFOCUSBORDER = 84,
|
||||
TABLETPC = 86,
|
||||
MEDIACENTER = 87,
|
||||
REMOTESESSION = 0x1000,
|
||||
REMOTECONTROL = 0x2001
|
||||
}
|
||||
|
||||
internal enum CacheSlot
|
||||
{
|
||||
DpiX,
|
||||
|
||||
FocusBorderWidth,
|
||||
FocusBorderHeight,
|
||||
HighContrast,
|
||||
MouseVanish,
|
||||
|
||||
DropShadow,
|
||||
FlatMenu,
|
||||
WorkAreaInternal,
|
||||
WorkArea,
|
||||
|
||||
IconMetrics,
|
||||
|
||||
KeyboardCues,
|
||||
KeyboardDelay,
|
||||
KeyboardPreference,
|
||||
KeyboardSpeed,
|
||||
SnapToDefaultButton,
|
||||
WheelScrollLines,
|
||||
MouseHoverTime,
|
||||
MouseHoverHeight,
|
||||
MouseHoverWidth,
|
||||
|
||||
MenuDropAlignment,
|
||||
MenuFade,
|
||||
MenuShowDelay,
|
||||
|
||||
ComboBoxAnimation,
|
||||
ClientAreaAnimation,
|
||||
CursorShadow,
|
||||
GradientCaptions,
|
||||
HotTracking,
|
||||
ListBoxSmoothScrolling,
|
||||
MenuAnimation,
|
||||
SelectionFade,
|
||||
StylusHotTracking,
|
||||
ToolTipAnimation,
|
||||
ToolTipFade,
|
||||
UIEffects,
|
||||
|
||||
MinimizeAnimation,
|
||||
Border,
|
||||
CaretWidth,
|
||||
ForegroundFlashCount,
|
||||
DragFullWindows,
|
||||
NonClientMetrics,
|
||||
|
||||
ThinHorizontalBorderHeight,
|
||||
ThinVerticalBorderWidth,
|
||||
CursorWidth,
|
||||
CursorHeight,
|
||||
ThickHorizontalBorderHeight,
|
||||
ThickVerticalBorderWidth,
|
||||
MinimumHorizontalDragDistance,
|
||||
MinimumVerticalDragDistance,
|
||||
FixedFrameHorizontalBorderHeight,
|
||||
FixedFrameVerticalBorderWidth,
|
||||
FocusHorizontalBorderHeight,
|
||||
FocusVerticalBorderWidth,
|
||||
FullPrimaryScreenWidth,
|
||||
FullPrimaryScreenHeight,
|
||||
HorizontalScrollBarButtonWidth,
|
||||
HorizontalScrollBarHeight,
|
||||
HorizontalScrollBarThumbWidth,
|
||||
IconWidth,
|
||||
IconHeight,
|
||||
IconGridWidth,
|
||||
IconGridHeight,
|
||||
MaximizedPrimaryScreenWidth,
|
||||
MaximizedPrimaryScreenHeight,
|
||||
MaximumWindowTrackWidth,
|
||||
MaximumWindowTrackHeight,
|
||||
MenuCheckmarkWidth,
|
||||
MenuCheckmarkHeight,
|
||||
MenuButtonWidth,
|
||||
MenuButtonHeight,
|
||||
MinimumWindowWidth,
|
||||
MinimumWindowHeight,
|
||||
MinimizedWindowWidth,
|
||||
MinimizedWindowHeight,
|
||||
MinimizedGridWidth,
|
||||
MinimizedGridHeight,
|
||||
MinimumWindowTrackWidth,
|
||||
MinimumWindowTrackHeight,
|
||||
PrimaryScreenWidth,
|
||||
PrimaryScreenHeight,
|
||||
WindowCaptionButtonWidth,
|
||||
WindowCaptionButtonHeight,
|
||||
ResizeFrameHorizontalBorderHeight,
|
||||
ResizeFrameVerticalBorderWidth,
|
||||
SmallIconWidth,
|
||||
SmallIconHeight,
|
||||
SmallWindowCaptionButtonWidth,
|
||||
SmallWindowCaptionButtonHeight,
|
||||
VirtualScreenWidth,
|
||||
VirtualScreenHeight,
|
||||
VerticalScrollBarWidth,
|
||||
VerticalScrollBarButtonHeight,
|
||||
WindowCaptionHeight,
|
||||
KanjiWindowHeight,
|
||||
MenuBarHeight,
|
||||
VerticalScrollBarThumbHeight,
|
||||
IsImmEnabled,
|
||||
IsMediaCenter,
|
||||
IsMenuDropRightAligned,
|
||||
IsMiddleEastEnabled,
|
||||
IsMousePresent,
|
||||
IsMouseWheelPresent,
|
||||
IsPenWindows,
|
||||
IsRemotelyControlled,
|
||||
IsRemoteSession,
|
||||
ShowSounds,
|
||||
IsSlowMachine,
|
||||
SwapButtons,
|
||||
IsTabletPC,
|
||||
VirtualScreenLeft,
|
||||
VirtualScreenTop,
|
||||
|
||||
PowerLineStatus,
|
||||
|
||||
IsGlassEnabled,
|
||||
UxThemeName,
|
||||
UxThemeColor,
|
||||
WindowCornerRadius,
|
||||
WindowGlassColor,
|
||||
WindowGlassBrush,
|
||||
WindowNonClientFrameThickness,
|
||||
WindowResizeBorderThickness,
|
||||
|
||||
NumSlots
|
||||
}
|
||||
|
||||
internal static class Win32Constant
|
||||
{
|
||||
internal const int MAX_PATH = 260;
|
||||
internal const int INFOTIPSIZE = 1024;
|
||||
internal const int TRUE = 1;
|
||||
internal const int FALSE = 0;
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
|
||||
internal class WNDCLASS
|
||||
{
|
||||
public int style;
|
||||
public WndProc lpfnWndProc;
|
||||
public int cbClsExtra;
|
||||
public int cbWndExtra;
|
||||
public IntPtr hInstance;
|
||||
public IntPtr hIcon;
|
||||
public IntPtr hCursor;
|
||||
public IntPtr hbrBackground;
|
||||
public string lpszMenuName;
|
||||
public string lpszClassName;
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential, Pack = 2)]
|
||||
internal struct BITMAPINFO
|
||||
{
|
||||
public int bmiHeader_biSize;
|
||||
|
||||
public int bmiHeader_biWidth;
|
||||
|
||||
public int bmiHeader_biHeight;
|
||||
|
||||
public short bmiHeader_biPlanes;
|
||||
|
||||
public short bmiHeader_biBitCount;
|
||||
|
||||
public int bmiHeader_biCompression;
|
||||
|
||||
public int bmiHeader_biSizeImage;
|
||||
|
||||
public int bmiHeader_biXPelsPerMeter;
|
||||
|
||||
public int bmiHeader_biYPelsPerMeter;
|
||||
|
||||
public int bmiHeader_biClrUsed;
|
||||
|
||||
public int bmiHeader_biClrImportant;
|
||||
|
||||
public BITMAPINFO(int width, int height, short bpp)
|
||||
{
|
||||
bmiHeader_biSize = SizeOf();
|
||||
bmiHeader_biWidth = width;
|
||||
bmiHeader_biHeight = height;
|
||||
bmiHeader_biPlanes = 1;
|
||||
bmiHeader_biBitCount = bpp;
|
||||
bmiHeader_biCompression = 0;
|
||||
bmiHeader_biSizeImage = 0;
|
||||
bmiHeader_biXPelsPerMeter = 0;
|
||||
bmiHeader_biYPelsPerMeter = 0;
|
||||
bmiHeader_biClrUsed = 0;
|
||||
bmiHeader_biClrImportant = 0;
|
||||
}
|
||||
|
||||
[SecuritySafeCritical]
|
||||
private static int SizeOf()
|
||||
{
|
||||
return Marshal.SizeOf(typeof(BITMAPINFO));
|
||||
}
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal class ICONINFO
|
||||
{
|
||||
public bool fIcon = false;
|
||||
public int xHotspot = 0;
|
||||
public int yHotspot = 0;
|
||||
public BitmapHandle hbmMask = null;
|
||||
public BitmapHandle hbmColor = null;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace HandyControl.Tools.Interop
|
||||
{
|
||||
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
|
||||
[SuppressMessage("ReSharper", "InconsistentNaming")]
|
||||
public class NOTIFYICONDATA
|
||||
{
|
||||
public int cbSize = Marshal.SizeOf(typeof(NOTIFYICONDATA));
|
||||
public IntPtr hWnd;
|
||||
public int uID;
|
||||
public int uFlags;
|
||||
public int uCallbackMessage;
|
||||
public IntPtr hIcon;
|
||||
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)]
|
||||
public string szTip = string.Empty;
|
||||
public int dwState = 0x01;
|
||||
public int dwStateMask = 0x01;
|
||||
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)]
|
||||
public string szInfo = string.Empty;
|
||||
public int uTimeoutOrVersion;
|
||||
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 64)]
|
||||
public string szInfoTitle = string.Empty;
|
||||
public int dwInfoFlags;
|
||||
}
|
||||
}
|
||||
@@ -1,246 +0,0 @@
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Runtime.Versioning;
|
||||
using System.Security;
|
||||
|
||||
namespace HandyControl.Tools.Interop
|
||||
{
|
||||
public delegate IntPtr WndProc(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam);
|
||||
|
||||
[SuppressMessage("ReSharper", "InconsistentNaming")]
|
||||
[SuppressMessage("ReSharper", "IdentifierTypo")]
|
||||
internal class NativeMethods
|
||||
{
|
||||
public const int
|
||||
WS_CHILD = 0x40000000,
|
||||
BITSPIXEL = 12,
|
||||
PLANES = 14,
|
||||
BI_RGB = 0,
|
||||
DIB_RGB_COLORS = 0,
|
||||
NIF_MESSAGE = 0x00000001,
|
||||
NIF_ICON = 0x00000002,
|
||||
NIF_TIP = 0x00000004,
|
||||
NIF_INFO = 0x00000010,
|
||||
NIN_BALLOONSHOW = WM_USER + 2,
|
||||
NIN_BALLOONHIDE = WM_USER + 3,
|
||||
NIN_BALLOONTIMEOUT = WM_USER + 4,
|
||||
NIM_ADD = 0x00000000,
|
||||
NIM_MODIFY = 0x00000001,
|
||||
NIM_DELETE = 0x00000002,
|
||||
NIIF_NONE = 0x00000000,
|
||||
NIIF_INFO = 0x00000001,
|
||||
NIIF_WARNING = 0x00000002,
|
||||
NIIF_ERROR = 0x00000003,
|
||||
NIIF_LARGE_ICON = 0x00000020,
|
||||
WM_KEYDOWN = 0x0100,
|
||||
WM_KEYUP = 0x0101,
|
||||
WM_SYSKEYDOWN = 0x0104,
|
||||
WM_SYSKEYUP = 0x0105,
|
||||
WM_SYSCOMMAND = 0x112,
|
||||
WM_MOUSEMOVE = 0x0200,
|
||||
WM_LBUTTONDOWN = 0x0201,
|
||||
WM_LBUTTONUP = 0x0202,
|
||||
WM_LBUTTONDBLCLK = 0x0203,
|
||||
WM_RBUTTONDOWN = 0x0204,
|
||||
WM_RBUTTONUP = 0x0205,
|
||||
WM_RBUTTONDBLCLK = 0x0206,
|
||||
WM_MBUTTONDOWN = 0x0207,
|
||||
WM_MBUTTONUP = 0x0208,
|
||||
WM_MBUTTONDBLCLK = 0x0209,
|
||||
WM_CLIPBOARDUPDATE = 0x031D,
|
||||
WM_USER = 0x0400,
|
||||
MF_BYPOSITION = 0x400,
|
||||
MF_SEPARATOR = 0x800,
|
||||
TB_GETBUTTON = WM_USER + 23,
|
||||
TB_BUTTONCOUNT = WM_USER + 24,
|
||||
TB_GETITEMRECT = WM_USER + 29,
|
||||
STANDARD_RIGHTS_REQUIRED = 0x000F0000,
|
||||
SYNCHRONIZE = 0x00100000,
|
||||
PROCESS_ALL_ACCESS = STANDARD_RIGHTS_REQUIRED | SYNCHRONIZE | 0xFFF,
|
||||
MEM_COMMIT = 0x1000,
|
||||
MEM_RELEASE = 0x8000,
|
||||
PAGE_READWRITE = 0x04,
|
||||
TBSTATE_HIDDEN = 0x08,
|
||||
VERTRES = 10,
|
||||
HORZRES = 8,
|
||||
DESKTOPVERTRES = 117,
|
||||
DESKTOPHORZRES = 118,
|
||||
LOGPIXELSX = 88,
|
||||
LOGPIXELSY = 90,
|
||||
CXFRAME = 32,
|
||||
CXSIZEFRAME = CXFRAME,
|
||||
SW_HIDE = 0;
|
||||
|
||||
[Flags]
|
||||
public enum ProcessAccess
|
||||
{
|
||||
AllAccess = CreateThread | DuplicateHandle | QueryInformation | SetInformation | Terminate | VMOperation | VMRead | VMWrite | Synchronize,
|
||||
CreateThread = 0x2,
|
||||
DuplicateHandle = 0x40,
|
||||
QueryInformation = 0x400,
|
||||
SetInformation = 0x200,
|
||||
Terminate = 0x1,
|
||||
VMOperation = 0x8,
|
||||
VMRead = 0x10,
|
||||
VMWrite = 0x20,
|
||||
Synchronize = 0x100000
|
||||
}
|
||||
|
||||
[Serializable, StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
|
||||
public struct RECT
|
||||
{
|
||||
public int Left;
|
||||
public int Top;
|
||||
public int Right;
|
||||
public int Bottom;
|
||||
|
||||
public RECT(int left, int top, int right, int bottom)
|
||||
{
|
||||
Left = left;
|
||||
Top = top;
|
||||
Right = right;
|
||||
Bottom = bottom;
|
||||
}
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
||||
public struct TBBUTTON
|
||||
{
|
||||
public int iBitmap;
|
||||
public int idCommand;
|
||||
public IntPtr fsStateStylePadding;
|
||||
public IntPtr dwData;
|
||||
public IntPtr iString;
|
||||
}
|
||||
|
||||
[Flags]
|
||||
public enum AllocationType
|
||||
{
|
||||
Commit = 0x1000,
|
||||
Reserve = 0x2000,
|
||||
Decommit = 0x4000,
|
||||
Release = 0x8000,
|
||||
Reset = 0x80000,
|
||||
Physical = 0x400000,
|
||||
TopDown = 0x100000,
|
||||
WriteWatch = 0x200000,
|
||||
LargePages = 0x20000000
|
||||
}
|
||||
|
||||
[Flags]
|
||||
public enum MemoryProtection
|
||||
{
|
||||
Execute = 0x10,
|
||||
ExecuteRead = 0x20,
|
||||
ExecuteReadWrite = 0x40,
|
||||
ExecuteWriteCopy = 0x80,
|
||||
NoAccess = 0x01,
|
||||
ReadOnly = 0x02,
|
||||
ReadWrite = 0x04,
|
||||
WriteCopy = 0x08,
|
||||
GuardModifierflag = 0x100,
|
||||
NoCacheModifierflag = 0x200,
|
||||
WriteCombineModifierflag = 0x400
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct TRAYDATA
|
||||
{
|
||||
public IntPtr hwnd;
|
||||
public uint uID;
|
||||
public uint uCallbackMessage;
|
||||
public uint bReserved0;
|
||||
public uint bReserved1;
|
||||
public IntPtr hIcon;
|
||||
}
|
||||
|
||||
[Flags]
|
||||
public enum FreeType
|
||||
{
|
||||
Decommit = 0x4000,
|
||||
Release = 0x8000,
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct POINT
|
||||
{
|
||||
public int X;
|
||||
public int Y;
|
||||
|
||||
public POINT(int x, int y)
|
||||
{
|
||||
X = x;
|
||||
Y = y;
|
||||
}
|
||||
}
|
||||
|
||||
[DllImport(ExternDll.User32, CharSet = CharSet.Auto)]
|
||||
[ResourceExposure(ResourceScope.None)]
|
||||
public static extern int RegisterWindowMessage(string msg);
|
||||
|
||||
[DllImport(ExternDll.User32, SetLastError = true, CharSet = CharSet.Auto)]
|
||||
public static extern int MapWindowPoints(IntPtr hWndFrom, IntPtr hWndTo, ref RECT lpPoints, uint cPoints);
|
||||
|
||||
[DllImport(ExternDll.Kernel32, SetLastError = true, CharSet = CharSet.Auto)]
|
||||
public static extern bool ReadProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, out TBBUTTON lpBuffer, int dwSize, out int lpNumberOfBytesRead);
|
||||
|
||||
[DllImport(ExternDll.Kernel32, SetLastError = true)]
|
||||
public static extern bool ReadProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, out RECT lpBuffer, int dwSize, out int lpNumberOfBytesRead);
|
||||
|
||||
[DllImport(ExternDll.Kernel32, SetLastError = true)]
|
||||
public static extern bool ReadProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, out TRAYDATA lpBuffer, int dwSize, out int lpNumberOfBytesRead);
|
||||
|
||||
[DllImport(ExternDll.User32, CharSet = CharSet.Auto)]
|
||||
public static extern uint SendMessage(IntPtr hWnd, uint Msg, uint wParam, IntPtr lParam);
|
||||
|
||||
[DllImport(ExternDll.User32, SetLastError = true, CharSet = CharSet.Auto)]
|
||||
public static extern uint GetWindowThreadProcessId(IntPtr hWnd, out uint lpdwProcessId);
|
||||
|
||||
[DllImport(ExternDll.Kernel32, SetLastError = true, CharSet = CharSet.Auto)]
|
||||
public static extern IntPtr OpenProcess(ProcessAccess dwDesiredAccess, [MarshalAs(UnmanagedType.Bool)] bool bInheritHandle, uint dwProcessId);
|
||||
|
||||
[DllImport(ExternDll.Kernel32, SetLastError = true, CharSet = CharSet.Auto)]
|
||||
public static extern IntPtr VirtualAllocEx(IntPtr hProcess, IntPtr lpAddress, int dwSize, AllocationType flAllocationType, MemoryProtection flProtect);
|
||||
|
||||
[DllImport(ExternDll.Kernel32, SetLastError = true, CharSet = CharSet.Auto)]
|
||||
public static extern int CloseHandle(IntPtr hObject);
|
||||
|
||||
[DllImport(ExternDll.Kernel32, SetLastError = true, CharSet = CharSet.Auto)]
|
||||
public static extern bool VirtualFreeEx(IntPtr hProcess, IntPtr lpAddress, int dwSize, FreeType dwFreeType);
|
||||
|
||||
[DllImport(ExternDll.User32, SetLastError = true)]
|
||||
public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
|
||||
|
||||
[DllImport(ExternDll.User32, SetLastError = true)]
|
||||
public static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);
|
||||
|
||||
[DllImport(ExternDll.User32)]
|
||||
public static extern int GetWindowRect(IntPtr hwnd, out RECT lpRect);
|
||||
|
||||
[DllImport(ExternDll.User32, CharSet = CharSet.Auto)]
|
||||
public static extern bool GetCursorPos(out POINT pt);
|
||||
|
||||
[SecurityCritical]
|
||||
[SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
|
||||
[DllImport(ExternDll.User32)]
|
||||
public static extern int GetSystemMetrics(SM nIndex);
|
||||
|
||||
[DllImport(ExternDll.User32)]
|
||||
public static extern IntPtr GetDesktopWindow();
|
||||
|
||||
[DllImport(ExternDll.User32, SetLastError = true)]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
public static extern bool AddClipboardFormatListener(IntPtr hwnd);
|
||||
|
||||
[DllImport(ExternDll.User32, SetLastError = true)]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
public static extern bool RemoveClipboardFormatListener(IntPtr hwnd);
|
||||
|
||||
[DllImport(ExternDll.User32)]
|
||||
public static extern IntPtr GetSystemMenu(IntPtr hWnd, bool bRevert);
|
||||
|
||||
[DllImport(ExternDll.User32)]
|
||||
public static extern bool InsertMenu(IntPtr hMenu, int wPosition, int wFlags, int wIDNewItem, string lpNewItem);
|
||||
}
|
||||
}
|
||||
@@ -1,235 +0,0 @@
|
||||
// ReSharper disable InconsistentNaming
|
||||
|
||||
namespace HandyControl.Tools.Interop
|
||||
{
|
||||
internal enum SM
|
||||
{
|
||||
CXSCREEN = 0,
|
||||
CYSCREEN = 1,
|
||||
CXVSCROLL = 2,
|
||||
CYHSCROLL = 3,
|
||||
CYCAPTION = 4,
|
||||
CXBORDER = 5,
|
||||
CYBORDER = 6,
|
||||
CXFIXEDFRAME = 7,
|
||||
CYFIXEDFRAME = 8,
|
||||
CYVTHUMB = 9,
|
||||
CXHTHUMB = 10,
|
||||
CXICON = 11,
|
||||
CYICON = 12,
|
||||
CXCURSOR = 13,
|
||||
CYCURSOR = 14,
|
||||
CYMENU = 15,
|
||||
CXFULLSCREEN = 16,
|
||||
CYFULLSCREEN = 17,
|
||||
CYKANJIWINDOW = 18,
|
||||
MOUSEPRESENT = 19,
|
||||
CYVSCROLL = 20,
|
||||
CXHSCROLL = 21,
|
||||
DEBUG = 22,
|
||||
SWAPBUTTON = 23,
|
||||
CXMIN = 28,
|
||||
CYMIN = 29,
|
||||
CXSIZE = 30,
|
||||
CYSIZE = 31,
|
||||
CXFRAME = 32,
|
||||
CXSIZEFRAME = CXFRAME,
|
||||
CYFRAME = 33,
|
||||
CYSIZEFRAME = CYFRAME,
|
||||
CXMINTRACK = 34,
|
||||
CYMINTRACK = 35,
|
||||
CXDOUBLECLK = 36,
|
||||
CYDOUBLECLK = 37,
|
||||
CXICONSPACING = 38,
|
||||
CYICONSPACING = 39,
|
||||
MENUDROPALIGNMENT = 40,
|
||||
PENWINDOWS = 41,
|
||||
DBCSENABLED = 42,
|
||||
CMOUSEBUTTONS = 43,
|
||||
SECURE = 44,
|
||||
CXEDGE = 45,
|
||||
CYEDGE = 46,
|
||||
CXMINSPACING = 47,
|
||||
CYMINSPACING = 48,
|
||||
CXSMICON = 49,
|
||||
CYSMICON = 50,
|
||||
CYSMCAPTION = 51,
|
||||
CXSMSIZE = 52,
|
||||
CYSMSIZE = 53,
|
||||
CXMENUSIZE = 54,
|
||||
CYMENUSIZE = 55,
|
||||
ARRANGE = 56,
|
||||
CXMINIMIZED = 57,
|
||||
CYMINIMIZED = 58,
|
||||
CXMAXTRACK = 59,
|
||||
CYMAXTRACK = 60,
|
||||
CXMAXIMIZED = 61,
|
||||
CYMAXIMIZED = 62,
|
||||
NETWORK = 63,
|
||||
CLEANBOOT = 67,
|
||||
CXDRAG = 68,
|
||||
CYDRAG = 69,
|
||||
SHOWSOUNDS = 70,
|
||||
CXMENUCHECK = 71,
|
||||
CYMENUCHECK = 72,
|
||||
SLOWMACHINE = 73,
|
||||
MIDEASTENABLED = 74,
|
||||
MOUSEWHEELPRESENT = 75,
|
||||
XVIRTUALSCREEN = 76,
|
||||
YVIRTUALSCREEN = 77,
|
||||
CXVIRTUALSCREEN = 78,
|
||||
CYVIRTUALSCREEN = 79,
|
||||
CMONITORS = 80,
|
||||
SAMEDISPLAYFORMAT = 81,
|
||||
IMMENABLED = 82,
|
||||
CXFOCUSBORDER = 83,
|
||||
CYFOCUSBORDER = 84,
|
||||
TABLETPC = 86,
|
||||
MEDIACENTER = 87,
|
||||
REMOTESESSION = 0x1000,
|
||||
REMOTECONTROL = 0x2001
|
||||
}
|
||||
|
||||
internal enum CacheSlot
|
||||
{
|
||||
DpiX,
|
||||
|
||||
FocusBorderWidth,
|
||||
FocusBorderHeight,
|
||||
HighContrast,
|
||||
MouseVanish,
|
||||
|
||||
DropShadow,
|
||||
FlatMenu,
|
||||
WorkAreaInternal,
|
||||
WorkArea,
|
||||
|
||||
IconMetrics,
|
||||
|
||||
KeyboardCues,
|
||||
KeyboardDelay,
|
||||
KeyboardPreference,
|
||||
KeyboardSpeed,
|
||||
SnapToDefaultButton,
|
||||
WheelScrollLines,
|
||||
MouseHoverTime,
|
||||
MouseHoverHeight,
|
||||
MouseHoverWidth,
|
||||
|
||||
MenuDropAlignment,
|
||||
MenuFade,
|
||||
MenuShowDelay,
|
||||
|
||||
ComboBoxAnimation,
|
||||
ClientAreaAnimation,
|
||||
CursorShadow,
|
||||
GradientCaptions,
|
||||
HotTracking,
|
||||
ListBoxSmoothScrolling,
|
||||
MenuAnimation,
|
||||
SelectionFade,
|
||||
StylusHotTracking,
|
||||
ToolTipAnimation,
|
||||
ToolTipFade,
|
||||
UIEffects,
|
||||
|
||||
MinimizeAnimation,
|
||||
Border,
|
||||
CaretWidth,
|
||||
ForegroundFlashCount,
|
||||
DragFullWindows,
|
||||
NonClientMetrics,
|
||||
|
||||
ThinHorizontalBorderHeight,
|
||||
ThinVerticalBorderWidth,
|
||||
CursorWidth,
|
||||
CursorHeight,
|
||||
ThickHorizontalBorderHeight,
|
||||
ThickVerticalBorderWidth,
|
||||
MinimumHorizontalDragDistance,
|
||||
MinimumVerticalDragDistance,
|
||||
FixedFrameHorizontalBorderHeight,
|
||||
FixedFrameVerticalBorderWidth,
|
||||
FocusHorizontalBorderHeight,
|
||||
FocusVerticalBorderWidth,
|
||||
FullPrimaryScreenWidth,
|
||||
FullPrimaryScreenHeight,
|
||||
HorizontalScrollBarButtonWidth,
|
||||
HorizontalScrollBarHeight,
|
||||
HorizontalScrollBarThumbWidth,
|
||||
IconWidth,
|
||||
IconHeight,
|
||||
IconGridWidth,
|
||||
IconGridHeight,
|
||||
MaximizedPrimaryScreenWidth,
|
||||
MaximizedPrimaryScreenHeight,
|
||||
MaximumWindowTrackWidth,
|
||||
MaximumWindowTrackHeight,
|
||||
MenuCheckmarkWidth,
|
||||
MenuCheckmarkHeight,
|
||||
MenuButtonWidth,
|
||||
MenuButtonHeight,
|
||||
MinimumWindowWidth,
|
||||
MinimumWindowHeight,
|
||||
MinimizedWindowWidth,
|
||||
MinimizedWindowHeight,
|
||||
MinimizedGridWidth,
|
||||
MinimizedGridHeight,
|
||||
MinimumWindowTrackWidth,
|
||||
MinimumWindowTrackHeight,
|
||||
PrimaryScreenWidth,
|
||||
PrimaryScreenHeight,
|
||||
WindowCaptionButtonWidth,
|
||||
WindowCaptionButtonHeight,
|
||||
ResizeFrameHorizontalBorderHeight,
|
||||
ResizeFrameVerticalBorderWidth,
|
||||
SmallIconWidth,
|
||||
SmallIconHeight,
|
||||
SmallWindowCaptionButtonWidth,
|
||||
SmallWindowCaptionButtonHeight,
|
||||
VirtualScreenWidth,
|
||||
VirtualScreenHeight,
|
||||
VerticalScrollBarWidth,
|
||||
VerticalScrollBarButtonHeight,
|
||||
WindowCaptionHeight,
|
||||
KanjiWindowHeight,
|
||||
MenuBarHeight,
|
||||
VerticalScrollBarThumbHeight,
|
||||
IsImmEnabled,
|
||||
IsMediaCenter,
|
||||
IsMenuDropRightAligned,
|
||||
IsMiddleEastEnabled,
|
||||
IsMousePresent,
|
||||
IsMouseWheelPresent,
|
||||
IsPenWindows,
|
||||
IsRemotelyControlled,
|
||||
IsRemoteSession,
|
||||
ShowSounds,
|
||||
IsSlowMachine,
|
||||
SwapButtons,
|
||||
IsTabletPC,
|
||||
VirtualScreenLeft,
|
||||
VirtualScreenTop,
|
||||
|
||||
PowerLineStatus,
|
||||
|
||||
IsGlassEnabled,
|
||||
UxThemeName,
|
||||
UxThemeColor,
|
||||
WindowCornerRadius,
|
||||
WindowGlassColor,
|
||||
WindowGlassBrush,
|
||||
WindowNonClientFrameThickness,
|
||||
WindowResizeBorderThickness,
|
||||
|
||||
NumSlots
|
||||
}
|
||||
|
||||
internal static class Win32Constant
|
||||
{
|
||||
internal const int MAX_PATH = 260;
|
||||
internal const int INFOTIPSIZE = 1024;
|
||||
internal const int TRUE = 1;
|
||||
internal const int FALSE = 0;
|
||||
}
|
||||
}
|
||||
@@ -1,225 +0,0 @@
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security;
|
||||
using System.Text;
|
||||
|
||||
namespace HandyControl.Tools.Interop
|
||||
{
|
||||
[SuppressMessage("ReSharper", "InconsistentNaming")]
|
||||
internal class UnsafeNativeMethods
|
||||
{
|
||||
[SecurityCritical]
|
||||
[SuppressUnmanagedCodeSecurity]
|
||||
[DllImport(ExternDll.User32, SetLastError = true, ExactSpelling = true, EntryPoint = nameof(GetDC), CharSet = CharSet.Auto)]
|
||||
public static extern IntPtr IntGetDC(HandleRef hWnd);
|
||||
|
||||
[SecurityCritical]
|
||||
public static IntPtr GetDC(HandleRef hWnd)
|
||||
{
|
||||
var hDc = IntGetDC(hWnd);
|
||||
if (hDc == IntPtr.Zero)
|
||||
{
|
||||
throw new Win32Exception();
|
||||
}
|
||||
|
||||
return HandleCollector.Add(hDc, CommonHandles.HDC);
|
||||
}
|
||||
|
||||
[SecurityCritical]
|
||||
[SuppressUnmanagedCodeSecurity]
|
||||
[DllImport(ExternDll.User32, ExactSpelling = true, EntryPoint = nameof(ReleaseDC), CharSet = CharSet.Auto)]
|
||||
public static extern int IntReleaseDC(HandleRef hWnd, HandleRef hDC);
|
||||
|
||||
[SecurityCritical]
|
||||
public static int ReleaseDC(HandleRef hWnd, HandleRef hDC)
|
||||
{
|
||||
HandleCollector.Remove((IntPtr)hDC, CommonHandles.HDC);
|
||||
return IntReleaseDC(hWnd, hDC);
|
||||
}
|
||||
|
||||
[SecurityCritical]
|
||||
[SuppressUnmanagedCodeSecurity]
|
||||
[DllImport(ExternDll.Gdi32, SetLastError = true, ExactSpelling = true, CharSet = CharSet.Auto)]
|
||||
public static extern int GetDeviceCaps(HandleRef hDC, int nIndex);
|
||||
|
||||
[SecurityCritical]
|
||||
[SuppressUnmanagedCodeSecurity]
|
||||
[DllImport(ExternDll.User32)]
|
||||
public static extern int GetSystemMetrics(SM nIndex);
|
||||
|
||||
[SecurityCritical]
|
||||
[SuppressUnmanagedCodeSecurity]
|
||||
[DllImport(ExternDll.User32, EntryPoint = nameof(DestroyIcon), CharSet = CharSet.Auto, SetLastError = true)]
|
||||
private static extern bool IntDestroyIcon(IntPtr hIcon);
|
||||
|
||||
[SecurityCritical]
|
||||
public static bool DestroyIcon(IntPtr hIcon)
|
||||
{
|
||||
var result = IntDestroyIcon(hIcon);
|
||||
return result;
|
||||
}
|
||||
|
||||
[SecurityCritical]
|
||||
[SuppressUnmanagedCodeSecurity]
|
||||
[DllImport(ExternDll.Gdi32, EntryPoint = nameof(DeleteObject), CharSet = CharSet.Auto, SetLastError = true)]
|
||||
private static extern bool IntDeleteObject(IntPtr hObject);
|
||||
|
||||
[SecurityCritical]
|
||||
public static bool DeleteObject(IntPtr hObject)
|
||||
{
|
||||
var result = IntDeleteObject(hObject);
|
||||
return result;
|
||||
}
|
||||
|
||||
[SecurityCritical]
|
||||
public static BitmapHandle CreateDIBSection(HandleRef hdc, ref BITMAPINFO bitmapInfo, int iUsage, ref IntPtr ppvBits, SafeFileMappingHandle hSection, int dwOffset)
|
||||
{
|
||||
if (hSection == null)
|
||||
{
|
||||
hSection = new SafeFileMappingHandle(IntPtr.Zero);
|
||||
}
|
||||
|
||||
var hBitmap = PrivateCreateDIBSection(hdc, ref bitmapInfo, iUsage, ref ppvBits, hSection, dwOffset);
|
||||
return hBitmap;
|
||||
}
|
||||
|
||||
[DllImport(ExternDll.Kernel32, EntryPoint = "CloseHandle", CharSet = CharSet.Auto, SetLastError = true)]
|
||||
public static extern bool IntCloseHandle(HandleRef handle);
|
||||
|
||||
[SecurityCritical, SuppressUnmanagedCodeSecurity]
|
||||
[DllImport(ExternDll.Gdi32, SetLastError = true, ExactSpelling = true, CharSet = CharSet.Auto, EntryPoint = nameof(CreateDIBSection))]
|
||||
private static extern BitmapHandle PrivateCreateDIBSection(HandleRef hdc, ref BITMAPINFO bitmapInfo, int iUsage, ref IntPtr ppvBits, SafeFileMappingHandle hSection, int dwOffset);
|
||||
|
||||
[SecurityCritical, SuppressUnmanagedCodeSecurity]
|
||||
[DllImport(ExternDll.User32, SetLastError = true, ExactSpelling = true, CharSet = CharSet.Auto, EntryPoint = nameof(CreateIconIndirect))]
|
||||
private static extern IconHandle PrivateCreateIconIndirect([In, MarshalAs(UnmanagedType.LPStruct)]ICONINFO iconInfo);
|
||||
|
||||
[SecurityCritical]
|
||||
public static IconHandle CreateIconIndirect([In, MarshalAs(UnmanagedType.LPStruct)]ICONINFO iconInfo)
|
||||
{
|
||||
var hIcon = PrivateCreateIconIndirect(iconInfo);
|
||||
return hIcon;
|
||||
}
|
||||
|
||||
[SecurityCritical, SuppressUnmanagedCodeSecurity]
|
||||
[DllImport(ExternDll.Gdi32, SetLastError = true, ExactSpelling = true, CharSet = CharSet.Auto, EntryPoint = nameof(CreateBitmap))]
|
||||
private static extern BitmapHandle PrivateCreateBitmap(int width, int height, int planes, int bitsPerPixel, byte[] lpvBits);
|
||||
|
||||
[SecurityCritical]
|
||||
internal static BitmapHandle CreateBitmap(int width, int height, int planes, int bitsPerPixel, byte[] lpvBits)
|
||||
{
|
||||
var hBitmap = PrivateCreateBitmap(width, height, planes, bitsPerPixel, lpvBits);
|
||||
return hBitmap;
|
||||
}
|
||||
|
||||
[SecurityCritical, SuppressUnmanagedCodeSecurity]
|
||||
[DllImport(ExternDll.Kernel32, EntryPoint = "GetModuleFileName", CharSet = CharSet.Unicode, SetLastError = true)]
|
||||
private static extern int IntGetModuleFileName(HandleRef hModule, StringBuilder buffer, int length);
|
||||
|
||||
[SecurityCritical]
|
||||
internal static string GetModuleFileName(HandleRef hModule)
|
||||
{
|
||||
var buffer = new StringBuilder(Win32Constant.MAX_PATH);
|
||||
while (true)
|
||||
{
|
||||
var size = IntGetModuleFileName(hModule, buffer, buffer.Capacity);
|
||||
if (size == 0)
|
||||
{
|
||||
throw new Win32Exception();
|
||||
}
|
||||
|
||||
if (size == buffer.Capacity)
|
||||
{
|
||||
buffer.EnsureCapacity(buffer.Capacity * 2);
|
||||
continue;
|
||||
}
|
||||
|
||||
return buffer.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
[SecurityCritical, SuppressUnmanagedCodeSecurity]
|
||||
[DllImport(ExternDll.Shell32, CharSet = CharSet.Auto, BestFitMapping = false, ThrowOnUnmappableChar = true)]
|
||||
internal static extern int ExtractIconEx(string szExeFileName, int nIconIndex, out IconHandle phiconLarge, out IconHandle phiconSmall, int nIcons);
|
||||
|
||||
[DllImport(ExternDll.Shell32, CharSet = CharSet.Auto)]
|
||||
public static extern int Shell_NotifyIcon(int message, NOTIFYICONDATA pnid);
|
||||
|
||||
[SecurityCritical]
|
||||
[SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
|
||||
[DllImport(ExternDll.User32, SetLastError = true, CharSet = CharSet.Unicode, EntryPoint = "CreateWindowExW")]
|
||||
public static extern IntPtr CreateWindowEx(
|
||||
int dwExStyle,
|
||||
[MarshalAs(UnmanagedType.LPWStr)] string lpClassName,
|
||||
[MarshalAs(UnmanagedType.LPWStr)] string lpWindowName,
|
||||
int dwStyle,
|
||||
int x,
|
||||
int y,
|
||||
int nWidth,
|
||||
int nHeight,
|
||||
IntPtr hWndParent,
|
||||
IntPtr hMenu,
|
||||
IntPtr hInstance,
|
||||
IntPtr lpParam);
|
||||
|
||||
[SecurityCritical]
|
||||
[SuppressUnmanagedCodeSecurity]
|
||||
[DllImport(ExternDll.User32, CharSet = CharSet.Unicode, SetLastError = true, BestFitMapping = false)]
|
||||
public static extern short RegisterClass(WNDCLASS wc);
|
||||
|
||||
[DllImport(ExternDll.User32, CharSet = CharSet.Auto)]
|
||||
public static extern IntPtr DefWindowProc(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam);
|
||||
|
||||
[DllImport(ExternDll.User32, ExactSpelling = true, CharSet = CharSet.Auto)]
|
||||
public static extern bool SetForegroundWindow(IntPtr hWnd);
|
||||
|
||||
[DllImport(ExternDll.User32, CharSet = CharSet.Auto, SetLastError = true)]
|
||||
public static extern IntPtr CallNextHookEx(IntPtr hhk, int nCode, IntPtr wParam, IntPtr lParam);
|
||||
|
||||
[DllImport(ExternDll.Kernel32, CharSet = CharSet.Auto, SetLastError = true)]
|
||||
public static extern IntPtr GetModuleHandle(string lpModuleName);
|
||||
|
||||
[DllImport(ExternDll.User32, CharSet = CharSet.Auto, SetLastError = true)]
|
||||
public static extern bool UnhookWindowsHookEx(IntPtr hhk);
|
||||
|
||||
public enum HookType
|
||||
{
|
||||
WH_KEYBOARD_LL = 13,
|
||||
WH_MOUSE_LL = 14
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct MOUSEHOOKSTRUCT
|
||||
{
|
||||
public NativeMethods.POINT pt;
|
||||
public IntPtr hwnd;
|
||||
public uint wHitTestCode;
|
||||
public IntPtr dwExtraInfo;
|
||||
}
|
||||
|
||||
public delegate IntPtr HookProc(int code, IntPtr wParam, IntPtr lParam);
|
||||
|
||||
[DllImport(ExternDll.User32, CharSet = CharSet.Auto, SetLastError = true)]
|
||||
public static extern IntPtr SetWindowsHookEx(int idHook, HookProc lpfn, IntPtr hMod, uint dwThreadId);
|
||||
|
||||
[DllImport(ExternDll.User32, SetLastError = true)]
|
||||
public static extern IntPtr GetDesktopWindow();
|
||||
|
||||
[DllImport(ExternDll.User32, SetLastError = true)]
|
||||
public static extern IntPtr GetWindowDC(IntPtr window);
|
||||
|
||||
[DllImport(ExternDll.Gdi32, SetLastError = true)]
|
||||
public static extern uint GetPixel(IntPtr dc, int x, int y);
|
||||
|
||||
[DllImport(ExternDll.User32, SetLastError = true)]
|
||||
public static extern int ReleaseDC(IntPtr window, IntPtr dc);
|
||||
|
||||
[DllImport(ExternDll.Gdi32, SetLastError = true, ExactSpelling = true, CharSet = CharSet.Auto)]
|
||||
public static extern int GetDeviceCaps(IntPtr hdc, int nIndex);
|
||||
|
||||
[DllImport(ExternDll.User32, CharSet = CharSet.Auto)]
|
||||
public static extern IntPtr GetDC(IntPtr ptr);
|
||||
}
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace HandyControl.Tools.Interop
|
||||
{
|
||||
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
|
||||
[SuppressMessage("ReSharper", "InconsistentNaming")]
|
||||
[SuppressMessage("ReSharper", "IdentifierTypo")]
|
||||
internal class WNDCLASS
|
||||
{
|
||||
public int style;
|
||||
public WndProc lpfnWndProc;
|
||||
public int cbClsExtra;
|
||||
public int cbWndExtra;
|
||||
public IntPtr hInstance;
|
||||
public IntPtr hIcon;
|
||||
public IntPtr hCursor;
|
||||
public IntPtr hbrBackground;
|
||||
public string lpszMenuName;
|
||||
public string lpszClassName;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user