private void button2_Click(object sender, EventArgs e) { Thread.Sleep(2000); var hwnd = dmsoft.GetForegroundWindow(); if (hwnd == 0) { rtb_message.AppendText("找不到窗口句柄\r\n"); return; } string title = dmsoft.GetWindowTitle(hwnd); BindWindowEx bindWindowEx = new BindWindowEx() { Display = "normal", Mouse = "normal", Keypad = "normal", Public = "", Mode = 0 }; bool res = dmsoft.BindWindowEx(hwnd, bindWindowEx); if (res) { rtb_message.AppendText($"绑定窗口 {title} 成功"); return; } else { rtb_message.AppendText($"绑定窗口 {title} 失败"); return; } }
// 绑定模拟器 public void BindEmu() { int top_Hwnd = dm.FindWindow("", game); GameMsg("顶层句柄为:" + top_Hwnd.ToString()); string child_Hwnd = dm.EnumWindow(top_Hwnd, "", "", 4); GameMsg("子句柄为:" + child_Hwnd); int dm_ret = dm.BindWindowEx(int.Parse(child_Hwnd), "dx.graphic.opengl", "windows", "windows", "", 0); if (dm_ret == 1) { GameMsg("绑定成功"); } else { GameMsg("绑定失败" + "错误代码:" + dm_ret.ToString()); } }
/// <summary> /// 绑定指定的窗口,并指定这个窗口的屏幕颜色获取方式,鼠标仿真模式,键盘仿真模式 高级用户使用. /// </summary> /// <param name="dmsoft"></param> /// <param name="hwnd"></param> /// <param name="bindWindow"></param> /// <returns></returns> public static bool BindWindowEx(this dmsoft dmsoft, int hwnd, BindWindowEx bindWindow) { return(dmsoft.BindWindowEx(hwnd, bindWindow.Display, bindWindow.Mouse, bindWindow.Keypad, bindWindow.Public, bindWindow.Mode) == 1); }
public int BindWindowEx(int hwnd, string display = "gdi", string mouse = "windows", string keypad = "windows", string public_desc = "", int mode = 0) { return(dm.BindWindowEx(hwnd, display, mouse, keypad, public_desc, mode)); }