架构师_程序员_码农网

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

搜索
查看: 298150|回复: 70

[资料] c#调用windows api修改文本框的值

  [复制链接]
发表于 2016-10-27 16:40:15 | 显示全部楼层 |阅读模式
winapi1.gif

随便写了个winfrom程序,然后,用windows api去修改软件里面文本框的内容,

winapi如下:

  1. public static class WinAPI
  2.     {
  3.         public const int MOUSEEVENTF_MOVE = 0x0001;    //  移动鼠标
  4.         public const int MOUSEEVENTF_LEFTDOWN = 0x0002;// 模拟鼠标左键按下
  5.         public const int MOUSEEVENTF_LEFTUP = 0x0004; //模拟鼠标左键抬起
  6.         public const int MOUSEEVENTF_RIGHTDOWN = 0x0008; //模拟鼠标右键按下
  7.         public const int MOUSEEVENTF_RIGHTUP = 0x0010;// 模拟鼠标右键抬起
  8.         public const int MOUSEEVENTF_MIDDLEDOWN = 0x0020; //模拟鼠标中键按下
  9.         public const int MOUSEEVENTF_MIDDLEUP = 0x0040; //模拟鼠标中键抬起
  10.         public const int MOUSEEVENTF_ABSOLUTE = 0x8000; //标示是否采用绝对坐标

  11.         public const int WM_GETTEXT = 0x000D;  //13
  12.         public const int WM_SETTEXT = 0x000C; //12
  13.         public const int WM_CLICK = 0x00F5; //245

  14.         [DllImport("user32.dll", EntryPoint = "mouse_event", SetLastError = true)]
  15.         public static extern int mouse_event(int dwFlags, int dx, int dy, int cButtons, int dwExtraInfo);

  16.         //方法声明
  17.         [DllImport("user32.dll")]
  18.         public static extern int SendMessage(IntPtr Handle, int WParam, int LParam);

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

  21.         [DllImport("user32.dll", EntryPoint = "FindWindowEx")]
  22.         public static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);

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

  25.         [DllImport("user32.dll ", EntryPoint = "GetDlgItem")]
  26.         public static extern IntPtr GetDlgItem(IntPtr hParent, int nIDParentItem);

  27.         [DllImport("user32.dll", EntryPoint = "GetWindowText")]
  28.         public static extern int GetWindowText(IntPtr hwnd, StringBuilder lpString, int cch);

  29.         [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
  30.         public static extern int GetWindowTextLength(IntPtr hWnd);

  31.         [DllImport("user32.dll", EntryPoint = "SendMessage", SetLastError = true, CharSet = CharSet.Auto)]
  32.         public static extern int SendMessage(IntPtr hwnd, uint wMsg, int wParam, int lParam);

  33.         [DllImport("user32.dll")]
  34.         public static extern int EnumChildWindows(IntPtr hWndParent, CallBack lpfn, int lParam);
  35.         public delegate bool CallBack(IntPtr hwnd, int lParam);
  36.     }
复制代码


调用代码如下:
游客,如果您要查看本帖隐藏内容请回复


demo下载:

游客,如果您要查看本帖隐藏内容请回复




上一篇:c# 模拟window 操作鼠标|winapi
下一篇:c中的关键字__in 和__in_opt是什么东西啊
码农网,只发表在实践过程中,遇到的技术难题,不误导他人。
发表于 2019-7-9 16:44:06 | 显示全部楼层
本帖最后由 woyaodaili1314 于 2019-7-9 17:59 编辑

现在有两个文本框,名字是一样的,用你的方法只有一个文本框有内容,另外一个是空白的,有什么办法解决吗?@小渣渣
码农网,只发表在实践过程中,遇到的技术难题,不误导他人。
发表于 2018-2-26 15:56:19 | 显示全部楼层
看看                      ~
码农网,只发表在实践过程中,遇到的技术难题,不误导他人。
 楼主| 发表于 2016-10-28 11:03:26 | 显示全部楼层
c# 调用windows api获取文本框内容
http://www.itsvse.com/thread-3288-1-1.html
(出处: 架构师)
码农网,只发表在实践过程中,遇到的技术难题,不误导他人。
发表于 2017-2-7 15:30:32 | 显示全部楼层
真不错,感谢啊。
码农网,只发表在实践过程中,遇到的技术难题,不误导他人。
发表于 2017-3-23 22:50:55 | 显示全部楼层
oooookkkkkkkkkkkkkk
码农网,只发表在实践过程中,遇到的技术难题,不误导他人。
发表于 2017-4-6 19:14:46 | 显示全部楼层
求啊   啊大苏打实打实
码农网,只发表在实践过程中,遇到的技术难题,不误导他人。
发表于 2017-4-18 18:41:42 | 显示全部楼层
兄弟,能不能一次说清楚?
码农网,只发表在实践过程中,遇到的技术难题,不误导他人。
发表于 2017-4-27 12:52:35 | 显示全部楼层
谢谢大师,我找一好久了
码农网,只发表在实践过程中,遇到的技术难题,不误导他人。
发表于 2017-5-27 14:05:45 | 显示全部楼层
不错,值得学习参考
码农网,只发表在实践过程中,遇到的技术难题,不误导他人。
发表于 2017-6-21 18:42:31 | 显示全部楼层
要要要要要要要要要要要
码农网,只发表在实践过程中,遇到的技术难题,不误导他人。
发表于 2017-6-22 14:24:52 | 显示全部楼层
sfdsfsefnsfjklsejflesjg;rjg;dfgdfhhfghhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh
码农网,只发表在实践过程中,遇到的技术难题,不误导他人。
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则

免责声明:
码农网所发布的一切软件、编程资料或者文章仅限用于学习和研究目的;不得将上述内容用于商业或者非法用途,否则,一切后果请用户自负。本站信息来自网络,版权争议与本站无关。您必须在下载后的24个小时之内,从您的电脑中彻底删除上述内容。如果您喜欢该程序,请支持正版软件,购买注册,得到更好的正版服务。如有侵权请邮件与我们联系处理。

Mail To:help@itsvse.com

QQ|小黑屋|架构师 ( 鲁ICP备14021824号-2 )|网站地图

GMT+8, 2026-10-28 23:37

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表