private void MouseHook_OnMouseUp(object sender, Point p) { //Point GetMousePos = Mouse.GetPosition(App.Current.MainWindow); //Name = System.Windows.Forms.Cursor.Position.X + "," + System.Windows.Forms.Cursor.Position.Y; MouseHook.SystemParametersInfo((uint)MouseHook.SystemParametersDesktopInfo.SPI_SETCURSORS, 0, IntPtr.Zero, (uint)MouseHook.SystemParametersDesktopInfo.SPIF_SENDWININICHANGE); MouseHook.OnMouseUp -= MouseHook_OnMouseUp; //Name = Control.MousePosition.X + "," + Control.MousePosition.Y; var handle = MouseHook.WindowFromPoint(new POINT(Control.MousePosition.X, Control.MousePosition.Y)); var title = new StringBuilder(256); User32Window.GetWindowText(handle, title, title.Capacity);//得到窗口的标题 var className = new StringBuilder(256); User32Window.GetClassName(handle, className, className.Capacity);//得得到窗口的句柄 类名 //SelectWindow.Title = title.ToString(); //SelectWindow.ClassName = className.ToString(); User32Window.GetWindowThreadProcessId(handle, out int pid); //SelectWindow.Process = Process.GetProcessById(pid); SelectWindow = new HandleWindow { Title = title.ToString(), ClassName = className.ToString(), Handle = handle, Process = Process.GetProcessById(pid) }; }
/// <summary> register the event of the inner window. </summary> private void AssignWindow() { Window = new HandleWindow(); Window.KeyPressed += delegate(object sender, KeyPressedEventArgs args) { if (KeyPressed != null) { KeyPressed(this, args); } }; }