大漠插件:3.1233
0、注册dm.dll;
1、添加com引用;
2、dmsoft各种调用;
原理:
查找窗口hwnd→窗口激活→添加消息到文本框→回车→窗口取消激活
截图:
代码:
1 class Form1 : Form 2 { 3 public Form1() 4 { 5 var dm = new dmsoft(); 6 Console.WriteLine(Resources.Form1_Form1_, dm.Ver()); 7 8 ClientSize = new Size(600, 400); 9 MaximizeBox = false; 10 FormBorderStyle = FormBorderStyle.FixedSingle; 11 12 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,}; 13 var btnReload = new Button() {Name = "btnReload", Text = Resources.Form1_Form1__刷新__R_, Location = new Point(300, 3), AutoSize = true}; 14 var btnSend = new Button() {Name = "btnSend", Text = Resources.Form1_Form1__发送__S_, Location = new Point(400, 3), AutoSize = true}; 15 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}; 16 this.Controls.AddRange(new Control[] {listView1, btnReload, btnSend, txtMessage}); 17 this.Text = string.Format(Resources.Form1_Form1__0___1_, this.ProductName, this.ProductVersion); 18 19 btnReload.Click += (sender, args) => 20 { 21 var hwnds = new List<int>(); 22 var classNames = "TXGuiFoundation,ChatWnd".Split(','); 23 foreach (var className in classNames) 24 { 25 var win = dm.EnumWindow(0, "", className, 18); 26 hwnds.AddRange(win.Split(',').Where(x => !string.IsNullOrEmpty(x)).Select(x => Convert.ToInt32(x))); 27 } 28 29 listView1.BeginUpdate(); 30 listView1.Items.Clear(); 31 foreach (var hwnd in hwnds) 32 { 33 listView1.Items.Add(hwnd.ToString()).SubItems 34 .AddRange(new string[] {dm.GetWindowTitle(hwnd), dm.GetWindowClass(hwnd)}); 35 } 36 37 listView1.EndUpdate(); 38 }; 39 btnSend.Click += (sender, args) => 40 { 41 var msg = txtMessage.Text; 42 foreach (ListViewItem item in listView1.CheckedItems) 43 { 44 var hwnd = Convert.ToInt32(item.Text); 45 Console.WriteLine(Resources.Form1_Form1_SendMessage_To__0_, item.SubItems[0].Text); 46 dm.BindWindowEx(hwnd, "gdi", "windows", "windows", "", 0); 47 dm.SetWindowState(hwnd, 1); 48 dm.SetWindowState(hwnd, 8); 49 dm.SendString2(hwnd, msg); 50 dm.KeyDown(13); 51 dm.KeyUp(13); 52 dm.SetWindowState(hwnd, 9); 53 dm.SetWindowState(hwnd, 2); 54 dm.UnBindWindow(); 55 } 56 }; 57 58 btnReload.PerformClick(); 59 } 60 }