xuechun 5 years ago
parent
commit
728f91bb4f

+ 30 - 0
WinSystem.sln

@@ -0,0 +1,30 @@
+
+Microsoft Visual Studio Solution File, Format Version 11.00
+# Visual Studio 2010
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WinSystem", "WinSystem\WinSystem.csproj", "{B3BD6804-799F-4B7D-AB8B-28F414FDC35D}"
+EndProject
+Global
+	GlobalSection(SolutionConfigurationPlatforms) = preSolution
+		Debug|Any CPU = Debug|Any CPU
+		Debug|Mixed Platforms = Debug|Mixed Platforms
+		Debug|x86 = Debug|x86
+		Release|Any CPU = Release|Any CPU
+		Release|Mixed Platforms = Release|Mixed Platforms
+		Release|x86 = Release|x86
+	EndGlobalSection
+	GlobalSection(ProjectConfigurationPlatforms) = postSolution
+		{B3BD6804-799F-4B7D-AB8B-28F414FDC35D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{B3BD6804-799F-4B7D-AB8B-28F414FDC35D}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{B3BD6804-799F-4B7D-AB8B-28F414FDC35D}.Debug|Mixed Platforms.ActiveCfg = Release|Any CPU
+		{B3BD6804-799F-4B7D-AB8B-28F414FDC35D}.Debug|Mixed Platforms.Build.0 = Release|Any CPU
+		{B3BD6804-799F-4B7D-AB8B-28F414FDC35D}.Debug|x86.ActiveCfg = Debug|Any CPU
+		{B3BD6804-799F-4B7D-AB8B-28F414FDC35D}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{B3BD6804-799F-4B7D-AB8B-28F414FDC35D}.Release|Any CPU.Build.0 = Release|Any CPU
+		{B3BD6804-799F-4B7D-AB8B-28F414FDC35D}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
+		{B3BD6804-799F-4B7D-AB8B-28F414FDC35D}.Release|Mixed Platforms.Build.0 = Release|Any CPU
+		{B3BD6804-799F-4B7D-AB8B-28F414FDC35D}.Release|x86.ActiveCfg = Release|Any CPU
+	EndGlobalSection
+	GlobalSection(SolutionProperties) = preSolution
+		HideSolutionNode = FALSE
+	EndGlobalSection
+EndGlobal

+ 150 - 0
WinSystem/Hook/KeyboardHook.cs

@@ -0,0 +1,150 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+using System.Diagnostics;
+using System.Runtime.InteropServices;
+using System.Windows.Forms;
+
+namespace WinSystem.Hook
+{
+    /// <summary>
+    /// 键盘钩子
+    /// </summary>
+    public class KeyboardHook
+    {
+
+        private int hHook;
+
+        Win32Api.HookProc KeyboardHookDelegate;
+        /// <summary>
+        /// 键盘按下事件
+        /// </summary>
+        public event KeyEventHandler OnKeyDownEvent;
+        /// <summary>
+        /// 键盘松开事件
+        /// </summary>
+        public event KeyEventHandler OnKeyUpEvent;
+        /// <summary>
+        /// 键盘敲击事件
+        /// </summary>
+        public event KeyPressEventHandler OnKeyPressEvent;
+        /// <summary>
+        /// 键盘钩子
+        /// </summary>
+        public KeyboardHook() { }
+        /// <summary>
+        /// 全局注入钩子
+        /// </summary>
+        public void SetHook()
+        {
+            KeyboardHookDelegate = new Win32Api.HookProc(KeyboardHookProc);
+            Process cProcess = Process.GetCurrentProcess();
+            ProcessModule cModule = cProcess.MainModule;
+            var mh = Win32Api.GetModuleHandle(cModule.ModuleName);
+            hHook = Win32Api.SetWindowsHookEx(Win32Api.WH_KEYBOARD_LL, KeyboardHookDelegate, mh, 0);
+        }
+        /// <summary>
+        /// 卸载钩子
+        /// </summary>
+        public void UnHook()
+        {
+            Win32Api.UnhookWindowsHookEx(hHook);
+        }
+
+        private List<Keys> preKeysList = new List<Keys>();//存放被按下的控制键,用来生成具体的键
+
+        private int KeyboardHookProc(int nCode, Int32 wParam, IntPtr lParam)
+        {
+            //如果该消息被丢弃(nCode<0)或者没有事件绑定处理程序则不会触发事件
+            if ((nCode >= 0) && (OnKeyDownEvent != null || OnKeyUpEvent != null || OnKeyPressEvent != null))
+            {
+                Win32Api.KeyboardHookStruct KeyDataFromHook = (Win32Api.KeyboardHookStruct)Marshal.PtrToStructure(lParam, typeof(Win32Api.KeyboardHookStruct));
+                Keys keyData = (Keys)KeyDataFromHook.vkCode;
+                //按下控制键
+                if ((OnKeyDownEvent != null || OnKeyPressEvent != null) && (wParam == Win32Api.WM_KEYDOWN || wParam == Win32Api.WM_SYSKEYDOWN))
+                {
+                    if (IsCtrlAltShiftKeys(keyData) && preKeysList.IndexOf(keyData) == -1)
+                    {
+                        preKeysList.Add(keyData);
+                    }
+                }
+                //WM_KEYDOWN和WM_SYSKEYDOWN消息,将会引发OnKeyDownEvent事件
+                if (OnKeyDownEvent != null && (wParam == Win32Api.WM_KEYDOWN || wParam == Win32Api.WM_SYSKEYDOWN))
+                {
+                    KeyEventArgs e = new KeyEventArgs(GetDownKeys(keyData));
+                    OnKeyDownEvent(this, e);
+                }
+                //WM_KEYDOWN消息将引发OnKeyPressEvent 
+                if (OnKeyPressEvent != null && wParam == Win32Api.WM_KEYDOWN)
+                {
+                    byte[] keyState = new byte[256];
+                    Win32Api.GetKeyboardState(keyState);
+                    byte[] inBuffer = new byte[2];
+                    if (Win32Api.ToAscii(KeyDataFromHook.vkCode, KeyDataFromHook.scanCode, keyState, inBuffer, KeyDataFromHook.flags) == 1)
+                    {
+                        KeyPressEventArgs e = new KeyPressEventArgs((char)inBuffer[0]);
+                        OnKeyPressEvent(this, e);
+                    }
+                }
+                //松开控制键
+                if ((OnKeyDownEvent != null || OnKeyPressEvent != null) && (wParam == Win32Api.WM_KEYUP || wParam == Win32Api.WM_SYSKEYUP))
+                {
+                    if (IsCtrlAltShiftKeys(keyData))
+                    {
+                        for (int i = preKeysList.Count - 1; i >= 0; i--)
+                        {
+                            if (preKeysList[i] == keyData)
+                            {
+                                preKeysList.RemoveAt(i);
+                            }
+                        }
+                    }
+                }
+
+                //WM_KEYUP和WM_SYSKEYUP消息,将引发OnKeyUpEvent事件 
+                if (OnKeyUpEvent != null && (wParam == Win32Api.WM_KEYUP || wParam == Win32Api.WM_SYSKEYUP))
+                {
+                    KeyEventArgs e = new KeyEventArgs(GetDownKeys(keyData));
+                    OnKeyUpEvent(this, e);
+                }
+            }
+
+            return Win32Api.CallNextHookEx(hHook, nCode, wParam, lParam);
+
+        }
+
+        //根据已经按下的控制键生成key
+
+        private Keys GetDownKeys(Keys key)
+        {
+
+            Keys rtnKey = Keys.None;
+            foreach (Keys i in preKeysList)
+            {
+                if (i == Keys.LControlKey || i == Keys.RControlKey)
+                {
+                    rtnKey = rtnKey | Keys.Control;
+                }
+                if (i == Keys.LMenu || i == Keys.RMenu)
+                {
+                    rtnKey = rtnKey | Keys.Alt;
+                }
+                if (i == Keys.LShiftKey || i == Keys.RShiftKey)
+                {
+                    rtnKey = rtnKey | Keys.Shift;
+                }
+            }
+            return rtnKey | key;
+        }
+
+        private Boolean IsCtrlAltShiftKeys(Keys key)
+        {
+            Console.WriteLine(key + "----");
+            if (key == Keys.LControlKey || key == Keys.RControlKey || key == Keys.LMenu || key == Keys.RMenu || key == Keys.LShiftKey || key == Keys.RShiftKey)
+            {
+                return true;
+            }
+            return false;
+        }
+    }
+}

+ 233 - 0
WinSystem/Hook/MouseHook.cs

@@ -0,0 +1,233 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+using System.Diagnostics;
+using System.Windows.Forms;
+using System.Runtime.InteropServices;
+using System.Reflection;
+using System.Drawing;
+
+
+namespace WinSystem.Hook
+{
+    /// <summary>
+    /// 鼠标钩子
+    /// </summary>
+    public class MouseHook
+    {
+        int hHook;
+
+        Win32Api.HookProc MouseHookDelegate;
+        //记录鼠标点下的坐标
+        Point point = new Point();
+        //上一次鼠标事件
+        private MouseEventArgs eb;
+        //上一次按下时间
+        private long beforeTime;
+        private const byte VK_SHIFT = 0x10;
+        private const byte VK_CAPITAL = 0x14;
+        //鼠标按下与松开的时候的两个句柄
+        private IntPtr mouse_down_hw = IntPtr.Zero;
+        private IntPtr mouse_up_hw = IntPtr.Zero;
+        /// <summary>
+        /// 双击超时时间
+        /// </summary>
+        private int outTime = Win32Api.GetDoubleClickTime()*10000;
+        //是否是双击
+        private bool isDoubleL = false;
+        private int dX = Win32Api.GetSystemMetrics(Win32Api.SM_CXDOUBLECLK) >> 1;
+        private int dY = Win32Api.GetSystemMetrics(Win32Api.SM_CYDOUBLECLK) >> 1;
+        //按下时的鼠标钩子结构体
+        private Win32Api.MouseHookStruct mouseHookStructDown;
+
+        #region 事件定义
+        /// <summary>
+        /// 鼠标事件
+        /// </summary>
+        public event MouseEventHandler OnMouseActivity;
+        /// <summary>
+        /// 鼠标双击事件
+        /// </summary>
+        public event MouseEventHandler OnMouseDoubleClickBActivity;
+        /// <summary>
+        /// 鼠标双击事件
+        /// </summary>
+        public event MouseEventHandler OnMouseDoubleClickFActivity;
+        /// <summary>
+        /// 一次点击事件(不区分按下松开事件)
+        /// </summary>
+        public event MouseEventBFHandler OnMouseBFActivity;
+        /// <summary>
+        /// 一次点击事件(区分按下松开事件)
+        /// </summary>
+        /// <param name="sender">事件来源</param>
+        /// <param name="ef">完成的事件</param>
+        /// <param name="eb">前一次事件</param>
+        public delegate void MouseEventBFHandler(object sender, MouseEventArgs ef, MouseEventArgs eb);
+        /////<summary>
+        /////鼠标更新事件
+        /////</summary>
+        /////<remarks>当鼠标移动或者滚轮滚动时触发</remarks>
+        //public event MouseEventHandler OnMouseUpdate;
+        /////<summary>
+        /////按键按下事件
+        /////</summary>
+        //public event KeyEventHandler OnKeyDown;
+        /////<summary>
+        /////按键按下并释放事件
+        /////</summary>
+        //public event KeyPressEventHandler OnKeyPress;
+        /////<summary>
+        /////按键释放事件
+        /////</summary>
+        //public event KeyEventHandler OnKeyUp;
+
+        #endregion 事件定义
+        /// <summary>
+        /// 鼠标钩子
+        /// </summary>
+        public MouseHook() { }
+        /// <summary>
+        /// 注入全局鼠标钩子
+        /// </summary>
+        /// <returns></returns>
+        public int SetHook()
+        {
+            beforeTime = 0L;
+            MouseHookDelegate = new Win32Api.HookProc(MouseHookProc);
+            Process cProcess = Process.GetCurrentProcess();
+            ProcessModule cModule = cProcess.MainModule;
+            var mh = Win32Api.GetModuleHandle(cModule.ModuleName);
+            //IntPtr mh = new IntPtr(1705710);
+            //var mh = Marshal.GetHINSTANCE(Assembly.GetExecutingAssembly().GetModules()[0]);
+            hHook = Win32Api.SetWindowsHookEx(Win32Api.WH_MOUSE_LL, MouseHookDelegate, mh, 0);
+            return hHook;
+        }
+        /// <summary>
+        /// 卸载鼠标钩子
+        /// </summary>
+        public void UnHook()
+        {
+            Win32Api.UnhookWindowsHookEx(hHook);
+        }
+        
+        private int MouseHookProc(int nCode, Int32 wParam, IntPtr lParam)
+        {
+            //if (nCode >= 0)
+            //{
+            //    Win32Api.MouseHookStruct MyMouseHookStruct = (Win32Api.MouseHookStruct)Marshal.PtrToStructure(lParam, typeof(Win32Api.MouseHookStruct));
+
+            //    KeyEventArgs e = new MouseEventHandler((POINT)MyMouseHookStruct.pt);
+            //    OnMouseMoveEvent(this.e);
+            //}
+            if ((nCode >= 0) && (OnMouseActivity != null || OnMouseBFActivity != null || OnMouseDoubleClickBActivity != null || OnMouseDoubleClickFActivity != null))
+            {
+                Win32Api.MouseHookStruct mouseHookStruct = (Win32Api.MouseHookStruct)Marshal.PtrToStructure(lParam, typeof(Win32Api.MouseHookStruct));
+                MouseButtons button = MouseButtons.None;
+                short mouseDelta = 0;
+                int clickCount = 0;
+                long now = 0L;
+                switch (wParam)
+                {
+                        //左键点击判断,若按下与抬起是同一个句柄则,认为是一次点击
+                    case (int)Win32Api.WM_LBUTTONDOWN:
+                        point.X = mouseHookStruct.pt.x;
+                        point.Y = mouseHookStruct.pt.y;
+                        mouse_down_hw = Win32Api.WindowFromPoint(point);
+                        eb = new MouseEventArgs(button, clickCount, mouseHookStruct.pt.x, mouseHookStruct.pt.y, mouseDelta);
+                        //需要双击事件时判断双击事件
+                        if (OnMouseDoubleClickBActivity != null || OnMouseDoubleClickFActivity != null)
+                        {
+                            now = DateTime.Now.ToFileTime();
+                            //判断双击时间间隔和坐标范围
+                            if (now - beforeTime < outTime && mouse_down_hw == mouse_up_hw
+                                && mouseHookStruct.pt.x >= mouseHookStructDown.pt.x - dX
+                                && mouseHookStruct.pt.x <= mouseHookStructDown.pt.x + dX
+                                && mouseHookStruct.pt.y >= mouseHookStructDown.pt.y - dY
+                                && mouseHookStruct.pt.y <= mouseHookStructDown.pt.y + dY
+                                )
+                            {
+                                isDoubleL = true;
+                                //有按下双击检测
+                                if (OnMouseDoubleClickBActivity != null)
+                                {
+                                    clickCount = 2;
+                                    button = MouseButtons.Left;
+                                    beforeTime = 0L;
+                                }
+                            }
+                            else
+                            {
+                                //不是双击事件重置点击时间
+                                beforeTime = DateTime.Now.ToFileTime();
+                                isDoubleL = false;
+                            }
+                        }
+                        break;
+                    case Win32Api.WM_LBUTTONUP:
+                        point.X = mouseHookStruct.pt.x;
+                        point.Y = mouseHookStruct.pt.y;
+                        mouse_up_hw = Win32Api.WindowFromPoint(point);
+
+                        if (mouse_down_hw == mouse_up_hw)
+                        {
+                            mouseHookStructDown = mouseHookStruct;
+                            if (isDoubleL)
+                            { //有松开双击检测
+                                if (OnMouseDoubleClickFActivity != null)
+                                {
+                                    clickCount = 2;
+                                    button = MouseButtons.Left;
+                                    beforeTime = 0L;
+                                }
+                            }
+                            else
+                            {
+                                clickCount = 1;
+                                button = MouseButtons.Left;
+                            }
+                        }
+                        break;
+                    case (int)Win32Api.WM_RBUTTONDOWN:
+                        button = MouseButtons.Right;
+                        break;
+                    case (int)Win32Api.WM_MBUTTONDOWN:
+                        button = MouseButtons.Middle;
+                        break;
+                    case (int)Win32Api.WM_MOUSEWHEEL:
+                        mouseDelta = (short)((mouseHookStruct.hwnd >> 16) & 0xffff);
+                        break;
+                }
+                MouseEventArgs e = new MouseEventArgs(button, clickCount, mouseHookStruct.pt.x, mouseHookStruct.pt.y, mouseDelta);
+                if (isDoubleL)
+                {
+                    //按下双击回调
+                    if (OnMouseDoubleClickBActivity != null && Win32Api.WM_LBUTTONDOWN == wParam)
+                    {
+                        OnMouseDoubleClickBActivity(this, e);
+                    }
+                    //松开双击回调
+                    if (OnMouseDoubleClickFActivity != null && Win32Api.WM_LBUTTONUP == wParam)
+                    {
+                        OnMouseDoubleClickFActivity(this, e);
+                    }
+                }
+                else
+                {
+                    //区分按下和松开的单击事件
+                    if (clickCount == 1 && OnMouseBFActivity != null)
+                    {
+                        OnMouseBFActivity(this, e, eb);
+                    }
+                    //其他鼠标事件
+                    if (OnMouseActivity != null)
+                    {
+                        OnMouseActivity(this, e);
+                    }
+                }
+            }
+
+            return Win32Api.CallNextHookEx(hHook, nCode, wParam, lParam);
+        }
+    }
+}

+ 246 - 0
WinSystem/Hwnd.cs

@@ -0,0 +1,246 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+using System.Threading;
+using System.Windows.Forms;
+using System.Drawing;
+using System.Drawing.Imaging;
+
+namespace WinSystem
+{
+    /// <summary>
+    /// 句柄操作
+    /// </summary>
+    public class Hwnd
+    {
+        /// <summary>
+        /// 获取焦点所在窗口句柄
+        /// </summary>
+        /// <param name="hwnd">焦点所在窗口或父窗口句柄</param>
+        /// <returns>焦点所在窗口句柄</returns>
+        public static IntPtr getFocusByhwnd(IntPtr hwnd)
+        {
+            int idAttachTo = AppDomain.GetCurrentThreadId();
+            int pid = 0;
+            int idAttach = Win32Api.GetWindowThreadProcessId(hwnd, out pid);
+            Win32Api.AttachThreadInput(idAttach, idAttachTo, true);
+            IntPtr nowFocus = Win32Api.GetFocus();
+            Win32Api.AttachThreadInput(idAttach, idAttachTo, false);
+            return nowFocus;
+        }
+
+        /// <summary>
+        /// 判断焦点是否在指定窗口句柄
+        /// </summary>
+        /// <param name="hwnd">窗口句柄</param>
+        /// <returns>焦点在指定句柄true,焦点不在指定句柄false</returns>
+        public static bool isFocus(IntPtr hwnd)
+        {
+            return hwnd!=IntPtr.Zero && hwnd == getFocusByhwnd(hwnd);
+        }
+
+        /// <summary>
+        /// 判断鼠标点击的是否是指定窗口句柄
+        /// </summary>
+        /// <param name="intptr">指定窗口句柄</param>
+        /// <param name="ef">松开鼠标事件数据</param>
+        /// <param name="eb">按下鼠标事件数据</param>
+        /// <param name="rect">点击确认范围</param>
+        /// <returns>true:是 false:否</returns>
+        public static bool isClickHwndIn(IntPtr intptr, MouseEventArgs ef, MouseEventArgs eb, Win32Api.RECT rect)
+        {
+
+            Win32Api.RECT recta;
+            Win32Api.GetWindowRect(intptr, out recta);
+            ////int t2 = rect.top + 48;
+            Win32Api.RECT rect1;
+            rect1.left = rect.left < 0 ? recta.left : (recta.left + rect.left);
+            rect1.right = rect.right < 0 ? recta.right : (recta.left + rect.right);
+            rect1.top = rect.top < 0 ? recta.top : (recta.top + rect.top);
+            rect1.bottom = rect.bottom < 0 ? recta.bottom : (recta.top + rect.bottom); ;
+            return (ef.X <= rect1.right && ef.X >= rect1.left && ef.Y <= rect1.bottom && ef.Y >= rect1.top &&
+                eb.X <= rect1.right && eb.X >= rect1.left && eb.Y <= rect1.bottom && eb.Y >= rect1.top &&
+                intptr == Win32Api.WindowFromPoint(new Point(ef.X, ef.Y)));
+
+            //return (MouseButtons.Left.Equals(e.Button) || MouseButtons.Right.Equals(e.Button))
+            //    && intptr == Win32Api.WindowFromPoint(new System.Drawing.Point(e.X, e.Y))
+            //    && isFocus(intptr);
+        }
+
+        /// <summary>
+        /// 判断鼠标点击的是否是指定窗口句柄
+        /// </summary>
+        /// <param name="intptr">指定窗口句柄</param>
+        /// <param name="e">鼠标事件数据</param>
+        /// <returns>true:是 false:否</returns>
+        public static bool isClickHwnd(IntPtr intptr, System.Windows.Forms.MouseEventArgs e)
+        {
+
+            return (MouseButtons.Left.Equals(e.Button) || MouseButtons.Right.Equals(e.Button))
+                && intptr == Win32Api.WindowFromPoint(new System.Drawing.Point(e.X, e.Y))
+                && isFocus(intptr);
+        }
+
+        /// <summary>
+        /// 查找窗口标题是以指定字符串开头的窗口
+        /// </summary>
+        /// <param name="titleStart">要比较的字符串</param>
+        /// <returns>窗口句柄</returns>
+        public static IntPtr FindFormStartWith(string titleStart)
+        {
+            string title="";
+            return FindFormStartWith(titleStart,out title);
+        }
+
+        /// <summary>
+        /// 查找窗口标题是以指定字符串开头的窗口
+        /// </summary>
+        /// <param name="titleStart">要比较的字符串</param>
+        /// <param name="title">窗口完整标题</param>
+        /// <returns>窗口句柄</returns>
+        public static IntPtr FindFormStartWith(string titleStart,out string title)
+        {
+            IntPtr intptr = IntPtr.Zero;
+            do
+            {
+                intptr = Win32Api.FindWindowEx(IntPtr.Zero, (uint)intptr, null, null);
+                StringBuilder sb = new StringBuilder(256);
+                Win32Api.GetWindowText(intptr, sb, 256);
+                title = sb.ToString();
+                if (title.StartsWith(titleStart))
+                    return intptr;
+            } while (intptr != IntPtr.Zero);
+            return IntPtr.Zero;
+        }
+
+        /// <summary>
+        /// 根据句柄截取图像并保存成指定文件(bmp格式),图像可以是被窗口挡着的,但对非GDI程序无效
+        /// </summary>
+        /// <param name="intptr">窗口句柄</param>
+        /// <param name="filePath">保存路径</param>
+        public static void GetWindowCapture(IntPtr intptr, string filePath)
+        {
+            GetWindowCapture(intptr).Save(filePath, ImageFormat.Bmp);
+        }
+        /// <summary>
+        /// 根据句柄截取图像,图像可以是被窗口挡着的,但对非GDI程序无效
+        /// </summary>
+        /// <param name="intptr">窗口句柄</param>
+        public static Bitmap GetWindowCapture(IntPtr intptr)
+        {
+            IntPtr hscrdc = Win32Api.GetWindowDC(intptr);
+            Win32Api.RECT windowRect = new Win32Api.RECT();
+            Win32Api.GetWindowRect(intptr, out windowRect);
+            int width = windowRect.right - windowRect.left;
+            int height = windowRect.bottom - windowRect.top;
+            IntPtr hbitmap = Win32Api.CreateCompatibleBitmap(hscrdc, width, height);
+            IntPtr hmemdc = Win32Api.CreateCompatibleDC(hscrdc);
+            Win32Api.SelectObject(hmemdc, hbitmap);
+            Win32Api.PrintWindow(intptr, hmemdc, 0);
+            Bitmap bmp = Bitmap.FromHbitmap(hbitmap);
+            Win32Api.DeleteDC(hscrdc);//删除用过的对象
+            Win32Api.DeleteDC(hmemdc);//删除用过的对象
+            return bmp;
+        }
+
+        /// <summary>
+        /// 寻找多个窗口中,第一个出现的窗口(用于等待多个窗口中的一个出现),若多窗口同时存在,随机返回一个
+        /// </summary>
+        /// <param name="title">窗口标题,最多支持二级窗口</param>
+        /// <param name="outTime">超时时间</param>
+        /// <returns>第几个窗口,失败返回-1</returns>
+        private static int FindOneFormCount(List<string[]> title, int outTime)
+        {
+            startTime = DateTime.Now;
+            thn = -1;
+            //intp = IntPtr.Zero;
+            loco1 = title;
+            sleeper = new Thread[loco1.Count];
+            for (int i = 0; i < loco1.Count; i++)
+            {
+                sleeper[i] = new Thread(new ParameterizedThreadStart(SleepThread));
+                sleeper[i].IsBackground = true;
+            }
+            for (int i = 0; i < sleeper.Length; i++)
+            {
+                sleeper[i].Start(i);
+            }
+            Thread.Sleep(100);
+            stoper = new Thread(
+                delegate() {
+                    int time = (int)outTime - (DateTime.Now - startTime).Milliseconds;
+                    Thread.Sleep(time > 0 ? time : 1);
+                    for (int i = 0; i < sleeper.Length; i++)
+                    {
+                        if (sleeper[i].IsAlive) sleeper[i].Abort();
+                    }
+                }
+                );
+            stoper.IsBackground = true;
+            //int time = outTime - 100;
+            //stoper.Start(time>0?time:0);
+            stoper.Start(outTime);
+            foreach (string[] ss in loco1)
+            {
+                lock (ss) { }
+            }
+            if (stoper.IsAlive) stoper.Abort();
+            return thn;
+        }
+        private static List<string[]> loco1 = new List<string[]>();
+        private static string str = "";
+        private static int thn = -1;
+        private static DateTime startTime;
+        private static Thread[] sleeper;
+        private static Thread stoper;
+        private static void SleepThread(object p)
+        {
+            int i = (int)p;
+            lock (loco1[i])
+            {
+                string[] name = (string[])loco1[i];
+                IntPtr pay_hwnd = IntPtr.Zero;
+                while (thn == -1 && pay_hwnd == IntPtr.Zero)
+                {
+                    pay_hwnd = IntPtr.Zero;
+                    if (name.Length == 1)
+                    {
+                        pay_hwnd = Win32Api.FindWindowEx(IntPtr.Zero, 0, null, name[0]);
+                    }
+                    else if (name.Length == 2)
+                    {
+                        if (name[0].Equals(""))
+                        {
+                            IntPtr inp = IntPtr.Zero;
+                            bool start = false;
+                            while ((inp != IntPtr.Zero || !start) && pay_hwnd == IntPtr.Zero)
+                            {
+                                if (thn != -1) break;
+                                start = true;
+                                inp = Win32Api.FindWindowEx(IntPtr.Zero, (uint)inp, null, name[0]);
+                                pay_hwnd = Win32Api.FindWindowEx(inp, 0, null, name[1]);
+                            }
+                        }
+                        else
+                        {
+                            pay_hwnd = Win32Api.FindWindowEx(IntPtr.Zero, 0, null, name[0]);
+                            pay_hwnd = Win32Api.FindWindowEx(pay_hwnd, 0, null, name[1]);
+                        }
+                    }
+                    if (thn == -1)
+                        Thread.Sleep(100);
+                }
+                if (pay_hwnd != IntPtr.Zero)
+                {
+                    lock (str)
+                    {
+                        if (thn == -1)
+                        {
+                            thn = i;
+                        }
+                    }
+                }
+            }
+        }
+    }
+}

+ 631 - 0
WinSystem/NetWork/HttpHelper.cs

@@ -0,0 +1,631 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+using System.Net;
+using System.IO;
+using System.Text.RegularExpressions;
+using System.IO.Compression;
+using System.Security.Cryptography.X509Certificates;
+using System.Net.Security;
+
+namespace DotNet.Utilities
+{
+    /// <summary>
+    /// Http连接操作帮助类
+    /// </summary>
+    public class HttpHelper
+    {
+        #region 预定义方法或者变更
+        //默认的编码
+        private Encoding encoding = Encoding.Default;
+        //HttpWebRequest对象用来发起请求
+        private HttpWebRequest request = null;
+        //获取影响流的数据对象
+        private HttpWebResponse response = null;
+        /// <summary>
+        /// 根据相传入的数据,得到相应页面数据
+        /// </summary>
+        /// <param name="objhttpitem">参数类对象</param>
+        /// <returns>返回HttpResult类型</returns>
+        private HttpResult GetHttpRequestData(HttpItem objhttpitem)
+        {
+            //返回参数
+            HttpResult result = new HttpResult();
+            try
+            {
+                #region 得到请求的response
+                using (response = (HttpWebResponse)request.GetResponse())
+                {
+                    result.StatusCode = response.StatusCode;
+                    result.StatusDescription = response.StatusDescription;
+                    result.Header = response.Headers;
+                    if (response.Cookies != null)
+                        result.CookieCollection = response.Cookies;
+                    if (response.Headers["set-cookie"] != null)
+                        result.Cookie = response.Headers["set-cookie"];
+                    MemoryStream _stream = new MemoryStream();
+                    //GZIIP处理
+                    if (response.ContentEncoding != null && response.ContentEncoding.Equals("gzip", StringComparison.InvariantCultureIgnoreCase))
+                    {
+                        //开始读取流并设置编码方式
+                        //new GZipStream(response.GetResponseStream(), CompressionMode.Decompress).CopyTo(_stream, 10240);
+                        //.net4.0以下写法
+                        _stream = GetMemoryStream(new GZipStream(response.GetResponseStream(), CompressionMode.Decompress));
+                    }
+                    else
+                    {
+                        //开始读取流并设置编码方式
+                        //response.GetResponseStream().CopyTo(_stream, 10240);
+                        //.net4.0以下写法
+                        _stream = GetMemoryStream(response.GetResponseStream());
+                    }
+                    //获取Byte
+                    byte[] RawResponse = _stream.ToArray();
+                    _stream.Close();
+                    //是否返回Byte类型数据
+                    if (objhttpitem.ResultType == ResultType.Byte)
+                        result.ResultByte = RawResponse;
+                    //从这里开始我们要无视编码了
+                    if (encoding == null)
+                    {
+                        Match meta = Regex.Match(Encoding.Default.GetString(RawResponse), "<meta([^<]*)charset=([^<]*)[\"']", RegexOptions.IgnoreCase);
+                        string charter = (meta.Groups.Count > 2) ? meta.Groups[2].Value.ToLower() : string.Empty;
+                        charter = charter.Replace("\"", "").Replace("'", "").Replace(";", "").Replace("iso-8859-1", "gbk");
+                        if (charter.Length > 2)
+                            encoding = Encoding.GetEncoding(charter.Trim());
+                        else
+                        {
+                            if (string.IsNullOrEmpty(response.CharacterSet))
+                                encoding = Encoding.UTF8;
+                            else
+                                encoding = Encoding.GetEncoding(response.CharacterSet);
+                        }
+                    }
+                    //得到返回的HTML
+                    result.Html = encoding.GetString(RawResponse);
+                }
+                #endregion
+            }
+            catch (WebException ex)
+            {
+                try
+                {
+                    //这里是在发生异常时返回的错误信息
+                    response = (HttpWebResponse)ex.Response;
+                    result.Html = ex.Message;
+                    if (response.StatusCode != HttpStatusCode.OK)
+                    {
+                        result.StatusCode = response.StatusCode;
+                        result.StatusDescription = response.StatusDescription;
+                    }
+                }
+                catch (Exception ex1) {
+                    result.Html = ex1.Message;
+                }
+            }
+            catch (Exception ex)
+            {
+                result.Html = ex.Message;
+            }
+            if (objhttpitem.IsToLower)
+                result.Html = result.Html.ToLower();
+
+            return result;
+        }
+        /// <summary>
+        /// 4.0以下.net版本取数据使用
+        /// </summary>
+        /// <param name="streamResponse">流</param>
+        private static MemoryStream GetMemoryStream(Stream streamResponse)
+        {
+            MemoryStream _stream = new MemoryStream();
+            int Length = 256;
+            Byte[] buffer = new Byte[Length];
+            int bytesRead = streamResponse.Read(buffer, 0, Length);
+            // write the required bytes  
+            while (bytesRead > 0)
+            {
+                _stream.Write(buffer, 0, bytesRead);
+                bytesRead = streamResponse.Read(buffer, 0, Length);
+            }
+            return _stream;
+        }
+        /// <summary>
+        /// 为请求准备参数
+        /// </summary>
+        ///<param name="objhttpItem">参数列表</param>
+        private void SetRequest(HttpItem objhttpItem)
+        {
+            // 验证证书
+            SetCer(objhttpItem);
+            //设置Header参数
+            if (objhttpItem.Header != null && objhttpItem.Header.Count > 0)
+            {
+                foreach (string item in objhttpItem.Header.AllKeys)
+                {
+                    request.Headers.Add(item, objhttpItem.Header[item]);
+                }
+            }
+            // 设置代理
+            SetProxy(objhttpItem);
+            //请求方式Get或者Post
+            request.Method = objhttpItem.Method;
+            request.Timeout = objhttpItem.Timeout;
+            request.ReadWriteTimeout = objhttpItem.ReadWriteTimeout;
+            //Accept
+            request.Accept = objhttpItem.Accept;
+            //ContentType返回类型
+            request.ContentType = objhttpItem.ContentType;
+            //UserAgent客户端的访问类型,包括浏览器版本和操作系统信息
+            request.UserAgent = objhttpItem.UserAgent;
+            // 编码
+            encoding = objhttpItem.Encoding;
+            //设置Cookie
+            SetCookie(objhttpItem);
+            //来源地址
+            request.Referer = objhttpItem.Referer;
+            //是否执行跳转功能
+            request.AllowAutoRedirect = objhttpItem.Allowautoredirect;
+            //设置Post数据
+            SetPostData(objhttpItem);
+            //设置最大连接
+            if (objhttpItem.Connectionlimit > 0)
+                request.ServicePoint.ConnectionLimit = objhttpItem.Connectionlimit;
+        }
+        /// <summary>
+        /// 设置证书
+        /// </summary>
+        /// <param name="objhttpItem"></param>
+        private void SetCer(HttpItem objhttpItem)
+        {
+            if (!string.IsNullOrEmpty(objhttpItem.CerPath))
+            {
+                //这一句一定要写在创建连接的前面。使用回调的方法进行证书验证。
+                ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback(CheckValidationResult);
+                //初始化对像,并设置请求的URL地址
+                request = (HttpWebRequest)WebRequest.Create(objhttpItem.URL);
+                //将证书添加到请求里
+                request.ClientCertificates.Add(new X509Certificate(objhttpItem.CerPath));
+            }
+            else
+                //初始化对像,并设置请求的URL地址
+                request = (HttpWebRequest)WebRequest.Create(objhttpItem.URL);
+        }
+        /// <summary>
+        /// 设置Cookie
+        /// </summary>
+        /// <param name="objhttpItem">Http参数</param>
+        private void SetCookie(HttpItem objhttpItem)
+        {
+            if (!string.IsNullOrEmpty(objhttpItem.Cookie))
+                //Cookie
+                request.Headers[HttpRequestHeader.Cookie] = objhttpItem.Cookie;
+            //设置Cookie
+            if (objhttpItem.CookieCollection != null)
+            {
+                request.CookieContainer = new CookieContainer();
+                request.CookieContainer.Add(objhttpItem.CookieCollection);
+            }
+        }
+        /// <summary>
+        /// 设置Post数据
+        /// </summary>
+        /// <param name="objhttpItem">Http参数</param>
+        private void SetPostData(HttpItem objhttpItem)
+        {
+            //验证在得到结果时是否有传入数据
+            if (request.Method.Trim().ToLower().Contains("post"))
+            {
+                byte[] buffer = null;
+                //写入Byte类型
+                if (objhttpItem.PostDataType == PostDataType.Byte && objhttpItem.PostdataByte != null && objhttpItem.PostdataByte.Length > 0)
+                {
+                    //验证在得到结果时是否有传入数据
+                    buffer = objhttpItem.PostdataByte;
+                }//写入文件
+                else if (objhttpItem.PostDataType == PostDataType.FilePath && !string.IsNullOrEmpty(objhttpItem.Postdata))
+                {
+                    StreamReader r = new StreamReader(objhttpItem.Postdata, encoding);
+                    buffer = Encoding.Default.GetBytes(r.ReadToEnd());
+                    r.Close();
+                } //写入字符串
+                else if (!string.IsNullOrEmpty(objhttpItem.Postdata))
+                {
+                    buffer = Encoding.Default.GetBytes(objhttpItem.Postdata);
+                }
+                if (buffer != null)
+                {
+                    request.ContentLength = buffer.Length;
+                    request.GetRequestStream().Write(buffer, 0, buffer.Length);
+                }
+            }
+        }
+        /// <summary>
+        /// 设置代理
+        /// </summary>
+        /// <param name="objhttpItem">参数对象</param>
+        private void SetProxy(HttpItem objhttpItem)
+        {
+            if (!string.IsNullOrEmpty(objhttpItem.ProxyIp))
+            {
+                //设置代理服务器
+                if (objhttpItem.ProxyIp.Contains(":"))
+                {
+                    string[] plist = objhttpItem.ProxyIp.Split(':');
+                    WebProxy myProxy = new WebProxy(plist[0].Trim(), Convert.ToInt32(plist[1].Trim()));
+                    //建议连接
+                    myProxy.Credentials = new NetworkCredential(objhttpItem.ProxyUserName, objhttpItem.ProxyPwd);
+                    //给当前请求对象
+                    request.Proxy = myProxy;
+                }
+                else
+                {
+                    WebProxy myProxy = new WebProxy(objhttpItem.ProxyIp, false);
+                    //建议连接
+                    myProxy.Credentials = new NetworkCredential(objhttpItem.ProxyUserName, objhttpItem.ProxyPwd);
+                    //给当前请求对象
+                    request.Proxy = myProxy;
+                }
+                //设置安全凭证
+                request.Credentials = CredentialCache.DefaultNetworkCredentials;
+            }
+        }
+
+        /// <summary>
+        /// 回调验证证书问题
+        /// </summary>
+        /// <param name="sender">流对象</param>
+        /// <param name="certificate">证书</param>
+        /// <param name="chain">X509Chain</param>
+        /// <param name="errors">SslPolicyErrors</param>
+        /// <returns>bool</returns>
+        public bool CheckValidationResult(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors)
+        {
+            // 总是接受    
+            return true;
+        }
+        #endregion
+        #region 普通类型
+        ///<summary>
+        ///采用https协议访问网络,根据传入的URl地址,得到响应的数据字符串。
+        ///</summary>
+        ///<param name="objhttpItem">参数列表</param>
+        ///<returns>String类型的数据</returns>
+        public HttpResult GetHtml(HttpItem objhttpItem)
+        {
+            try
+            {
+                //准备参数
+                SetRequest(objhttpItem);
+            }
+            catch (Exception ex)
+            {
+                HttpResult Result = new HttpResult()
+                {
+                    Cookie = "",
+                    Header = null,
+                    Html = ex.Message,
+                    StatusDescription = "配置参考时报错"
+                };
+                return Result;
+            }
+            //调用专门读取数据的类
+            return GetHttpRequestData(objhttpItem);
+        }
+        #endregion
+    }
+    /// <summary>
+    /// Http请求参考类
+    /// </summary>
+    public class HttpItem
+    {
+        string _URL = string.Empty;
+        /// <summary>
+        /// 请求URL必须填写
+        /// </summary>
+        public string URL
+        {
+            get { return _URL; }
+            set { _URL = value; }
+        }
+        string _Method = "GET";
+        /// <summary>
+        /// 请求方式默认为GET方式,当为POST方式时必须设置Postdata的值
+        /// </summary>
+        public string Method
+        {
+            get { return _Method; }
+            set { _Method = value; }
+        }
+        int _Timeout = 100000;
+        /// <summary>
+        /// 默认请求超时时间
+        /// </summary>
+        public int Timeout
+        {
+            get { return _Timeout; }
+            set { _Timeout = value; }
+        }
+        int _ReadWriteTimeout = 30000;
+        /// <summary>
+        /// 默认写入Post数据超时间
+        /// </summary>
+        public int ReadWriteTimeout
+        {
+            get { return _ReadWriteTimeout; }
+            set { _ReadWriteTimeout = value; }
+        }
+        string _Accept = "text/html, application/xhtml+xml, */*";
+        /// <summary>
+        /// 请求标头值 默认为text/html, application/xhtml+xml, */*
+        /// </summary>
+        public string Accept
+        {
+            get { return _Accept; }
+            set { _Accept = value; }
+        }
+        string _ContentType = "text/html";
+        /// <summary>
+        /// 请求返回类型默认 text/html
+        /// </summary>
+        public string ContentType
+        {
+            get { return _ContentType; }
+            set { _ContentType = value; }
+        }
+        string _UserAgent = "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)";
+        /// <summary>
+        /// 客户端访问信息默认Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)
+        /// </summary>
+        public string UserAgent
+        {
+            get { return _UserAgent; }
+            set { _UserAgent = value; }
+        }
+        Encoding _Encoding = null;
+        /// <summary>
+        /// 返回数据编码默认为NUll,可以自动识别,一般为utf-8,gbk,gb2312
+        /// </summary>
+        public Encoding Encoding
+        {
+            get { return _Encoding; }
+            set { _Encoding = value; }
+        }
+        private PostDataType _PostDataType = PostDataType.String;
+        /// <summary>
+        /// Post的数据类型
+        /// </summary>
+        public PostDataType PostDataType
+        {
+            get { return _PostDataType; }
+            set { _PostDataType = value; }
+        }
+        string _Postdata = string.Empty;
+        /// <summary>
+        /// Post请求时要发送的字符串Post数据
+        /// </summary>
+        public string Postdata
+        {
+            get { return _Postdata; }
+            set { _Postdata = value; }
+        }
+        private byte[] _PostdataByte = null;
+        /// <summary>
+        /// Post请求时要发送的Byte类型的Post数据
+        /// </summary>
+        public byte[] PostdataByte
+        {
+            get { return _PostdataByte; }
+            set { _PostdataByte = value; }
+        }
+        CookieCollection cookiecollection = null;
+        /// <summary>
+        /// Cookie对象集合
+        /// </summary>
+        public CookieCollection CookieCollection
+        {
+            get { return cookiecollection; }
+            set { cookiecollection = value; }
+        }
+        string _Cookie = string.Empty;
+        /// <summary>
+        /// 请求时的Cookie
+        /// </summary>
+        public string Cookie
+        {
+            get { return _Cookie; }
+            set { _Cookie = value; }
+        }
+        string _Referer = string.Empty;
+        /// <summary>
+        /// 来源地址,上次访问地址
+        /// </summary>
+        public string Referer
+        {
+            get { return _Referer; }
+            set { _Referer = value; }
+        }
+        string _CerPath = string.Empty;
+        /// <summary>
+        /// 证书绝对路径
+        /// </summary>
+        public string CerPath
+        {
+            get { return _CerPath; }
+            set { _CerPath = value; }
+        }
+        private Boolean isToLower = false;
+        /// <summary>
+        /// 是否设置为全文小写,默认为不转化
+        /// </summary>
+        public Boolean IsToLower
+        {
+            get { return isToLower; }
+            set { isToLower = value; }
+        }
+        private Boolean allowautoredirect = false;
+        /// <summary>
+        /// 支持跳转页面,查询结果将是跳转后的页面,默认是不跳转
+        /// </summary>
+        public Boolean Allowautoredirect
+        {
+            get { return allowautoredirect; }
+            set { allowautoredirect = value; }
+        }
+        private int connectionlimit = 1024;
+        /// <summary>
+        /// 最大连接数
+        /// </summary>
+        public int Connectionlimit
+        {
+            get { return connectionlimit; }
+            set { connectionlimit = value; }
+        }
+        private string proxyusername = string.Empty;
+        /// <summary>
+        /// 代理Proxy 服务器用户名
+        /// </summary>
+        public string ProxyUserName
+        {
+            get { return proxyusername; }
+            set { proxyusername = value; }
+        }
+        private string proxypwd = string.Empty;
+        /// <summary>
+        /// 代理 服务器密码
+        /// </summary>
+        public string ProxyPwd
+        {
+            get { return proxypwd; }
+            set { proxypwd = value; }
+        }
+        private string proxyip = string.Empty;
+        /// <summary>
+        /// 代理 服务IP
+        /// </summary>
+        public string ProxyIp
+        {
+            get { return proxyip; }
+            set { proxyip = value; }
+        }
+        private ResultType resulttype = ResultType.String;
+        /// <summary>
+        /// 设置返回类型String和Byte
+        /// </summary>
+        public ResultType ResultType
+        {
+            get { return resulttype; }
+            set { resulttype = value; }
+        }
+        private WebHeaderCollection header = new WebHeaderCollection();
+        /// <summary>
+        /// header对象
+        /// </summary>
+        public WebHeaderCollection Header
+        {
+            get { return header; }
+            set { header = value; }
+        }
+    }
+    /// <summary>
+    /// Http返回参数类
+    /// </summary>
+    public class HttpResult
+    {
+        string _Cookie = string.Empty;
+        /// <summary>
+        /// Http请求返回的Cookie
+        /// </summary>
+        public string Cookie
+        {
+            get { return _Cookie; }
+            set { _Cookie = value; }
+        }
+        CookieCollection cookiecollection = new CookieCollection();
+        /// <summary>
+        /// Cookie对象集合
+        /// </summary>
+        public CookieCollection CookieCollection
+        {
+            get { return cookiecollection; }
+            set { cookiecollection = value; }
+        }
+        private string html = string.Empty;
+        /// <summary>
+        /// 返回的String类型数据 只有ResultType.String时才返回数据,其它情况为空
+        /// </summary>
+        public string Html
+        {
+            get { return html; }
+            set { html = value; }
+        }
+        private byte[] resultbyte = null;
+        /// <summary>
+        /// 返回的Byte数组 只有ResultType.Byte时才返回数据,其它情况为空
+        /// </summary>
+        public byte[] ResultByte
+        {
+            get { return resultbyte; }
+            set { resultbyte = value; }
+        }
+        private WebHeaderCollection header = new WebHeaderCollection();
+        /// <summary>
+        /// header对象
+        /// </summary>
+        public WebHeaderCollection Header
+        {
+            get { return header; }
+            set { header = value; }
+        }
+        private string statusDescription = "";
+        /// <summary>
+        /// 返回状态说明
+        /// </summary>
+        public string StatusDescription
+        {
+            get { return statusDescription; }
+            set { statusDescription = value; }
+        }
+        private HttpStatusCode statusCode = HttpStatusCode.OK;
+        /// <summary>
+        /// 返回状态码,默认为OK
+        /// </summary>
+        public HttpStatusCode StatusCode
+        {
+            get { return statusCode; }
+            set { statusCode = value; }
+        }
+    }
+    /// <summary>
+    /// 返回类型
+    /// </summary>
+    public enum ResultType
+    {
+        /// <summary>
+        /// 表示只返回字符串 只有Html有数据
+        /// </summary>
+        String,
+        /// <summary>
+        /// 表示返回字符串和字节流 ResultByte和Html都有数据返回
+        /// </summary>
+        Byte
+    }
+    /// <summary>
+    /// Post的数据格式默认为string
+    /// </summary>
+    public enum PostDataType
+    {
+        /// <summary>
+        /// 字符串类型,这时编码Encoding可不设置
+        /// </summary>
+        String,
+        /// <summary>
+        /// Byte类型,需要设置PostdataByte参数的值编码Encoding可设置为空
+        /// </summary>
+        Byte,
+        /// <summary>
+        /// 传文件,Postdata必须设置为文件的绝对路径,必须设置Encoding的值
+        /// </summary>
+        FilePath
+    }
+}

+ 36 - 0
WinSystem/Properties/AssemblyInfo.cs

@@ -0,0 +1,36 @@
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+// 有关程序集的常规信息通过以下
+// 特性集控制。更改这些特性值可修改
+// 与程序集关联的信息。
+[assembly: AssemblyTitle("WinSystem")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("Microsoft")]
+[assembly: AssemblyProduct("WinSystem")]
+[assembly: AssemblyCopyright("Copyright © Microsoft 2015")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// 将 ComVisible 设置为 false 使此程序集中的类型
+// 对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型,
+// 则将该类型上的 ComVisible 特性设置为 true。
+[assembly: ComVisible(false)]
+
+// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
+[assembly: Guid("279282bb-d2af-4204-95e6-b100ff78f07c")]
+
+// 程序集的版本信息由下面四个值组成:
+//
+//      主版本
+//      次版本 
+//      内部版本号
+//      修订号
+//
+// 可以指定所有这些值,也可以使用“内部版本号”和“修订号”的默认值,
+// 方法是按如下所示使用“*”:
+// [assembly: AssemblyVersion("1.0.*")]
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]

+ 83 - 0
WinSystem/UnixTime.cs

@@ -0,0 +1,83 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace WinSystem
+{
+    /// <summary>
+    /// 时间转换处理
+    /// </summary>
+    public class UnixTime
+    {
+        /// <summary>
+        /// 将时间戳转换成DateTime
+        /// </summary>
+        /// <param name="timeStamp">时间戳</param>
+        /// <returns>时间</returns>
+        public static DateTime StampToDateTime(long timeStamp)
+        {
+            int count = timeStamp.ToString().Length;
+            long timeStampl = timeStamp;
+            switch (count)
+            {
+                case 13:
+                    timeStampl *= 10000;
+                    break;
+                case 17:
+                    break;
+                case 18:
+                    return DateTime.FromFileTimeUtc(timeStampl);
+                default: return new DateTime();
+            }
+            //13或17,执行以下代码
+            DateTime dateTimeStart = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1));
+            TimeSpan toNow = new TimeSpan(timeStampl);
+            return dateTimeStart.Add(toNow);
+        }
+
+        /// <summary>
+        /// 将时间戳转换成DateTime
+        /// </summary>
+        /// <param name="timeStamp">时间戳</param>
+        /// <returns>时间</returns>
+        public static DateTime StampToDateTime(string timeStamp)
+        {
+            int count = timeStamp.Length;
+            string timeStamps = timeStamp;
+            switch (count)
+            {
+                case 13:
+                    timeStamps += "0000";
+                    break;
+                case 17:
+                    break;
+                case 18:
+                    return DateTime.FromFileTimeUtc(long.Parse(timeStamp));
+                default: return new DateTime();
+            }
+            //13或17,执行以下代码
+            try
+            {
+                DateTime dateTimeStart = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1));
+                long lTime = long.Parse(timeStamps);
+                TimeSpan toNow = new TimeSpan(lTime);
+                return dateTimeStart.Add(toNow);
+            }
+            catch (Exception)
+            {
+                return new DateTime();
+            }
+            
+        }
+        /// <summary>
+        /// DateTime时间格式转换为Unix时间戳格式(毫秒)
+        /// </summary>
+        /// <param name="time">时间</param>
+        /// <returns>时间戳</returns>
+        public static long DateTimeToStamp(System.DateTime time)
+        {
+            System.DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1));
+            return (long)(time - startTime).TotalMilliseconds;
+        }
+    }
+}

