大漠插件:3.1233

找图,找色,识字,找字,窗口,按鼠标,按键盘

0、注册dm.dll;

regsvr32 xxx\dm.dll

1、添加com引用;

2、dmsoft各种调用;

原理:

查找窗口hwnd→窗口激活→添加消息到文本框→回车→窗口取消激活

截图:

 

代码:

  1. 1 class Form1 : Form
  2. 2 {
  3. 3 public Form1()
  4. 4 {
  5. 5 var dm = new dmsoft();
  6. 6 Console.WriteLine($"大漠插件{dm.Ver()}");
  7. 7 Console.WriteLine($"{Application.ProductName}-{Application.ProductVersion}");
  8. 8
  9. 9 ClientSize = new Size(600, 400);
  10. 10 MaximizeBox = false;
  11. 11 FormBorderStyle = FormBorderStyle.FixedSingle;
  12. 12
  13. 13 var listView1 = new ListView() {Name = "lstView1", Location = new Point(0, 0), Size = new Size(300, this.ClientRectangle.Height), Columns = {"句柄", "标题", "类名"}, BackColor = Color.Cornsilk, FullRowSelect = true, GridLines = true, View = View.Details, CheckBoxes = true, MultiSelect = true,};
  14. 14 var btnReload = new Button() {Name = "btnReload", Text = "刷新(&R)", Location = new Point(300, 3), AutoSize = true};
  15. 15 var btnSend = new Button() {Name = "btnSend", Text = "发送(&S)", Location = new Point(400, 3), AutoSize = true};
  16. 16 var txtMessage = new TextBox() {Name = "txtMessage", Text = "hello world!", Location = new Point(300, 30), Size = new Size(this.Width - 300, ClientRectangle.Height - 30), Multiline = true};
  17. 17 this.Controls.AddRange(new Control[] {listView1, btnReload, btnSend, txtMessage});
  18. 18 this.Text = $"{ProductName}-{ProductVersion}";
  19. 19
  20. 20 btnReload.Click += (sender, args) =>
  21. 21 {
  22. 22 var hwnds = new List<int>();
  23. 23 var classNames = "TXGuiFoundation,ChatWnd".Split(\',\');
  24. 24 foreach (var className in classNames)
  25. 25 {
  26. 26 var win = dm.EnumWindow(0, "", className, 18);
  27. 27 hwnds.AddRange(win.Split(\',\').Where(x => !string.IsNullOrEmpty(x)).Select(x => Convert.ToInt32(x)));
  28. 28 }
  29. 29
  30. 30 listView1.BeginUpdate();
  31. 31 listView1.Items.Clear();
  32. 32 foreach (var hwnd in hwnds)
  33. 33 {
  34. 34 listView1.Items.Add(hwnd.ToString()).SubItems
  35. 35 .AddRange(new string[] {dm.GetWindowTitle(hwnd), dm.GetWindowClass(hwnd)});
  36. 36 }
  37. 37
  38. 38 listView1.EndUpdate();
  39. 39 };
  40. 40 btnSend.Click += (sender, args) =>
  41. 41 {
  42. 42 var msg = txtMessage.Text;
  43. 43 foreach (ListViewItem item in listView1.CheckedItems)
  44. 44 {
  45. 45 var hwnd = Convert.ToInt32(item.Text);
  46. 46 Console.WriteLine($"SendMessage To {item.SubItems[0].Text}");
  47. 47 dm.BindWindowEx(hwnd, "gdi", "windows", "windows", "", 0);
  48. 48 dm.SetWindowState(hwnd, 1);
  49. 49 dm.SetWindowState(hwnd, 8);
  50. 50 dm.SendString2(hwnd, msg);
  51. 51 dm.KeyDown(13);
  52. 52 dm.KeyUp(13);
  53. 53 dm.SetWindowState(hwnd, 9);
  54. 54 dm.SetWindowState(hwnd, 2);
  55. 55 dm.UnBindWindow();
  56. 56 }
  57. 57 };
  58. 58 this.Load += (sender, args) => { btnReload.PerformClick(); };
  59. 59 }
  60. 60 }

 

版权声明:本文为Running_Zhang原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/Running_Zhang/p/11388381.html