Jex Posted November 30, 2007 Share Posted November 30, 2007 (edited) How can i find client position? That question looking easy but i can't find solution..WinGetPos giving window position and i can't add + pixel for find client position because have menu and if im use another Windows skin that client position will be not true.ControlGetPos giving window relative coordinate and that mean X=0 Y=0I need WinGetClientPos I'm tried AutoItSetOptions too but still can't find Window Client pos..I need find client position for my Image Editor.Edit : I'm found GetClientRect Function ( http://msdn2.microsoft.com/en-us/library/ms633503.aspx ) Edited November 30, 2007 by Jex My scripts : Immediate Window , My Web Browser , Travian , Text Effect , Characters & Words per minute or second , Image Editor (ImageMagick) , Matrix style background effect ( Screensaver ) , Mail Sender , Protectlinks decoder and Rapidshare links checker , Fonts Fetcher , Region determine , Compare pictures , Gradient color box , Mouse Coordinates, Colors, Pixel Search things , Encrypt/Decrypt and embeding file in jpeg thing , Hard disk space monitor , Reflex game , Multiplayer Tic Tac Toe , WLM ( MSN ) personal message changer Link to comment Share on other sites More sharing options...
Fossil Rock Posted November 30, 2007 Share Posted November 30, 2007 I'm not sure if this will help but look into Opt("MouseCoordMode", 2).Sets the way coords are used in the mouse functions, either absolute coords or coords relative to the current active window:0 = relative coords to the active window1 = absolute screen coordinates (default)2 = relative coords to the client area of the active window Agreement is not necessary - thinking for one's self is! Link to comment Share on other sites More sharing options...
Jex Posted November 30, 2007 Author Share Posted November 30, 2007 (edited) Func WinGetClientPos($Handle) $hwnd = WinGetHandle($Handle) $cPos = DllStructCreate("long;long;long;long") DllCall("user32.dll", "int", "GetClientRect", "hwnd", $hwnd, "ptr", DllStructGetPtr($cPos)) Dim $cPos2[4] = [DllStructGetData($cPos, 1), DllStructGetData($cPos, 2), DllStructGetData($cPos, 3), DllStructGetData($cPos, 4)] Return $cPos2 EndFunc Giving client relative coordinate Buffy opts not help. Edit : Now im see Autoit have that function ( _WinAPI_GetClientRect ) Edit2 : I'm said Buffy but your nick Fossil Rock ?! Edited November 30, 2007 by Jex My scripts : Immediate Window , My Web Browser , Travian , Text Effect , Characters & Words per minute or second , Image Editor (ImageMagick) , Matrix style background effect ( Screensaver ) , Mail Sender , Protectlinks decoder and Rapidshare links checker , Fonts Fetcher , Region determine , Compare pictures , Gradient color box , Mouse Coordinates, Colors, Pixel Search things , Encrypt/Decrypt and embeding file in jpeg thing , Hard disk space monitor , Reflex game , Multiplayer Tic Tac Toe , WLM ( MSN ) personal message changer Link to comment Share on other sites More sharing options...
PsaltyDS Posted November 30, 2007 Share Posted November 30, 2007 (edited) Another way to do that UDF, just for fun: expandcollapse popup#include <array.au3> $PID = Run("Notepad.exe") WinWait("Untitled - Notepad") $hNotepad = WinGetHandle("Untitled - Notepad") $avResult = _WinGetClientPos($hNotepad) _ArrayDisplay($avResult, "Client Pos (Relative)") $avResult = _WinGetClientPos($hNotepad, 1) _ArrayDisplay($avResult, "Client Pos (Absolute)") ProcessClose($PID) ; Returns X/Y coord of client are, absolute to the desktop if $fAbsolute <> 0 Func _WinGetClientPos($hWin, $fAbsolute = 0) If Not WinActivate($hWin) Then Return SetError(1, 0, 0) Local $cPos = DllStructCreate("long;long;long;long") DllCall("user32.dll", "int", "GetClientRect", "hwnd", $hWin, "ptr", DllStructGetPtr($cPos)) Local $cPos2[4] = [DllStructGetData($cPos, 1), DllStructGetData($cPos, 2), DllStructGetData($cPos, 3), DllStructGetData($cPos, 4)] If $fAbsolute Then WinActivate($hWin) WinWaitActive($hWin) Local $MousePosSav = MouseGetPos() Local $MouseModeSav = Opt("MouseCoordMode", 2) MouseMove(0, 0, 0) Opt("MouseCoordMode", 1) Local $avRET = MouseGetPos() Opt("MouseCoordMode", $MouseModeSav) MouseMove($MousePosSav[0], $MousePosSav[1], 0) $cPos2[0] = $avRET[0] $cPos2[1] = $avRET[1] $cPos2[2] = $avRET[0] + $cPos2[2] $cPos2[3] = $avRET[1] + $cPos2[3] EndIf Return $cPos2 EndFunc ;==>_WinGetClientPos Edited November 30, 2007 by PsaltyDS Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
Jex Posted December 1, 2007 Author Share Posted December 1, 2007 (edited) PsaltyDS very thanks that method working but have problems. $Timer = TimerInit() $Position = _WinGetClientPos(WinGetHandle($GUI), 1) MsgBox("", "", Round(TimerDiff($Timer), 0) & "ms") +1000ms and i can't loop that function because moving mouse every loop. I need find better way for get client position Edited December 1, 2007 by Jex My scripts : Immediate Window , My Web Browser , Travian , Text Effect , Characters & Words per minute or second , Image Editor (ImageMagick) , Matrix style background effect ( Screensaver ) , Mail Sender , Protectlinks decoder and Rapidshare links checker , Fonts Fetcher , Region determine , Compare pictures , Gradient color box , Mouse Coordinates, Colors, Pixel Search things , Encrypt/Decrypt and embeding file in jpeg thing , Hard disk space monitor , Reflex game , Multiplayer Tic Tac Toe , WLM ( MSN ) personal message changer Link to comment Share on other sites More sharing options...
PsaltyDS Posted December 1, 2007 Share Posted December 1, 2007 PsaltyDS very thanks that method working but have problems. expandcollapse popup$Timer = TimerInit() $Position = _WinGetClientPos(WinGetHandle($GUI), 1) MsgBox("", "", Round(TimerDiff($Timer), 0) & "ms")oÝ÷ ÛítÓI¬jwbq©÷öÙh¢aj×îËb¢vÞq«¬zj/x&¢ëz÷«ÊZ(¤Þy×âÖ޶׫Á¬¢¸µÉbz{i¢Èÿªê-xbçl¢g¨~Ø^¥ªí±©Ý~§v+pjËaz·ªº*Þéí¶§²êÞ¶«z«¢çpwhìiËb½ëajÛh¢F¥Ø^¶)N¬½êìåy«Þ²ØZ¶êm¢Ø^r^©"ayÆ¥©Ýêeë"i¢X¬yÊ+ë,jëh×6#include <array.au3> $PID = Run("Notepad.exe") WinWait("Untitled - Notepad") $hNotepad = WinGetHandle("Untitled - Notepad") WinActivate($hNotepad) WinWaitActive($hNotepad) $iTimer = TimerInit() $avResult = _WinGetClientPos() ; Relative _ArrayDisplay($avResult, "Client Pos (Relative) in " & Round(TimerDiff($iTimer) / 1000, 3) & "secs") Sleep(2000) $iTimer = TimerInit() $avResult = _WinGetClientPos(1) ; Absolute (to desktop) _ArrayDisplay($avResult, "Client Pos (Absolute) in " & Round(TimerDiff($iTimer) / 1000, 3) & "secs") ProcessClose($PID) ; Returns X/Y coord of client area of the active window; absolute to the desktop if $fAbsolute <> 0 Func _WinGetClientPos($fAbsolute = 0) Local $cPos = DllStructCreate("long;long;long;long"), $hWin = WinGetHandle("") DllCall("user32.dll", "int", "GetClientRect", "hwnd", $hWin, "ptr", DllStructGetPtr($cPos)) Local $cPos2[4] = [DllStructGetData($cPos, 1), DllStructGetData($cPos, 2), DllStructGetData($cPos, 3), DllStructGetData($cPos, 4)] If $fAbsolute Then Local $MousePosSav = MouseGetPos() Local $MouseModeSav = Opt("MouseCoordMode", 2) MouseMove(0, 0, 0) Opt("MouseCoordMode", 1) Local $avRET = MouseGetPos() Opt("MouseCoordMode", $MouseModeSav) MouseMove($MousePosSav[0], $MousePosSav[1], 0) $cPos2[0] = $avRET[0] $cPos2[1] = $avRET[1] $cPos2[2] = $avRET[0] + $cPos2[2] $cPos2[3] = $avRET[1] + $cPos2[3] EndIf Return $cPos2 EndFunc ;==>_WinGetClientPos I can't help you with the mouse movement. The fuction moves the mouse exactly twice, at speed = 0 (instantaneous), and puts the both the mouse mode and mouse pos where they were before it started. This all happens too fast to see on my computer. Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
Jex Posted December 2, 2007 Author Share Posted December 2, 2007 (edited) Very thanks now working instantly I'm changed code and now find client coordinate and size in 0ms ( _WinGetClientPos find in 1 or 2 ms ) and not need move mouse. Just in startup use that "Global $Client = _WinGetClientPos(1)" ( I mean after created GUI ) and later use "GetClientPos("Title")" I think that method can find coordinates 100% true, if Windows Skin not changed but i'm not sure. expandcollapse popup#include <Array.au3> $tNotepad = "Untitled - Notepad" $PID = Run("Notepad.exe") WinWait($tNotepad) $hNotepad = WinGetHandle($tNotepad) WinActivate($hNotepad) WinWaitActive($hNotepad) Global $Client = _WinGetClientPos(1) $iTimer = TimerInit() $ClientPos = GetClientPos($tNotepad) _ArrayDisplay($ClientPos, "Client position and size found in " & Round(TimerDiff($iTimer), 0) & "ms") ProcessClose($PID) Func GetClientPos($wTitle = "") Local $cPos[6] $wPos = WinGetPos($wTitle) $cPos[0] = $wPos[0] + $Client[0] $cPos[1] = $wPos[1] + $Client[1] $cPos[2] = ($wPos[0] + $wPos[2]) - $Client[2] $cPos[3] = ($wPos[1] + $wPos[3]) - $Client[3] $cPos[4] = $cPos[2] - $cPos[0] $cPos[5] = $cPos[3] - $cPos[1] Return $cPos EndFunc ;==>GetClientPos Func _WinGetClientPos($fAbsolute = 0) Local $cPos = DllStructCreate("long;long;long;long"), $hWin = WinGetHandle("") DllCall("user32.dll", "int", "GetClientRect", "hwnd", $hWin, "ptr", DllStructGetPtr($cPos)) Local $cPos2[4] = [DllStructGetData($cPos, 1), DllStructGetData($cPos, 2), DllStructGetData($cPos, 3), DllStructGetData($cPos, 4)] If $fAbsolute Then Local $MousePosSav = MouseGetPos() Local $MouseModeSav = Opt("MouseCoordMode", 2) MouseMove(0, 0, 0) Opt("MouseCoordMode", 1) Local $avRET = MouseGetPos() Opt("MouseCoordMode", $MouseModeSav) MouseMove($MousePosSav[0], $MousePosSav[1], 0) $wPos = WinGetPos("") $cPos2[0] = $avRET[0] - $wPos[0] $cPos2[1] = $avRET[1] - $wPos[1] $cPos2[2] = ($wPos[0] + $wPos[2]) - ($avRET[0] + $cPos2[2]) $cPos2[3] = ($wPos[1] + $wPos[3]) - ($avRET[1] + $cPos2[3]) EndIf Return $cPos2 EndFunc ;==>_WinGetClientPos Edited December 2, 2007 by Jex My scripts : Immediate Window , My Web Browser , Travian , Text Effect , Characters & Words per minute or second , Image Editor (ImageMagick) , Matrix style background effect ( Screensaver ) , Mail Sender , Protectlinks decoder and Rapidshare links checker , Fonts Fetcher , Region determine , Compare pictures , Gradient color box , Mouse Coordinates, Colors, Pixel Search things , Encrypt/Decrypt and embeding file in jpeg thing , Hard disk space monitor , Reflex game , Multiplayer Tic Tac Toe , WLM ( MSN ) personal message changer Link to comment Share on other sites More sharing options...
elloco Posted July 23, 2009 Share Posted July 23, 2009 (edited) Use the _WinAPI_ClientToScreen($hWnd, ByRef $tPoint) and _WinAPI_ScreenToClient($hWnd, ByRef $tPoint) functions to get the position of the client area. Have a look at the help file to use the functions. Easy and no hacks required via positioning of the mouse... Edited July 23, 2009 by elloco Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now