📄 imageutils.cs.svn-base
字号:
using System;
using System.IO;
using System.Collections;
using System.Text;
using System.Runtime.InteropServices;
using System.Drawing;
using System.Reflection;
namespace Aspecto
{
enum AnimationSpeed
{
Off = 1,
Fastest = 3,
Fast = 5,
Medium = 7,
Smooth = 9,
Smoothest = 11
}
public struct NOTIFYICONDATA
{
public int cbSize;
public IntPtr hWnd;
public uint uID;
public uint uFlags;
public uint uCallbackMessage;
public IntPtr hIcon;
//internal char[] szTip = new char[64];
//internal IntPtr szTip;
}
public struct WNDCLASS
{
public uint style;
public IntPtr lpfnWndProc;
public int cbClsExtra;
public int cbWndExtra;
public IntPtr hInstance;
public IntPtr hIcon;
public IntPtr hCursor;
public IntPtr hbrBackground;
public IntPtr lpszMenuName;
public IntPtr lpszClassName;
}
public class ImageUtils
{
private const int MAX_NAME_CHARS = 100;
private static Random random = new Random();
[DllImport("coredll.dll")]
public static extern IntPtr LoadIcon(IntPtr hInst, string IconName);
[DllImport("coredll.dll")]
public static extern IntPtr GetModuleHandle(string lpModuleName);
[DllImport("coredll.dll")]
public static extern int Shell_NotifyIcon(int dwMessage, ref NOTIFYICONDATA pnid);
[DllImport("coredll")]
private static extern int GetClassName(IntPtr hWnd, StringBuilder name, int maxchars);
[DllImport("coredll")]
private static extern bool GetClassInfo(IntPtr hWnd, string name, ref WNDCLASS wndClass);
[DllImport("coredll")]
private static extern int GetClassLong(IntPtr hWnd, int index);
[DllImport("coredll")]
private static extern int GetLastError();
[DllImport("coredll")]
private static extern uint GetDlgItemText(IntPtr hWnd, int item, StringBuilder sb, int maxchars);
[DllImport("coredll")]
private static extern IntPtr GetParent(IntPtr hWnd);
[DllImport("coredll")]
public static extern bool IsChild(IntPtr parent, IntPtr child);
[DllImport("coredll")]
public static extern uint GetWindowThreadProcessId(IntPtr hWnd, ref uint id);
[DllImport("coredll")]
private static extern bool SipShowIM(byte flag);
[DllImport("coredll")]
private static extern bool SHSipPreference(IntPtr hWnd, int state);
public static bool HideInput(IntPtr win)
{
return SHSipPreference(win, 1);
}
public static bool ShowInput(bool show)
{
if (!show)
return SipShowIM(0x00000000);
else
return SipShowIM(0x00000001);
}
public static string ExecutingDir()
{
return Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetModules()[0].FullyQualifiedName) + "\\";
}
public static IntPtr GetParentWindow(IntPtr win)
{
return GetParent(win);
}
public static ArrayList GetCrackKeys()
{
ArrayList cracked = new ArrayList();
cracked.Add("999FFKKKFUUF33Z");
cracked.Add("ISHCPDTQBNJXDFV");
return cracked;
}
[DllImport("Coredll.dll")]
private extern static int KernelIoControl(int dwIoControlCode, IntPtr lpInBuf, int nInBufSize, IntPtr lpOutBuf, int nOutBufSize , ref int lpBytesReturned );
[DllImport("Coredll.dll")]
private extern static void SetCleanRebootFlag();
internal static void HardReset()
{
int IOCTL_HAL_REBOOT = 0x101003C;
int bytesReturned = 0;
SetCleanRebootFlag();
KernelIoControl(IOCTL_HAL_REBOOT, IntPtr.Zero, 0, IntPtr.Zero, 0, ref bytesReturned );
}
public static bool CheckReg(string regKey)
{
if (regKey.Length != 15)
return false;
if (GetCrackKeys().Contains(regKey))
return false;
int[] divs = {57, 43, 11, 24, 32};
for (int i = 0; i < regKey.Length; i += 3)
{
int n1 = (int)regKey[i];
int n2 = (int)regKey[i + 1];//int.Parse("" + regKey[i + 1]);
int n3 = (int)regKey[i + 2];//int.Parse("" + regKey[i + 2]);
if ((n1 + n2 + n3) % divs[i / 3] != 0)
return false;
}
return true;
}
public static byte[] CaptureScreen(int Width, int Height, int offset)
{
IntPtr screenWnd = DrawingWrapper.GetForegroundWindow();
IntPtr dc1 = DrawingWrapper.GetDC(screenWnd);
IntPtr InMemoryDC = DrawingWrapper.CreateCompatibleDC(dc1);
IntPtr hBitmap;
IntPtr ppvBits;
BITMAPINFO bmi = DrawingWrapper.GetOurNiceBitmap(Width, Height);
hBitmap = DrawingWrapper.CreateDIBSection(new IntPtr(0), bmi, 0, out ppvBits, new IntPtr(0), 0 );
IntPtr OldBitmap = DrawingWrapper.SelectObject( InMemoryDC, hBitmap );
IntPtr dc2 = DrawingWrapper.GetWindowDC(screenWnd);
//int offset = offHeight > 400 ? -52 : -26;
// TODO: should that -26 here be hardcoded?
DrawingWrapper.StretchBlt(InMemoryDC, 0, 0, Width, Height, dc2, 0, offset, Width, Height,
DrawingWrapper.SRCCOPY);
byte[] rawData = new byte[bmi.biSizeImage];
Marshal.Copy(ppvBits, rawData, 0, bmi.biSizeImage);
DrawingWrapper.SelectObject(InMemoryDC, OldBitmap);
DrawingWrapper.DeleteDC(InMemoryDC);
DrawingWrapper.ReleaseDC(IntPtr.Zero, dc1);
DrawingWrapper.ReleaseDC(screenWnd, dc2);
Marshal.FreeHGlobal(ppvBits); // not localFree anymore
return DrawingWrapper.CreateBitmap(Width, Height, rawData, bmi);
//MemoryStream ms = new MemoryStream(bitmap);
//return new Bitmap(ms);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -