1、相关声明函数,SendMessage可定义两种格式。

[DllImport("User32.DLL", CharSet = CharSet.Auto)]
public static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);

[DllImport("User32.dll")]
private static extern IntPtr FindWindow(string lpClassName, string lpWindowName);

[DllImport("User32.DLL")]
public static extern int SendMessage(IntPtr hWnd, uint Msg, uint wParam, uint lParam);
[DllImport("User32.DLL")]
public static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam, string lParam);

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

2、相关消息

public const uint WM_SETTEXT = 0x000C;

public const uint WM_CHAR = 0x0102;

public const uint EM_SETSEL = 0x00B1;

3、
用spy++观察是哪个窗口处理消息,然后用FindWindow找到窗口句柄
IntPtr main = FindWindow("TFrmMain", null);


自己启动,比如记事本
Process vProcess = Process.Start("notepad.exe");
while (vProcess.MainWindowHandle == IntPtr.Zero) vProcess.Refresh();
注:启动之后可以直接发键值
SendKeys.Send("01234/n");SendKeys.Send("56789/n");


枚举所有进程
Process[] vP2 = Process.GetProcesses();

用FindWindowEx找子窗口句柄,一层层找下去。
IntPtr panel1 = FindWindowEx(main, IntPtr.Zero, "TPanel", null);
IntPtr panel2 = FindWindowEx(panel1, IntPtr.Zero, "TPanel", null);

如果有多个同类子窗口,FindWindowEx第二个参数,控制从哪个子窗口开始找何开始找。
IntPtr edit1 = FindWindowEx(panel2, (IntPtr)null, "TEdit", null);
IntPtr edit2 = FindWindowEx(panel2, edit1, "TEdit", null);

逐个发消息
SendMessage(edit1, WM_CHAR, (uint)Keys.F3, 0);

用循环发
string end="hello";
for(int i=0;i<5;i++)
  SendMessage(edit1, WM_CHAR, (uint)end[i], 0);

发字符串
SendMessage(vHandle, WM_SETTEXT, IntPtr.Zero, "测试/r/n换行");

选中7个文本
SendMessage(vHandle, EM_SETSEL, 0, 7);

最新文章

  1. java并发控制:lock
  2. 如何在SqlServer中获取前端连接的IP地址,计算机名等信息
  3. c# Dictionary的遍历和排序
  4. 【linux】find删除指定时间之前的文件
  5. Servlet 获取 ApplicationContext
  6. android如何获取到启动类的包和类路径
  7. 【转】关于loadrunner中设置进程和线程的区别
  8. 关于String和StringBuffer的使用
  9. linux中的文件结构
  10. sublime Text3快捷键使用大全
  11. 一套代码小程序&amp;Web&amp;Native运行的探索07——mpvue简单调研
  12. 【细语】C#之扩展方法原理及其使用
  13. jpa数据库表实体命名规则 Unknown column &#39;user0_.create_time&#39; in &#39;field list&#39;
  14. 初学C的感想
  15. Nexus私服搭建
  16. git常见用法介绍
  17. nginx介绍(三) - 虚拟主机
  18. MyBatis基础入门《十八》动态SQL(if-where)
  19. Git简单操作命令
  20. ThinkPHP5自定义分页样式

热门文章

  1. opentsdb basic install
  2. BZOJ1500: [NOI2005]维修数列[splay ***]
  3. 1.认识EJB
  4. 第1章 重构,第一个案例(3):运用多态取代switch
  5. 使用scrollpagination实现页面底端自动加载无需翻页功能
  6. 错误提示:LINK : fatal error LNK1123: failure during conversion to COFF: file invalid or corrupt 的解决方法
  7. CSS中不为人知Zoom属性的使用介绍(IE私有属性)
  8. 通过接口实现JAVA和.NET互调用-JNInterface
  9. 10 行 Python 代码写的模糊查询
  10. 【OpenJudge 8463】Stupid cat &amp; Doge