这段脚本的核心用途是:在屏幕坐标和窗口工作区坐标之间进行转换。
F1:: ; 确保当前窗口是目标窗口 hwnd := WinExist("A") ; 屏幕坐标转工作区坐标 ClientPos := ScreenToClient(hwnd, 100, 100) MsgBox % "屏幕坐标转工作区坐标`nx: " ClientPos.x "`ny: " ClientPos.y ; 工作区坐标转屏幕坐标 ScreenPos := ClientToScreen(hwnd, 100, 100) MsgBox % "工作区坐标转屏幕坐标`nx: " ScreenPos.x "`ny: " ScreenPos.y Return ; 工作区坐标转屏幕坐标 ClientToScreen(hWnd, x, y) { VarSetCapacity(lpPoint, 8) NumPut(x, lpPoint, 0, "int") NumPut(y, lpPoint, 4, "int") if !DllCall("User32\ClientToScreen", "ptr", hWnd, "ptr", &lpPoint) return {x: -1, y: -1} ; 错误时返回无效值 x := NumGet(lpPoint, 0, "int") y := NumGet(lpPoint, 4, "int") return {x: x, y: y} } ; 屏幕坐标转工作区坐标 ScreenToClient(hWnd, x, y) { VarSetCapacity(lpPoint, 8) NumPut(x, lpPoint, 0, "int") NumPut(y, lpPoint, 4, "int") if !DllCall("User32\ScreenToClient", "ptr", hWnd, "ptr", &lpPoint) return {x: -1, y: -1} ; 错误时返回无效值 x := NumGet(lpPoint, 0, "int") y := NumGet(lpPoint, 4, "int") return {x: x, y: y} } /* ; 好像返回坐标有问题 F1:: ClientPos := ScreenToClient(WinExist("A"), 100, 100) MsgBox % "屏幕坐标转工作区坐标`nx: " ClientPos.x "`ny: " ClientPos.y ScreenPos := ClientToScreen(WinExist("A"), 100, 100) MsgBox % "工作区坐标转屏幕坐标`nx: "ScreenPos.x "`ny: " ScreenPos.y Return ; 工作区坐标转屏幕坐标 ClientToScreen(hWnd, x, y) { VarSetCapacity(lpPoint, 8) NumPut(x, lpPoint, "int") NumPut(y, lpPoint, 4, "int") DllCall("User32\ClientToScreen", "ptr", hwnd, "ptr", &lpPoint, "int") x := NumGet(lpPoint, 0, "int") y := NumGet(lpPoint, 4, "int") return {x: x, y: y} } ; 屏幕坐标转工作区坐标 ScreenToClient(hWnd, x, y) { VarSetCapacity(lpPoint, 8) NumPut(x, lpPoint, "int") NumPut(y, lpPoint, 4, "int") DllCall("User32\ScreenToClient", "ptr", hwnd, "ptr", &lpPoint, "int") x := NumGet(lpPoint, 0, "int") y := NumGet(lpPoint, 4, "int") return {x: x, y: y} } */
声明:站内资源为整理优化好的代码上传分享与学习研究,如果是开源代码基本都会标明出处,方便大家扩展学习路径。请不要恶意搬运,破坏站长辛苦整理维护的劳动成果。本站为爱好者分享站点,所有内容不作为商业行为。如若本站上传内容侵犯了原著者的合法权益,请联系我们进行删除下架。
评论(0)