C# API 0.6

using System;
using System.Collections.Generic;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Text;
using System.Windows.Forms;

class CsAPI
    {

    [DllImport("kernel32.dll")]
    public static extern int OpenProcess(int dwDesiredAccess, bool bInheritHandle, int dwProcessId);

    [DllImport("User32.dll", CharSet = CharSet.Auto)]
    public static extern int GetWindowThreadProcessId(IntPtr hwnd, out int ID);

    [DllImport("user32.dll", EntryPoint = "FindWindow")]
    public extern static IntPtr FindWindow(string lpClassName, string lpWindowName);

    [DllImport("user32.dll")]
    public static extern bool SetForegroundWindow(IntPtr hWnd);

    [DllImport("User32.dll", EntryPoint = "FindWindowEx")]
    public static extern IntPtr FindWindowEx(IntPtr hwndParent, int hwndChildAfter, string lpClassName, string lpWindowName);

    [DllImport("kernel32.dll ")]
    public static extern bool ReadProcessMemory(int hProcess, Int64 lpBaseAddress, out Int64 lpBuffer, int nSize, out Int64 lpNumberOfBytesRead);
    [DllImport("Kernel32.dll")]
    public static extern int WriteProcessMemory(int hProcess, Int64 lpBaseAddress, [In, Out] byte[] lpBuffer, int nSize, Int64 lpNumberOfBytesWritten);

    [DllImport("user32.dll", CharSet = CharSet.Auto)]
    public static extern int MoveWindow(IntPtr hWnd, int x, int y, int nWidth, int nHeight, bool BRePaint);

    public struct Rect
    {
        public int Left;
        public int Top;
        public int Right;
        public int Bottom;
    }

    [DllImport("user32.dll")]
    public static extern int GetWindowRect(IntPtr hwnd, out Rect lpRect);

    [DllImport("user32.dll")]
    public static extern bool GetCursorPos(ref Point lpPoint);

    [DllImport("user32.dll")]
    public static extern int SetCursorPos(int x, int y);

    [DllImport("kernel32", SetLastError = true)]
    public static extern short GlobalAddAtom(string lpString);

    [DllImport("kernel32", SetLastError = true)]
    public static extern short GlobalDeleteAtom(short nAtom);

    [DllImport("user32.dll")]
    public static extern int GetAsyncKeyState(int vKey);

    [System.Runtime.InteropServices.DllImport("user32")]
    public static extern int mouse_event(int dwFlags, int dx, int dy, int cButtons, int dwExtraInfo);

    //移动鼠标
    public const int MOUSEEVENTF_MOVE = 0x0001;
    //模拟鼠标左键按下
    public const int MOUSEEVENTF_LEFTDOWN = 0x0002;
    //模拟鼠标左键抬起
    public const int MOUSEEVENTF_LEFTUP = 0x0004;
    //模拟鼠标右键按下
    public const int MOUSEEVENTF_RIGHTDOWN = 0x0008;
    //模拟鼠标右键抬起
    public const int MOUSEEVENTF_RIGHTUP = 0x0010;
    //模拟鼠标中键按下
    public const int MOUSEEVENTF_MIDDLEDOWN = 0x0020;
    //模拟鼠标中键抬起
    public const int MOUSEEVENTF_MIDDLEUP = 0x0040;
    //标示是否采用绝对坐标
    public const int MOUSEEVENTF_ABSOLUTE = 0x8000;

    [DllImport("user32.dll")]
    public static extern IntPtr GetActiveWindow();

    [DllImport("user32.dll")]
    public static extern IntPtr GetForegroundWindow();

    public static int MakeLong(int A, int B)
    {
        int result;
        result = A | B << 16;
        return result;
    }

    [DllImport("User32.dll", EntryPoint = "PostMessage")]
    public static extern int PostMessage(IntPtr hWnd, int Msg, int wParam, int lParam);

    [DllImport("User32.dll", EntryPoint = "SendMessage")]
    public static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);

    [DllImport("user32.dll", EntryPoint = "SendMessageA")]
    public static extern int SendMessageA(IntPtr hwnd, int wMsg, int wParam, int lParam);

    [DllImport("user32.dll")]
    public static extern int WindowFromPoint(int xPoint, int yPoint);

    [DllImport("user32.dll")]
    public static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndlnsertAfter, int X, int Y, int cx, int cy, uint Flags);
    public struct CURSORINFO
    {
        public int cbSize;
        public int flags;
        public IntPtr hCursor;
        public System.Drawing.Point ptScreenPos;
    }

    [DllImport("user32.dll")]
    public static extern bool GetCursorInfo(out CURSORINFO pci);

    [DllImport("user32.dll")]
    public static extern void keybd_event(byte bVk, byte bScan, int dwFlags, int dwExtraInfo);

    /// <summary>
    /// 移动鼠标到指定的坐标点
    /// </summary>
    public void MoveMouseToPoint(Point p)
    {
        SetCursorPos(p.X, p.Y);
    }
    //如果函数执行成功,返回值不为0。
    //如果函数执行失败,返回值为0。要得到扩展错误信息,调用GetLastError。
    [System.Runtime.InteropServices.DllImport("user32.dll", SetLastError = true)]
    public static extern bool RegisterHotKey(IntPtr hWnd,                //要定义热键的窗口的句柄
       int id,                     //定义热键ID(不能与其它ID重复)
        KeyModifiers fsModifiers,   //标识热键是否在按Alt、Ctrl、Shift、Windows等键时才会生效
        Keys vk                     //定义热键的内容
        );
    [System.Runtime.InteropServices.DllImport("user32.dll", SetLastError = true)]
    public static extern bool UnregisterHotKey(
        IntPtr hWnd,                //要取消热键的窗口的句柄
        int id                      //要取消热键的ID
        );
    //定义了辅助键的名称(将数字转变为字符以便于记忆,也可去除此枚举而直接使用数值)
    [Flags()]
    public enum KeyModifiers
    {
        None = 0,
        Alt = 1,
        Ctrl = 2,
        Shift = 4,
        WindowsKey = 8
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值