longfields Posted March 6, 2009 Posted March 6, 2009 Hello, Can anyone advise on the correct syntax for this special window description? I have tried it various ways, for example: WinWaitActive("[200\ 200\ 100\ 100]", "") but nothing seems to work. I can't find any examples either in the help file or on this forum. Thanks in advance for your assistance.
Robjong Posted March 6, 2009 Posted March 6, 2009 Hey,Read the help file http://www.autoitscript.com/autoit3/docs/i...indowsbasic.htmhttp://www.autoitscript.com/autoit3/docs/i...owsadvanced.htm
longfields Posted March 6, 2009 Author Posted March 6, 2009 OK, I'm sure you mean to help, but like I said, I read the helpfile. In describing this parameter it says:X \ Y \ W \ H - The position and size of a windowbut there are no practical examples. I have been trying it in different ways, but I must be misunderstanding how the syntax works. Anyone got a working example?Thanks.
Robjong Posted March 6, 2009 Posted March 6, 2009 Hey, I ment it in a good way I understand your question now, I'm not sure on the syntax but will take a look and let you know asap.
Robjong Posted March 6, 2009 Posted March 6, 2009 (edited) Hey,It is not documented as far as i can see and I played with it a bit but didn't get it to work either.Do you need to get a window by position and size or posiition or size? Edited March 6, 2009 by Robjong
longfields Posted March 6, 2009 Author Posted March 6, 2009 (edited) I'd prefer both, but I could manage with position only. Thanks for your help! Edited March 6, 2009 by longfields
Robjong Posted March 6, 2009 Posted March 6, 2009 (edited) hey, To get the window by position i whipped up this function(Edit: see 2 posts down, http://www.autoitscript.com/forum/index.ph...p;#entry653385)I'm sure you can get the rest to work, after you have the handle of the window, look at WinGetPos (element 2 and 3 are W and H) Edited March 6, 2009 by Robjong
longfields Posted March 6, 2009 Author Posted March 6, 2009 Hey, yeah, looks like that should work. Will try it shortly. Many, many thanks for all your help - you're a star!!
Robjong Posted March 6, 2009 Posted March 6, 2009 (edited) Hey, No problem, glad i could help. I am still curious about the X \ Y \ W \ H method, can anyone explain how this works? I went ahead and wrote a _GetWindowByXYWH function. expandcollapse popup;#### EXAMPLE ################################################### ; create example target window vars Global $hTWin, $aTWinPos, $hWin1, $hWin2 $hTWin= WinGetHandle("[ACTIVE]") $aTWinPos = WinGetPos($hTWin) If Not IsArray($aTWinPos) Then Exit 1 ; print target window info to console ConsoleWrite("+> Target Window: " & $hTWin & " - " & WinGetTitle($hTWin) & " ") ConsoleWrite("X: " & $aTWinPos[0] & " Y: " & $aTWinPos[1] & " W: " & $aTWinPos[2] & " H: " & $aTWinPos[3] & @CRLF) ; Get window by X position, Y position $hWin1 = _GetWindowFromPoint($aTWinPos[0], $aTWinPos[1]) ;~ ConsoleWrite("-> _GetWindowFromPoint: " & $hWin1 & " @error:" & @error & " @extended:" & @extended & @CRLF) If Not IsHWnd($hWin1) Then Exit 3 ConsoleWrite("-> _GetWindowFromPoint-Window: " & $hWin1 & " - " & WinGetTitle($hWin1) & @CRLF) ; Get window by X position, Y position, width and height $hWin2 = _GetWindowByXYWH($aTWinPos[0], $aTWinPos[1], $aTWinPos[2], $aTWinPos[3]) ;~ ConsoleWrite("-> _GetWindowByXYWH: " & $hWin2 & " @error:" & @error & " @extended:" & @extended & @CRLF) If Not IsHWnd($hWin2) Then Exit 4 ConsoleWrite("-> _GetWindowByXYWH-Window: " & $hWin2 & " - " & WinGetTitle($hWin2) & @CRLF) ;################################################################ ;================================================================================ ; Function Name....: _GetWindowByXYWH ; Description......: Get the handle of a window by the position (x, y) ; Syntax...........: _GetWindowByXYWH($iPosX, $iPosY, $iWidth, $iHeight) ; Parameter(s).....: $iPosX - X position of the target window ; $iPosY - Y position of the target window ; $iWidth - Width of the target window ; $iHeight - Height of the target window ; Return Value(s)..: Success: The handle of the window ; Failure: 0 ; sets @error to non-zero ; | @error = 1 - $iPosX is not an integer ; | @error = 2 - $iPosY is not an integer ; | @error = 3 - $iWidth is not an integer ; | @error = 4 - $iHeight is not an integer ; | @error = 5 - WindowFromPoint failed ; | @error = 6 - WinGetPos failed ; | @error = 7 - No window found matching all params ; Requirement(s)...: Windows 2000 or higher, user32.dll, Gdi32.dll ; Related..........: _GetWindowFromPoint ; Limitation(s)....: - ; Example(s).......: - ; Comment(s).......: http://msdn.microsoft.com/en-us/library/ms633558(VS.85).aspx ; Author(s)........: Robjong ; Modified.........: - ;================================================================================ Func _GetWindowByXYWH($iPosX, $iPosY, $iWidth, $iHeight) If Not StringIsInt($iPosX) Then Return SetError(1, 0, 0) If Not StringIsInt($iPosY) Then Return SetError(2, 0, 0) If Not StringIsInt($iWidth) Then Return SetError(3, 0, 0) If Not StringIsInt($iHeight) Then Return SetError(4, 0, 0) Local $sStruct = DllStructCreate("long x;long y") DllStructSetData($sStruct, "x", $iPosX) DllStructSetData($sStruct, "y", $iPosY) Local $aRes = DllCall("user32.dll", "hwnd", "WindowFromPoint", "Int64", $sStruct) If Not IsArray($aRes) Or Not IsHWnd($aRes[0]) Then Return SetError(5, 0, 0) Local $aWinPos = WinGetPos($aRes[0]) If Not IsArray($aWinPos ) Then Return SetError(6, 0, 0) If $iWidth == $aWinPos[2] And $iHeight == $aWinPos[3] Then Return SetError(0, 0, $aRes[0]) Return SetError(7, 0, 0) EndFunc ;==>_GetWindowByXYWH ;================================================================================ ; Function Name....: _GetWindowFromPoint ; Description......: Get the handle of a window by the position (x, y) ; Syntax...........: _GetWindowFromPoint($iPosX, $iPosY) ; Parameter(s).....: $iPosX - X position of the target window ; $iPosY - Y position of the target window ; Return Value(s)..: Success: The handle of the window ; Failure: 0 ; sets @error to non-zero ; | @error = 1 - $iPosX is not an integer ; | @error = 2 - $iPosY is not an integer ; | @error = 3 - WindowFromPoint failed ; Requirement(s)...: Windows 2000 or higher, user32.dll, Gdi32.dll ; Related..........: _GetWindowByXYWH ; Limitation(s)....: - ; Example(s).......: - ; Comment(s).......: http://msdn.microsoft.com/en-us/library/ms633558(VS.85).aspx ; Author(s)........: Robjong ; Modified.........: - ;================================================================================ Func _GetWindowFromPoint($iPosX, $iPosY) If Not StringIsInt($iPosX) Then Return SetError(1, 0, 0) If Not StringIsInt($iPosY) Then Return SetError(2, 0, 0) Local $sStruct = DllStructCreate("long x;long y") DllStructSetData($sStruct, "x", $iPosX) DllStructSetData($sStruct, "y", $iPosY) Local $aRes = DllCall("user32.dll", "hwnd", "WindowFromPoint", "Int64", $sStruct) If Not IsArray($aRes) Then Return SetError(3, 0, 0) Return SetError(0, 0, $aRes[0]) EndFunc ;==>_GetWindowFromPoint Edit: needed the func but lost it and noticed a mistake Edited March 23, 2009 by Robjong
martin Posted March 6, 2009 Posted March 6, 2009 (edited) Hello, Can anyone advise on the correct syntax for this special window description? I have tried it various ways, for example: WinWaitActive("[200\ 200\ 100\ 100]", "") but nothing seems to work. I can't find any examples either in the help file or on this forum. Thanks in advance for your assistance. The help is unusually unhelpful with this one, but the way it's done is wingettitle("[X:400\Y:500\W:200\H:300]") EDIT: Apparently not, see later posts. Edited March 7, 2009 by martin Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Robjong Posted March 6, 2009 Posted March 6, 2009 (edited) Hey, @martin: nice, thats works great. something to add to the help file... e.g. Wait for a window on the X position 101, Y position 102 and with Width 103 and Height 104 (all are optional) WinWaitActive("[X:101\Y:102\W:103\H:104]") Edited March 6, 2009 by Robjong
PsaltyDS Posted March 7, 2009 Posted March 7, 2009 (edited) There is a bug trac on using all four at once - fixed for the Beta 3.3.1.0 (yet to be released). There is a demo included in the bug trac ticket #802. P.S. Also discussed in this topic: AfxWndW Controls Edited March 7, 2009 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
Robjong Posted March 7, 2009 Posted March 7, 2009 (edited) There is a bug trac on using all four at once - fixed for the Beta 3.3.1.0 (yet to be released). There is a demo included in the bug trac ticket #802. P.S. Also discussed in this topic: AfxWndW Controls After the 3rd post i messed around withit a bit and only tried it with a semicolon and 4 params so it always failed. It seems to work fine if you use the backslash instead of the semicolon, but it does not see next post. Example: $hTWin = WinGetHandle("[ACTIVE]") $aTWinPos = WinGetPos($hTWin) If Not IsArray($aTWinPos) Then Exit 1 ConsoleWrite(WinGetHandle("[X:" & $aTWinPos[0] & "; Y:" & $aTWinPos[1] & "; W:" & $aTWinPos[2] & "; H:" & $aTWinPos[3] & "]") & @CRLF) ; failes ConsoleWrite(WinGetHandle("[X:" & $aTWinPos[0] & "\Y:" & $aTWinPos[1] & "\W:" & $aTWinPos[2] & "\H:" & $aTWinPos[3] & "]") & @CRLF) ; works Edit: n/m Edited March 7, 2009 by Robjong
PsaltyDS Posted March 7, 2009 Posted March 7, 2009 It seems to work fine if you use the backslash instead of the semicolon Example: $hTWin = WinGetHandle("[ACTIVE]") $aTWinPos = WinGetPos($hTWin) If Not IsArray($aTWinPos) Then Exit 1 ConsoleWrite(WinGetHandle("[X:" & $aTWinPos[0] & "; Y:" & $aTWinPos[1] & "; W:" & $aTWinPos[2] & "; H:" & $aTWinPos[3] & "]") & @CRLF); failes ConsoleWrite(WinGetHandle("[X:" & $aTWinPos[0] & "\Y:" & $aTWinPos[1] & "\W:" & $aTWinPos[2] & "\H:" & $aTWinPos[3] & "]") & @CRLF); works You didn't read the whole topic. That only works because all the values after the invalid syntax are ignored. Note that it still works with clearly bogus values plugged in there: ConsoleWrite(WinGetHandle("[X:" & $aTWinPos[0] & "\Y:" & 12345 & "\W:" & 12345 & "\H:" & 12345 & "]") & @CRLF); works 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
Robjong Posted March 7, 2009 Posted March 7, 2009 Ok, well then i guess we will have to wait for the next release. Untill then people will have to use WinGetHandle for the X,Y and WinGetPos to match W and H or something. Thanks for pointing that out to me
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