using System; using System.Collections.Generic; using System.Linq; using System.Runtime.InteropServices; using System.Text; namespace POSV { public class WindowsAPI { //窗口拖动 public const int WM_NCLBUTTONDOWN = 0xA1; public const int HT_CAPTION = 0x2; [DllImport("user32.dll")] public static extern int SendMessage(IntPtr hWnd , int Msg , int wParam , int lParam); [DllImport("user32.dll")] public static extern bool ReleaseCapture(); public static void MoveWindows(IntPtr handle) { ReleaseCapture(); SendMessage(handle , WM_NCLBUTTONDOWN , HT_CAPTION , 0); } //键盘 public const uint KEYEVENTF_EXTENDEDKEY = 0x1; public const uint KEYEVENTF_KEYUP = 0x2; [System.Runtime.InteropServices.DllImport("user32.dll")] static extern short GetKeyState(int nVirtKey); [System.Runtime.InteropServices.DllImport("user32.dll")] static extern void keybd_event(byte bVk , byte bScan , uint dwFlags , uint dwExtraInfo); [DllImport("user32.dll")] public extern static void mouse_event(int dwFlags , int dx , int dy , int dwData , int dwExtraInfo); [DllImport("user32.dll")] public extern static bool SetCursorPos(int X , int Y); public enum MouseEventFlags { Move = 0x0001, LeftDown = 0x0002, LeftUp = 0x0004, RightDown = 0x0008, RightUp = 0x0010, MiddleDown = 0x0020, MiddleUp = 0x0040, Wheel = 0x0800, Absolute = 0x8000 } public enum VirtualKeys : byte { VK_NUMLOCK = 0x90, //数字锁定键 VK_SCROLL = 0x91, //滚动锁定 VK_CAPITAL = 0x14, //大小写锁定 VK_A = 62 } public static bool GetState(VirtualKeys Key) { return (GetKeyState((int)Key) == 1); } public static void SetState(VirtualKeys Key , bool State) { if (State != GetState(Key)) { keybd_event((byte)Key , 0x45 , KEYEVENTF_EXTENDEDKEY | 0 , 0); keybd_event((byte)Key , 0x45 , KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP , 0); } } ////开启键盘大写 //SetState(VirtualKeys.VK_CAPITAL, true); ////关闭键盘大写 //SetState(VirtualKeys.VK_CAPITAL, false); ////开启键盘滚动锁定 //SetState(VirtualKeys.VK_SCROLL, true); ////关闭键盘滚动锁定 //SetState(VirtualKeys.VK_SCROLL, false); ////开启键盘数字锁定键 //SetState(VirtualKeys.VK_NUMLOCK, true); ////关闭键盘数字锁定键 //SetState(VirtualKeys.VK_NUMLOCK, false); public const int WM_SYSCOMMAND = 0x0112; public const int SC_CLOSE = 0xF060; [System.Runtime.InteropServices.DllImport("user32.dll" , CharSet = System.Runtime.InteropServices.CharSet.Auto , SetLastError = true)] public static extern IntPtr FindWindow(String sClassName , String sAppName); [System.Runtime.InteropServices.DllImport("user32.dll" , CharSet = System.Runtime.InteropServices.CharSet.Auto , SetLastError = true)] public static extern int SendMessage(IntPtr hWnd , uint Msg , int wParam , int lParam); [System.Runtime.InteropServices.DllImport("wininet.dll")] public extern static bool InternetGetConnectedState(out int description , int reservedValue); [DllImport("user32.dll" , CharSet = CharSet.Auto , ExactSpelling = true)] public static extern int GetSystemMetrics(int nIndex); public bool IsTouchAvailable() { return ((GetSystemMetrics(0x5e) & 0x40) > 0); } [DllImport("gdi32.dll", EntryPoint = "AddFontResourceW", SetLastError = true)] public static extern int AddFontResource([In][MarshalAs(UnmanagedType.LPWStr)] string lpFileName); } }