![](https://csdnimg.cn/release/download_crawler_static/30897211/bg1.jpg)
Windows API 用 C#调用
1. 设置钩子
[DllImport("user32", EntryPoint="SetWindowsHookEx")]
public static extern int SetWindowsHookExA(int idHook, int lpfn, int hmod, int dwThreadId)
2.根据窗口名找到窗口句柄
[DllImport("user32", EntryPoint="FindWindow")]
public static extern int FindWindowA(string lpClassName, string lpWindowName)
3
[DllImport("user32")] public static extern int GetWindowRect(int hwnd, ref RECT lpRect)
3.
[DllImport("user32")]
public static extern int ActivateKeyboardLayout(int HKL, int flags)
4.
[DllImport("user32")]
public static extern int AdjustWindowRect(ref RECT lpRect, int dwStyle, int bMenu)
5.
[DllImport("user32")]
public static extern int AdjustWindowRectEx(ref RECT lpRect, int dsStyle, int bMenu, int
dwEsStyle)
6.
[DllImport("user32")]
public static extern int AnyPopup(int hwnd)
7.
[DllImport("user32")]
public static extern int ArrangeIconicWindows(int hwnd)
8.
[DllImport("user32")]
public static extern int AttachThreadInput(int idAttach, int idAttachTo, int fAttach)
9.
[DllImport("user32")]
public static extern int BeginDeferWindowPos(int nNumWindows)
10.
[DllImport("user32")]
public static extern int BeginPaint(int hwnd, ref PAINTSTRUCT lpPaint)
11.
[DllImport("user32")]
public static extern int BringWindowToTop(int hwnd)
12.
[DllImport("user32")]
public static extern int BroadcastSystemMessage(int dw, ref int pdw, int un, int wParam, int
lParam)
13.
[DllImport("user32", EntryPoint="CallMsgFilter")]
public static extern int CallMsgFilterA(ref MSG lpMsg, int nCode)