随便写了个winfrom程序,然后,用windows api去修改软件里面文本框的内容,
winapi如下:
- public static class WinAPI
- {
- 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; //标示是否采用绝对坐标
- public const int WM_GETTEXT = 0x000D; //13
- public const int WM_SETTEXT = 0x000C; //12
- public const int WM_CLICK = 0x00F5; //245
- [DllImport("user32.dll", EntryPoint = "mouse_event", SetLastError = true)]
- public static extern int mouse_event(int dwFlags, int dx, int dy, int cButtons, int dwExtraInfo);
- //方法声明
- [DllImport("user32.dll")]
- public static extern int SendMessage(IntPtr Handle, int WParam, int LParam);
- [DllImport("User32.dll", EntryPoint = "FindWindow")]
- public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
- [DllImport("user32.dll", EntryPoint = "FindWindowEx")]
- public static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);
- [DllImport("User32.dll", EntryPoint = "SendMessage")]
- public static extern int SendMessage(IntPtr hWnd, int Msg, IntPtr wParam, string lParam);
- [DllImport("user32.dll ", EntryPoint = "GetDlgItem")]
- public static extern IntPtr GetDlgItem(IntPtr hParent, int nIDParentItem);
- [DllImport("user32.dll", EntryPoint = "GetWindowText")]
- public static extern int GetWindowText(IntPtr hwnd, StringBuilder lpString, int cch);
- [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
- public static extern int GetWindowTextLength(IntPtr hWnd);
- [DllImport("user32.dll", EntryPoint = "SendMessage", SetLastError = true, CharSet = CharSet.Auto)]
- public static extern int SendMessage(IntPtr hwnd, uint wMsg, int wParam, int lParam);
- [DllImport("user32.dll")]
- public static extern int EnumChildWindows(IntPtr hWndParent, CallBack lpfn, int lParam);
- public delegate bool CallBack(IntPtr hwnd, int lParam);
- }
复制代码
调用代码如下:
demo下载:
|