Skip to content

Instantly share code, notes, and snippets.

@maul-esel
Created October 3, 2012 21:23
Show Gist options
  • Save maul-esel/3829941 to your computer and use it in GitHub Desktop.
Save maul-esel/3829941 to your computer and use it in GitHub Desktop.
a function to convert client-area-relative cooordinates to window-relative coordinates
ClientToWindow(hwnd, byRef x, byRef y)
{
VarSetCapacity(pt, 8, 0)
, NumPut(x, pt, 0, "UInt")
, NumPut(y, pt, 4, "UInt")
if (!DllCall("ClientToScreen", "Ptr", hwnd, "Ptr", &pt, "UInt"))
return false
VarSetCapacity(rc, 16, 0)
if (!DllCall("GetWindowRect", "Ptr", hwnd, "Ptr", &rc, "UInt"))
return false
screen_x := NumGet(pt, 0, "UInt")
, screen_y := NumGet(pt, 4, "UInt")
win_x := NumGet(rc, 0, "UInt")
, win_y := NumGet(rc, 4, "UInt")
x := screen_x - win_x
, y := screen_y - win_y
return true
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment