在最小化中获取鼠标点击坐标 window
Get mouse click coordinates in a minimized window
我正在尝试以最小化的方式自动执行鼠标点击 window。
由于我的 screen/desktop 坐标与 process/window 坐标不同,我遇到了问题。
这是我正在测试的代码:
Function MakeDWord(LoWord As Integer, HiWord As Integer) As Long
Return New IntPtr((HiWord << 16) Or (LoWord And &HFFFF))
End Function
SendMessage(_targetProcess.MainWindowHandle, WM_LBUTTONDOWN, 0&, MakeDWord(x, y))
SendMessage(_targetProcess.MainWindowHandle, WM_LBUTTONUP, 0&, MakeDWord(x, y))
代码正在运行,它将鼠标点击发送到所需的 window,但不是正确的坐标。
所以,我需要找到我想要点击的window区域的相对坐标,而不是desktop/screen坐标。
有什么方法可以检测发送到 process/window 的事件以获得相对坐标?
例如,在 Visual Studio 中有一个名为 spy++ 的工具可以工作,但现在我没有将点击发送到我自己的应用程序。
ScreenToClient 函数解决了这个问题:
https://pinvoke.net/default.aspx/user32/ScreenToClient.html
RECT rct;
POINT topLeft;
POINT bottomRight;
/** Getting a windows position **/
GetWindowRect(hWnd, out rct);
/** assign RECT coods to POINT **/
topLeft.X = rct.Left;
topLeft.Y = rct.Top;
bottomRight.X = rct.Right;
bottomRight.Y = rct.Bottom;
/** this takes the POINT, which is using screen coords (0,0 in top left screen) and converts them into coords inside specified window (0,0 from top left of hWnd) **/
ScreenToClient(hWnd, ref topLeft);
ScreenToClient(hWnd, ref bottomRight);
int width = bottomRight.X - topLeft.X;
int height = bottomRight.Y - topLeft.Y;
Rectangle R = new Rectangle(topLeft.X, topLeft.Y, width, height);
我正在尝试以最小化的方式自动执行鼠标点击 window。
由于我的 screen/desktop 坐标与 process/window 坐标不同,我遇到了问题。
这是我正在测试的代码:
Function MakeDWord(LoWord As Integer, HiWord As Integer) As Long
Return New IntPtr((HiWord << 16) Or (LoWord And &HFFFF))
End Function
SendMessage(_targetProcess.MainWindowHandle, WM_LBUTTONDOWN, 0&, MakeDWord(x, y))
SendMessage(_targetProcess.MainWindowHandle, WM_LBUTTONUP, 0&, MakeDWord(x, y))
代码正在运行,它将鼠标点击发送到所需的 window,但不是正确的坐标。
所以,我需要找到我想要点击的window区域的相对坐标,而不是desktop/screen坐标。
有什么方法可以检测发送到 process/window 的事件以获得相对坐标?
例如,在 Visual Studio 中有一个名为 spy++ 的工具可以工作,但现在我没有将点击发送到我自己的应用程序。
ScreenToClient 函数解决了这个问题:
https://pinvoke.net/default.aspx/user32/ScreenToClient.html
RECT rct;
POINT topLeft;
POINT bottomRight;
/** Getting a windows position **/
GetWindowRect(hWnd, out rct);
/** assign RECT coods to POINT **/
topLeft.X = rct.Left;
topLeft.Y = rct.Top;
bottomRight.X = rct.Right;
bottomRight.Y = rct.Bottom;
/** this takes the POINT, which is using screen coords (0,0 in top left screen) and converts them into coords inside specified window (0,0 from top left of hWnd) **/
ScreenToClient(hWnd, ref topLeft);
ScreenToClient(hWnd, ref bottomRight);
int width = bottomRight.X - topLeft.X;
int height = bottomRight.Y - topLeft.Y;
Rectangle R = new Rectangle(topLeft.X, topLeft.Y, width, height);