【发布时间】:2020-11-01 15:49:23
【问题描述】:
我有 2 个窗口,可以是不同大小/不同位置。 最终目标是能够在某个位置点击窗口A,并在同一点相对发送点击窗口B。
这是一个解释我想要实现的目标的屏幕:
现在我可以找回:
- 窗口 A 把手/矩形
- 窗口 B 手柄/矩形
- 屏幕上的光标位置
我听说过ScreenToClient/ClientToScreen,我知道我需要找到点击窗口A时的相对鼠标位置,并将点击相对发送到窗口B
另外,发送我的按钮点击我使用:
SendMessage(character.MainWindowHandle, 0x201, IntPtr.Zero, CreateParams(?,?);
SendMessage(character.MainWindowHandle, 0x202, IntPtr.Zero, CreateParams(?,?);
我需要找到两个问号
我现在的代码:
var windowAHandle = Win32Api.GetForegroundWindow();
var windowARect = Win32Api.GetWindowRectangle(windowAHandle);
var windowB = PersosEnLigne.First(w => w.Nom == "Character 2");
var windowBRect = Win32Api.GetWindowRectangle(windowB.Process.MainWindowHandle);
var ptTopLeft = new Win32Api.POINT();
var ptBottomRight = new Win32Api.POINT();
ptTopLeft.x = windowARect.Left;
ptTopLeft.y = windowARect.Top;
ptBottomRight.x = windowARect.Right;
ptBottomRight.y = windowARect.Bottom;
Win32Api.ScreenToClient(windowB.MainWindowHandle, ref ptTopLeft);
Win32Api.ScreenToClient(windowB.MainWindowHandle, ref ptBottomRight);
//I'm not even sure if I need to use ScreenToClient or ClientToScreen
【问题讨论】:
-
这能回答你的问题吗? How to get window's position?
-
剩下的就是数学
-
问题在于数学,我找不到我应该计算的内容。 (我从 2 天就开始了,我的大脑已经累了抱歉)
-
@andI'msureI'mmissingsome 该链接对我没有帮助,因为我已经知道如何使窗口正确
-
@user3673720 请将您的尝试添加到问题中 - 您没有显示任何相关代码。你的计算到底有什么问题?请澄清。
标签: c#