添加引用using System.Runtime.InteropServices;
- 消息
[DllImport("user32.dll", CharSet = CharSet.Unicode)]//windows
[DllImport("coredll.dll", CharSet = CharSet.Unicode)]//mobile
public static extern IntPtr PostMessage(IntPtr hwnd, int wmsg, IntPtr wparam, IntPtr lparam);
- 窗体
[DllImport("user32.dll")]
[DllImport("coredll.dll")]
public static extern IntPtr FindWindow(string lpclassname, string lpwindowname);
[DllImport("user32.dll")]
[DllImport("coredll.dll")]
public static extern IntPtr FindWindowEx(IntPtr hwndparent, IntPtr hwndchildafter, string lpszclass, string lpszwindow);
[DllImport("coredll.dll", SetLastError=true)]
public static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);
[DllImport("coredll.dll", SetLastError = true)]
public static extern int SetWindowLong(IntPtr hWnd, int nIndex, WndProcDelegate newProc);
[DllImport("coredll.dll", SetLastError = true)]
public static extern IntPtr GetWindowLong(IntPtr hWnd, int nIndex);
[DllImport("coredll.dll")]
public static extern IntPtr CreateWindowEx(uint dwExStyle, string lpClassName,string lpWindowName, uint dwStyle, int x, int y, int nWidth, int nHeight,IntPtr hWndParent, IntPtr hMenu, IntPtr hInstance, IntPtr lpParam);
[DllImport("coredll.dll")]
public static extern IntPtr CallWindowProc(IntPtr lpPrevWndFunc, IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);
[DllImport("coredll.dll", CharSet = CharSet.Auto)]
public static extern IntPtr DefWindowProc(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam);
[DllImport("coredll.dll", CharSet = CharSet.Auto)]
public static extern IntPtr GetModuleHandle(string modName);
[DllImport("coredll.dll", CharSet = CharSet.Auto)]
public static extern bool DestroyWindow(IntPtr hWnd);
- 钩子
[DllImport("coredll.dll")]
private static extern int SetWindowsHookEx(int type, HookKeyProc HookKeyProc, IntPtr hInstance, int m);
[DllImport("coredll.dll")]
private static extern int CallNextHookEx(HookKeyProc hhk,int nCode,IntPtr wParam,IntPtr lParam);
[DllImport("coredll.dll", SetLastError = true)]
private static extern int UnhookWindowsHookEx(int idHook);
[DllImport("coredll.dll")]
private static extern IntPtr GetModuleHandle(string mod);
[DllImport("coredll.dll")]
private static extern int GetCurrentThreadId();