public static Point TransferCoordinate(IntPtr hwnd, int loc_x, int loc_y) { RECT rc = new RECT(); MouseKeyHook.GetWindowRect(hwnd, ref rc); int width = rc.Right - rc.Left; //窗口的宽度 int height = rc.Bottom - rc.Top; //窗口的高度 int x = rc.Left; int y = rc.Top; if (loc_x > width || loc_y > height) { throw new Exception("警告,窗口大小小于设定值!"); } return(new Point(x + loc_x, y + loc_y)); }
private void OnMouseClick(object sender, MouseEventArgs e) { clickElf.targetWinInfo.TargetWindowHandle = MouseKeyHook.GetForegroundWindow(); RECT rc = new RECT(); MouseKeyHook.GetWindowRect(clickElf.targetWinInfo.TargetWindowHandle, ref rc); int x = rc.Left; int y = rc.Top; clickElf.targetWinInfo.WindowPosition = new Point(e.X - x, e.Y - y);; StringBuilder s = new StringBuilder(512); int i = MouseKeyHook.GetWindowText(clickElf.targetWinInfo.TargetWindowHandle.ToInt32(), s, s.Capacity); clickElf.targetWinInfo.TargetWindowTitle = s.ToString(); UpdateInfo(); Unsubscribe(); }