Jump to content
Sign in to follow this  

ScreenToClient offset

Recommended Posts


I'm trying to convert mouse position into MS Publisher's Document coordinates

but my mouse is like 50 to 100 points off from the place it should be

What I'm doing wrong? Maybe I need some conversion? Like PointsToPixels?


Local $tpoint = DllStructCreate("int X;int Y")

DllStructSetData($tpoint, "X", $pos[0])

DllStructSetData($tpoint, "Y", $pos[1])

_WinAPI_ScreenToClient($oPublisherObj.Activewindow.hwnd, $tPoint)

$X1Pos=DllStructGetData($tpoint, "X");

$Y1Pos=DllStructGetData($tpoint, "Y");


Share this post

Link to post
Share on other sites


Your code looks correct. This is something I wrote to answer another question some time ago which uses the same function (you need AutoIt Help open so you can click in it):

#include <Misc.au3>
#include <WinAPI.au3>


Func _Convert_Coordinates()

    Local $tPoint = DllStructCreate("int X;int Y")
    Local $aCoords

    Local $dll = DllOpen("user32.dll")

    While 1

        If _Ispressed("01", $dll) = 1 Then
            $aCoords = MouseGetPos()
            ConsoleWrite("Screen coords: " & $aCoords[0] & " - " & $aCoords[1] & @CRLF)



    WinActivate("AutoIt Help")
    WinWaitActive("AutoIt Help")
    Local $hWnd = WinGetHandle("AutoIt Help")

    DllStructSetData($tPoint, "X", $aCoords[0])
    DllStructSetData($tPoint, "Y", $aCoords[1])

    _WinAPI_ScreenToClient($hWnd, $tPoint)

    $aCoords[0] = DllStructGetData($tPoint, "X")
    $aCoords[1] = DllStructGetData($tPoint, "Y")

    ConsoleWrite("Client coords: " & $aCoords[0] & " - " & $aCoords[1] & @CRLF)


Two things spring to mind (bear in mind I am not at all familiar with the app you are using! :huggles: ):

1. Does the active window of MS Publisher which you are using have coordinates which start 0,0 in the top left corner?

2. Is $oPublisherObj.Activewindow.hwnd actually giving you the handle of the window you want? (You can check this with the Au3 Window Info Tool)

Sorry I cannot be of more help - I hope one of these suggestions does the trick. :D


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:


ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area


Share this post

Link to post
Share on other sites

I'm doing custom resizing

on Alt+1 it grabs left top corner of my object and should drag it with mouse cursor til I click Alt+1 again

I guess I'm missing conversion from Client mouse position into Document points/objects position


Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this