+ 696 - 0
WinSystem/Win32Api.cs

@@ -0,0 +1,696 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+using System.Runtime.InteropServices;
+using System.Drawing;
+
+namespace WinSystem
+{
+    /// <summary>
+    /// 调用系统底层函数
+    /// </summary>
+    public class Win32Api
+    {
+
+        #region 常数和结构
+        #region 常数
+        /// <summary>
+        /// 非系统键按下
+        /// </summary>
+        public const int WM_KEYDOWN = 0x100;
+        /// <summary>
+        /// 非系统键松开
+        /// </summary>
+        public const int WM_KEYUP = 0x101;
+        /// <summary>
+        /// 系统键按下
+        /// </summary>
+        public const int WM_SYSKEYDOWN = 0x104;
+        /// <summary>
+        /// 非系统键松开
+        /// </summary>
+        public const int WM_SYSKEYUP = 0x105;
+        /// <summary>
+        /// 键盘敲击
+        /// </summary>
+        public const int WH_KEYBOARD_LL = 13;
+        /// <summary>
+        /// 全局鼠标事件
+        /// </summary>
+        public const int WH_MOUSE_LL = 14;
+        /// <summary>
+        /// 显示
+        /// </summary>
+        public const int WS_SHOWNORMAL = 1;
+        /// <summary>
+        /// 移动鼠标时发生,同WM_MOUSEFIRST
+        /// </summary>
+        public const int WM_MOUSEMOVE = 0x200;
+        /// <summary>
+        /// 按下鼠标左键
+        /// </summary>
+        public const int WM_LBUTTONDOWN = 0x201;
+        /// <summary>
+        /// 释放鼠标左键
+        /// </summary>
+        public const int WM_LBUTTONUP = 0x202;
+        /// <summary>
+        /// 双击鼠标左键
+        /// </summary>
+        public const int WM_LBUTTONDBLCLK = 0x203;
+        /// <summary>
+        /// 按下鼠标右键
+        /// </summary>
+        public const int WM_RBUTTONDOWN = 0x204;
+        /// <summary>
+        ///  释放鼠标右键
+        /// </summary>
+        public const int WM_RBUTTONUP = 0x205;
+        /// <summary>
+        /// 双击鼠标右键
+        /// </summary>
+        public const int WM_RBUTTONDBLCLK = 0x206;
+        /// <summary>
+        /// 按下鼠标中键
+        /// </summary>
+        public const int WM_MBUTTONDOWN = 0x207;
+        /// <summary>
+        /// 鼠标滚轮滚动
+        /// </summary>
+        public const int WM_MOUSEWHEEL = 0x020A;
+        /// <summary>
+        /// 单选复选选中状态
+        /// </summary>
+        public const int BM_GETCHECK = 0x00F0;
+        /// <summary>
+        /// 通道叠加
+        /// </summary>
+        public const byte AC_SRC_OVER = 0;
+        /// <summary>
+        /// 开启α混合
+        /// </summary>
+        public const Int32 ULW_ALPHA = 2;
+        /// <summary>
+        /// α通道叠加值
+        /// </summary>
+        public const byte AC_SRC_ALPHA = 1;
+        /// <summary>
+        /// 使窗体支持透明ModifyStyleEx(0, WS_EX_LAYERED);效果
+        /// </summary>
+        public const uint WS_EX_LAYERED = 0x80000;
+        /// <summary>
+        /// 半透明窗口
+        /// </summary>
+        public const int WS_EX_TRANSPARENT = 0x20;
+        /// <summary>
+        /// 设定一个新的窗口风格。
+        /// </summary>
+        public const int GWL_STYLE = (-16);
+        /// <summary>
+        /// 设定一个新的扩展风格。
+        /// </summary>
+        public const int GWL_EXSTYLE = (-20);
+        /// <summary>
+        /// 表示把窗体设置成半透明样式
+        /// </summary>
+        public const int LWA_ALPHA = 0;
+
+        #region 系统配置编号
+        //public const int SM_CXSCREEN = 0;
+        //public const int SM_CYSCREEN = 1;
+        //public const int SM_CXVSCROLL = 2;
+        //public const int SM_CYHSCROLL = 3;
+        //public const int SM_CYCAPTION = 4;
+        //public const int SM_CXBORDER = 5;
+        //public const int SM_CYBORDER = 6;
+        //public const int SM_CXDLGFRAME = 7;
+        //public const int SM_CYDLGFRAME = 8;
+        //public const int SM_CYHTHUMB = 9;
+        //public const int SM_CXHTHUMB = 10;
+        //public const int SM_CXICON = 1;
+        //public const int SM_CYICON = 12;
+        //public const int SM_CXCURSOR = 13;
+        //public const int SM_CYCURSOR = 14;
+        //public const int SM_CYMENU = 15;
+        //public const int SM_CXFULLSCREEN = 16;
+        //public const int SM_CYFULLSCREEN = 17;
+        //public const int SM_CYKANJIWINDOW = 18;
+        //public const int SM_MOUSEPRESENT = 19;
+        //public const int SM_CYVSCROLL = 20;
+        //public const int SM_CXHSCROLL = 21;
+        //public const int SM_DEBUG = 22;
+        //public const int SM_SWAPBUTTON = 23;
+        //public const int SM_CXMIN = 28;
+        //public const int SM_CYMIN = 29;
+        //public const int SM_CXSIZE = 30;
+        //public const int SM_CYSIZE = 31;
+        //public const int SM_CXMINTRACK = 34;
+        //public const int SM_CYMINTRACK = 35;
+        /// <summary>
+        /// 双击矩形区域的宽
+        /// </summary>
+        public const int SM_CXDOUBLECLK = 36;
+        /// <summary>
+        /// 双击矩形区域的高
+        /// </summary>
+        public const int SM_CYDOUBLECLK = 37;
+        //public const int SM_CXICONSPACING = 38;
+        //public const int SM_CYICONSPACING = 39;
+        //public const int SM_MENUDROPALIGNMENT = 40;
+        #endregion
+
+        #endregion
+
+        #region 键盘
+        /// <summary>
+        /// 声明键盘钩子的封送结构类型 
+        /// </summary>
+        [StructLayout(LayoutKind.Sequential)]
+        public struct KeyboardHookStruct
+        {
+            /// <summary>
+            /// 表示一个在1到254间的虚似键盘码
+            /// </summary>
+            public int vkCode;
+            /// <summary>
+            /// 表示硬件扫描码 
+            /// </summary>
+            public int scanCode;
+            /// <summary>
+            /// 
+            /// </summary>
+            public int flags;
+            /// <summary>
+            /// 
+            /// </summary>
+            public int time;
+            /// <summary>
+            /// 
+            /// </summary>
+            public int dwExtraInfo;
+        }
+        #endregion
+
+        #region 鼠标
+        /// <summary>
+        /// 鼠标坐标结构类型
+        /// </summary>
+        [StructLayout(LayoutKind.Sequential)]
+        public struct POINT
+        {
+            /// <summary>
+            /// x像素
+            /// </summary>
+            public Int32 x;
+            /// <summary>
+            /// y像素
+            /// </summary>
+            public Int32 y;
+            /// <summary>
+            /// 构造函数
+            /// </summary>
+            /// <param name="x"></param>
+            /// <param name="y"></param>
+            public POINT(Int32 x, Int32 y)
+            {
+                this.x = x;
+                this.y = y;
+            }
+        }
+
+        /// <summary>
+        /// 鼠标钩子结构类型
+        /// </summary>
+        [StructLayout(LayoutKind.Sequential)]
+        public struct MouseHookStruct
+        {
+            /// <summary>
+            /// 坐标
+            /// </summary>
+            public POINT pt;
+            /// <summary>
+            /// 句柄
+            /// </summary>
+            public int hwnd;
+            /// <summary>
+            /// 
+            /// </summary>
+            public int wHitTestCode;
+            /// <summary>
+            /// 
+            /// </summary>
+            public int dwExtraInfo;
+        }
+        /// <summary>
+        /// 区域结构类型
+        /// </summary>
+        [StructLayout(LayoutKind.Sequential)]
+        public struct RECT
+        {
+            /// <summary>
+            /// 左端位置
+            /// </summary>
+            public int left;
+            /// <summary>
+            /// 顶端位置
+            /// </summary>
+            public int top;
+            /// <summary>
+            /// 右端位置
+            /// </summary>
+            public int right;
+            /// <summary>
+            /// 下端位置
+            /// </summary>
+            public int bottom;
+        }
+
+        /// <summary>
+        /// 窗口大小
+        /// </summary>
+        [StructLayout(LayoutKind.Sequential)]
+        public struct Size
+        {
+            /// <summary>
+            /// 窗口x轴宽度
+            /// </summary>
+            public Int32 cx;
+            /// <summary>
+            /// 窗口y轴高度
+            /// </summary>
+            public Int32 cy;
+            /// <summary>
+            /// 构造函数
+            /// </summary>
+            /// <param name="x"></param>
+            /// <param name="y"></param>
+            public Size(Int32 x, Int32 y)
+            {
+                cx = x;
+                cy = y;
+            }
+        }
+
+        /// <summary>
+        /// 颜色通道
+        /// </summary>
+        [StructLayout(LayoutKind.Sequential, Pack = 1)]
+        public struct BLENDFUNCTION
+        {
+            /// <summary>
+            /// BlendOp
+            /// </summary>
+            public byte BlendOp;
+            /// <summary>
+            /// BlendFlags
+            /// </summary>
+            public byte BlendFlags;
+            /// <summary>
+            /// SourceConstantAlpha
+            /// </summary>
+            public byte SourceConstantAlpha;
+            /// <summary>
+            /// AlphaFormat
+            /// </summary>
+            public byte AlphaFormat;
+        }
+
+        #endregion
+        #endregion
+
+
+        #region Api
+        /// <summary>
+        /// 钩子委托函数
+        /// </summary>
+        /// <param name="nCode"></param>
+        /// <param name="wParam"></param>
+        /// <param name="lParam"></param>
+        /// <returns></returns>
+        public delegate int HookProc(int nCode, Int32 wParam, IntPtr lParam);
+
+        /// <summary>
+        /// 安装钩子的函数 
+        /// </summary>
+        /// <param name="idHook"></param>
+        /// <param name="lpfn"></param>
+        /// <param name="hInstance"></param>
+        /// <param name="threadId"></param>
+        /// <returns></returns>
+        [DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
+        public static extern int SetWindowsHookEx(int idHook, HookProc lpfn, IntPtr hInstance, int threadId);
+
+        /// <summary>
+        /// 卸下钩子的函数 
+        /// </summary>
+        /// <param name="idHook"></param>
+        /// <returns></returns>
+        [DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
+        public static extern bool UnhookWindowsHookEx(int idHook);
+
+        /// <summary>
+        /// 下一个钩挂的函数 
+        /// </summary>
+        /// <param name="idHook"></param>
+        /// <param name="nCode"></param>
+        /// <param name="wParam"></param>
+        /// <param name="lParam"></param>
+        /// <returns></returns>
+        [DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
+        public static extern int CallNextHookEx(int idHook, int nCode, Int32 wParam, IntPtr lParam);
+
+        /// <summary>
+        /// 下一个钩挂的函数 
+        /// </summary>
+        /// <param name="idHook"></param>
+        /// <param name="nCode"></param>
+        /// <param name="wParam"></param>
+        /// <param name="lParam"></param>
+        /// <returns></returns>
+        [DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
+        public static extern int CallNextHookEx(int idHook, int nCode, IntPtr wParam, IntPtr lParam);
+
+        /// <summary>
+        /// 转成Ascii编码
+        /// </summary>
+        /// <param name="uVirtKey"></param>
+        /// <param name="uScanCode"></param>
+        /// <param name="lpbKeyState"></param>
+        /// <param name="lpwTransKey"></param>
+        /// <param name="fuState"></param>
+        /// <returns></returns>
+        [DllImport("user32")]
+        public static extern int ToAscii(int uVirtKey, int uScanCode, byte[] lpbKeyState, byte[] lpwTransKey, int fuState);
+
+        /// <summary>
+        /// 获取键盘状态
+        /// </summary>
+        /// <param name="pbKeyState"></param>
+        /// <returns></returns>
+        [DllImport("user32")]
+        public static extern int GetKeyboardState(byte[] pbKeyState);
+
+        /// <summary>
+        /// 获取一个应用程序或动态链接库的模块句柄
+        /// </summary>
+        /// <param name="lpModuleName"></param>
+        /// <returns></returns>
+        [DllImport("kernel32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
+        public static extern IntPtr GetModuleHandle(string lpModuleName);
+
+        /// <summary>
+        /// 获取窗口句柄
+        /// </summary>
+        /// <param name="lpClassName">窗口类名</param>
+        /// <param name="lpWindowName">窗口标题</param>
+        /// <returns></returns>
+        [DllImport("user32.dll", EntryPoint = "FindWindow", SetLastError = true)]
+        public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
+
+        /// <summary>
+        ///  获取窗口句柄
+        /// </summary>
+        /// <param name="hwndParent">父窗口句柄</param>
+        /// <param name="hwndChildAfter">上一个窗口句柄</param>
+        /// <param name="lpszClass">窗口类名</param>
+        /// <param name="lpszWindow">窗口标题</param>
+        /// <returns></returns>
+        [DllImport("user32.dll", EntryPoint = "FindWindowEx", SetLastError = true)]
+        public static extern IntPtr FindWindowEx(IntPtr hwndParent, uint hwndChildAfter, string lpszClass, string lpszWindow);
+
+        /// <summary>
+        /// 发送消息
+        /// </summary>
+        /// <param name="hwnd">窗口句柄</param>
+        /// <param name="wMsg">消息1</param>
+        /// <param name="wParam">消息2</param>
+        /// <param name="lParam">消息值</param>
+        /// <returns></returns>
+        [DllImport("user32.dll", EntryPoint = "SendMessage", SetLastError = true, CharSet = CharSet.Auto)]
+        public static extern int SendMessage(IntPtr hwnd, uint wMsg, int wParam, int lParam);
+
+        /// <summary>
+        /// 发送消息
+        /// </summary>
+        /// <param name="hwnd">窗口句柄</param>
+        /// <param name="wMsg">消息1</param>
+        /// <param name="wParam">消息2</param>
+        /// <param name="lParam">消息值</param>
+        /// <returns></returns>
+        [DllImport("user32.dll", EntryPoint = "SendMessage", SetLastError = true, CharSet = CharSet.Auto)]
+        public static extern int SendMessageStr(IntPtr hwnd, uint wMsg, int wParam, string lParam);
+
+        /// <summary>
+        /// 发送消息
+        /// </summary>
+        /// <param name="hwnd">窗口句柄</param>
+        /// <param name="wMsg">消息</param>
+        /// <param name="wParam">消息值1</param>
+        /// <param name="lParam">消息值2</param>
+        /// <returns></returns>
+        [DllImport("user32.dll", EntryPoint = "SendMessage")]
+        public static extern int SendMessageStrB(IntPtr hwnd, uint wMsg, int wParam, StringBuilder lParam);
+
+        /// <summary>
+        /// 创建指定窗口的线程设置到前台,并且激活该窗口,对非自身程序无效
+        /// </summary>
+        /// <param name="hwnd">窗口句柄</param>
+        [DllImport("user32.dll", EntryPoint = "SetForegroundWindow", SetLastError = true)]
+        public static extern void SetForegroundWindow(IntPtr hwnd);
+
+        /// <summary>
+        /// 获取窗口类名
+        /// </summary>
+        /// <param name="hwnd">窗口句柄</param>
+        /// <param name="text">类名返回值</param>
+        /// <param name="MaxCount">类名最大长度</param>
+        [DllImport("User32.dll")]
+        public static extern void GetClassName(IntPtr hwnd, StringBuilder text, int MaxCount);
+
+        /// <summary>
+        /// 获取窗口标题
+        /// </summary>
+        /// <param name="hwnd">窗口句柄</param>
+        /// <param name="text">标题返回值</param>
+        /// <param name="MaxLen">标题最大长度</param>
+        [DllImport("User32.dll")]
+        public static extern void GetWindowText(IntPtr hwnd, StringBuilder text, int MaxLen);
+
+        /// <summary>
+        /// 设置窗口层次
+        /// </summary>
+        /// <param name="hwnd">窗口句柄</param>
+        /// <param name="cmdShow">层次</param>
+        /// <returns></returns>
+        [DllImport("User32.dll")]
+        public static extern bool ShowWindowAsync(IntPtr hwnd, int cmdShow);
+
+        /// <summary>
+        /// 获取窗口大小
+        /// </summary>
+        /// <param name="hwnd">窗口句柄</param>
+        /// <param name="lpRect">区域</param>
+        /// <returns></returns>
+        [DllImport("user32.dll")]
+        public static extern int GetWindowRect(IntPtr hwnd, out RECT lpRect);
+
+        /// <summary>
+        /// 获取指定坐标处窗口句柄
+        /// </summary>
+        /// <param name="point">坐标</param>
+        /// <returns>窗口句柄</returns>
+        [DllImport("user32.dll")]
+        public static extern IntPtr WindowFromPoint(Point point);
+
+        /// <summary>
+        /// 获取活跃窗口句柄,对非自身程序无效
+        /// </summary>
+        /// <returns></returns>
+        [DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
+        public static extern IntPtr GetForegroundWindow();
+
+        /// <summary>
+        /// 获取指定窗口线程ID,out进程ID
+        /// </summary>
+        /// <param name="hwnd">窗口句柄</param>
+        /// <param name="pid">线程ID</param>
+        /// <returns></returns>
+        [DllImport("user32", EntryPoint = "GetWindowThreadProcessId")]
+        public static extern int GetWindowThreadProcessId(IntPtr hwnd, out int pid);
+
+        /// <summary>
+        /// 线程注入、卸载
+        /// </summary>
+        /// <param name="idAttach">要注入的线程ID</param>
+        /// <param name="idAttachTo">当前线程ID</param>
+        /// <param name="fAttach">行为 true:注入,false:卸载</param>
+        /// <returns></returns>
+        [DllImport("user32", EntryPoint = "AttachThreadInput")]
+        public static extern int AttachThreadInput(int idAttach, int idAttachTo, bool fAttach);
+
+        /// <summary>
+        /// 获取焦点所在句柄
+        /// </summary>
+        /// <returns>窗口句柄</returns>
+        [DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.Winapi)]
+        public static extern IntPtr GetFocus();
+
+        /// <summary>
+        /// 获取系统鼠标双击时间间隔(单位:毫秒)
+        /// </summary>
+        /// <returns>鼠标双击时间间隔 毫秒</returns>
+        [DllImport("user32.dll", EntryPoint = "GetDoubleClickTime")]
+        public extern static int GetDoubleClickTime();
+
+        /// <summary>
+        /// 得到被定义的系统数据或者系统配置信息
+        /// </summary>
+        /// <param name="intnIndex">配置编码</param>
+        /// <returns>配置信息</returns>
+        [DllImport("user32.dll", EntryPoint = "GetSystemMetrics")]
+        public extern static int GetSystemMetrics(int intnIndex);
+
+        /// <summary>
+        /// 创建驱动设备环境
+        /// </summary>
+        /// <param name="lpszDriver">驱动名</param>
+        /// <param name="lpszDevice">设备名</param>
+        /// <param name="lpszOutput">输出</param>
+        /// <param name="lpInitData">输入</param>
+        /// <returns>设备上下文环境的句柄</returns>
+        [DllImport("gdi32.dll", ExactSpelling = true, SetLastError = true)]
+        public static extern IntPtr CreateDC(string lpszDriver,string lpszDevice,string lpszOutput,IntPtr lpInitData);
+        /// <summary>
+        /// 获取窗口的设备环境
+        /// </summary>
+        /// <param name="hwnd">窗口句柄</param>
+        /// <returns>设备上下文环境的句柄</returns>
+        [DllImport("user32.dll", ExactSpelling = true, SetLastError = true)]
+        public static extern IntPtr GetWindowDC(IntPtr hwnd);
+
+        /// <summary>
+        /// 该函数创建一个与指定设备兼容的内存设备上下文环境(DC)
+        /// </summary>
+        /// <param name="hdc">设备上下文环境的句柄</param>
+        /// <returns></returns>
+        [DllImport("gdi32.dll", ExactSpelling = true, SetLastError = true)]
+        public static extern IntPtr CreateCompatibleDC(IntPtr hdc);
+
+        /// <summary>
+        /// 检索一指定窗口的客户区域或整个屏幕的显示设备上下文环境的句柄,以后可以在GDI函数中使用该句柄来在设备上下文环境中绘图
+        /// </summary>
+        /// <param name="hWnd"></param>
+        /// <returns></returns>
+        [DllImport("user32.dll", ExactSpelling = true, SetLastError = true)]
+        public static extern IntPtr GetDC(IntPtr hWnd);
+
+        /// <summary>
+        /// 创建与指定的设备环境相关的设备兼容的位图
+        /// </summary>
+        /// <param name="hdc">设备上下文环境的句柄</param>
+        /// <param name="width">图像宽</param>
+        /// <param name="height">图像高</param>
+        /// <returns></returns>
+        [DllImport("gdi32.dll")]
+        public static extern IntPtr CreateCompatibleBitmap(IntPtr hdc, int width, int height);
+
+        /// <summary>
+        /// 选择一对象到指定的设备上下文环境中
+        /// </summary>
+        /// <param name="hdc">设备上下文环境的句柄</param>
+        /// <param name="hgdiobj">被选择的对象的句柄</param>
+        /// <returns>如果选择对象不是区域并且函数执行成功,那么返回值是被取代的对象的句柄;如果选择对象是区域并且函数执行成功</returns>
+        [DllImport("gdi32.dll", ExactSpelling = true)]
+        public static extern IntPtr SelectObject(IntPtr hdc,IntPtr hgdiobj);
+
+        /// <summary>
+        /// 释放设备上下文环境(DC)
+        /// </summary>
+        /// <param name="hWnd"></param>
+        /// <param name="hDC"></param>
+        /// <returns></returns>
+        [DllImport("user32.dll", ExactSpelling = true)]
+        public static extern int ReleaseDC(IntPtr hWnd, IntPtr hDC);
+
+        /// <summary>
+        /// 删除指定的设备上下文环境
+        /// </summary>
+        /// <param name="hdc">设备上下文环境的句柄</param>
+        /// <returns>成功:非0 失败:0</returns>
+        [DllImport("gdi32.dll", ExactSpelling = true, SetLastError = true)]
+        public static extern int DeleteDC(IntPtr hdc);
+       
+        /// <summary>
+        /// 截取非屏幕区的窗口
+        /// </summary>
+        /// <param name="hwnd">窗口句柄</param>
+        /// <param name="hdcBlt">被选择的对象的句柄</param>
+        /// <param name="nFlags">可选标志,指定绘图选项</param>
+        /// <returns>成功:非0 失败:0</returns>
+        [DllImport("user32.dll")]
+        public static extern bool PrintWindow(IntPtr hwnd, IntPtr hdcBlt, UInt32 nFlags);
+
+        /// <summary>
+        /// 删除一个逻辑笔、画笔、字体、位图、区域或者调色板,释放所有与该对象有关的系统资源,在对象被删除之后,指定的句柄也就失效了
+        /// 注释:当一个绘画对象(如笔或画笔)当前被选入一个设备上下文环境时不要删除该对象。当一个调色板画笔被删除时,与该画笔相关的位图并不被删除,该图必须单独地删除。
+        /// </summary>
+        /// <param name="hObj"></param>
+        /// <returns>成功,返回非零值;如果指定的句柄无效或者它已被选入设备上下文环境,则返回值为零</returns>
+        [DllImport("gdi32.dll", ExactSpelling = true, SetLastError = true)]
+        public static extern int DeleteObject(IntPtr hObj);
+
+        /// <summary>
+        /// 更新一个分层窗口的位置,大小,形状,内容和半透明度
+        /// </summary>
+        /// <param name="hwnd"></param>
+        /// <param name="hdcDst"></param>
+        /// <param name="pptDst"></param>
+        /// <param name="psize"></param>
+        /// <param name="hdcSrc"></param>
+        /// <param name="pptSrc"></param>
+        /// <param name="crKey"></param>
+        /// <param name="pblend"></param>
+        /// <param name="dwFlags"></param>
+        /// <returns></returns>
+        [DllImport("user32.dll", ExactSpelling = true, SetLastError = true)]
+        public static extern int UpdateLayeredWindow(IntPtr hwnd, IntPtr hdcDst, ref POINT pptDst, ref Size psize, IntPtr hdcSrc, ref POINT pptSrc, Int32 crKey, ref BLENDFUNCTION pblend, Int32 dwFlags);
+        /// <summary>
+        /// 此函数用于设置分层窗口透明度,常和 UpdateLayeredWindow 函数结合使用。
+        /// </summary>
+        /// <param name="hwnd"></param>
+        /// <param name="crKey"></param>
+        /// <param name="bAlpha"></param>
+        /// <param name="dwFlags"></param>
+        /// <returns></returns>
+        [DllImport("user32", EntryPoint = "SetLayeredWindowAttributes")]
+        public static extern int SetLayeredWindowAttributes(IntPtr hwnd, int crKey, int bAlpha, int dwFlags);
+        /// <summary>
+        /// 根据世界转换修改区域
+        /// </summary>
+        /// <param name="lpXform"></param>
+        /// <param name="nCount"></param>
+        /// <param name="rgnData"></param>
+        /// <returns></returns>
+        [DllImport("gdi32.dll", ExactSpelling = true, SetLastError = true)]
+        public static extern IntPtr ExtCreateRegion(IntPtr lpXform, uint nCount, IntPtr rgnData);
+        /// <summary>
+        /// 改变指定窗口的属性.函数也将指定的一个32位值设置在窗口的额外存储空间的指定偏移位置
+        /// </summary>
+        /// <param name="hwnd"></param>
+        /// <param name="nIndex"></param>
+        /// <param name="dwNewLong"></param>
+        /// <returns></returns>
+        [DllImport("user32", EntryPoint = "SetWindowLong")]
+        public static extern uint SetWindowLong(IntPtr hwnd, int nIndex, uint dwNewLong);
+        /// <summary>
+        /// 获得指定窗口的有关信息,函数也获得在额外窗口内存中指定偏移位地址的32位度整型值
+        /// </summary>
+        /// <param name="hwnd"></param>
+        /// <param name="nIndex"></param>
+        /// <returns></returns>
+        [DllImport("user32", EntryPoint = "GetWindowLong")]
+        public static extern uint GetWindowLong(IntPtr hwnd, int nIndex);
+        #endregion
+
+    }
+}

+ 60 - 0
WinSystem/WinSystem.csproj

@@ -0,0 +1,60 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <ProductVersion>8.0.30703</ProductVersion>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{B3BD6804-799F-4B7D-AB8B-28F414FDC35D}</ProjectGuid>
+    <OutputType>Library</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <RootNamespace>WinSystem</RootNamespace>
+    <AssemblyName>WinSystem</AssemblyName>
+    <TargetFrameworkVersion>v2.0</TargetFrameworkVersion>
+    <FileAlignment>512</FileAlignment>
+    <TargetFrameworkProfile />
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+    <DebugSymbols>true</DebugSymbols>
+    <DebugType>full</DebugType>
+    <Optimize>false</Optimize>
+    <OutputPath>bin\Debug\</OutputPath>
+    <DefineConstants>DEBUG;TRACE</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+    <DebugType>pdbonly</DebugType>
+    <Optimize>true</Optimize>
+    <OutputPath>..\..\RotateTransformDemo\Pet\bin\Release\bin\</OutputPath>
+    <DefineConstants>TRACE</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+    <UseVSHostingProcess>false</UseVSHostingProcess>
+    <DocumentationFile>bin\Release\WinSystem.XML</DocumentationFile>
+  </PropertyGroup>
+  <ItemGroup>
+    <Reference Include="System" />
+    <Reference Include="System.Data" />
+    <Reference Include="System.Drawing" />
+    <Reference Include="System.Windows.Forms" />
+    <Reference Include="System.Xml" />
+  </ItemGroup>
+  <ItemGroup>
+    <Compile Include="Hook\KeyboardHook.cs" />
+    <Compile Include="Hook\MouseHook.cs" />
+    <Compile Include="Hwnd.cs" />
+    <Compile Include="NetWork\HttpHelper.cs" />
+    <Compile Include="Properties\AssemblyInfo.cs" />
+    <Compile Include="UnixTime.cs" />
+    <Compile Include="Win32Api.cs" />
+  </ItemGroup>
+  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+  <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
+       Other similar extension points exist, see Microsoft.Common.targets.
+  <Target Name="BeforeBuild">
+  </Target>
+  <Target Name="AfterBuild">
+  </Target>
+  -->
+</Project>