Task

Get the current location of the mouse cursor relative to the active window.

Please specify if the window may be externally created.




    nomainwin
 
    UpperLeftX = DisplayWidth-WindowWidth
    UpperLeftY = DisplayHeight-WindowHeight
 
    struct point, x as long, y as long
 
    stylebits #main.st ,0,0,_WS_EX_STATICEDGE,0
    statictext #main.st "",16,16,100,26
 
    stylebits #main ,0,0,_WS_EX_TOPMOST,0
    open "move your mouse" for window_nf as #main
 
    #main "trapclose [quit]"
    timer 100, [mm]
    wait
 
[mm]
    CallDll #user32, "GetForegroundWindow", WndHandle as uLong
    #main.st CursorPos$(WndHandle)
    wait
 
[quit]
    close #main
    end
 
function CursorPos$(handle)
    Calldll #user32, "GetCursorPos",_
        point as struct,_
        result as long
    Calldll #user32, "ScreenToClient",_
        handle As Ulong,_
        point As struct,_
        result as long
    x = point.x.struct
    y = point.y.struct
    CursorPos$=x; ",";y
end function