spyro Posted October 26, 2006 Share Posted October 26, 2006 I am trying to automate some menu calls, part of the problem is that these menu calls only work correctly if I call the menu item by the control name using controlsend() . The other part of the problem is that these controls change names all to often when the product is built or updated. How else can I handle this issue? Regular Send() does not accurately call the items. www.SecurityDistro.com Link to comment Share on other sites More sharing options...
GaryFrost Posted October 26, 2006 Share Posted October 26, 2006 If the text stays the same on the menu controls then maybe WinMenuSelectItem SciTE for AutoItDirections for Submitting Standard UDFs Don't argue with an idiot; people watching may not be able to tell the difference. Link to comment Share on other sites More sharing options...
spyro Posted October 26, 2006 Author Share Posted October 26, 2006 If the text stays the same on the menu controls then maybe WinMenuSelectItemThanks for the suggestion but no luck with that one. www.SecurityDistro.com Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted October 26, 2006 Moderators Share Posted October 26, 2006 (edited) _CtrlGetByPos(), I made it somewhere on the forum.Edit:http://www.autoitscript.com/forum/index.ph...st&p=219847 Edited October 26, 2006 by SmOke_N Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
spyro Posted October 26, 2006 Author Share Posted October 26, 2006 _CtrlGetByPos(), I made it somewhere on the forum.Edit:http://www.autoitscript.com/forum/index.ph...st&p=219847This might have to be a last resort in case I have no other option. I try to stay away from anything using x,y chords since they can vary from host to host. Thanks for the code though, it my be my only option. www.SecurityDistro.com Link to comment Share on other sites More sharing options...
Dizzy Posted November 7, 2006 Share Posted November 7, 2006 (edited) Hi SmOke_N, i found your script to get the controls by coordinates, but i didn't get the right ones. See my script: expandcollapse popupOpt('WinTitleMatchMode', 4) $PID = Run(@ProgramFilesDir & "\Outlook Express\msimn.exe") WinWaitActive("Outlook Express") Global $Control_To_Interact_With_Is = _CtrlGetByPos('classname=Outlook Express Browser Class', '', 200, 35, 3) If IsArray($Control_To_Interact_With_Is) Then For $i = 1 To UBound($Control_To_Interact_With_Is) - 1 ;MsgBox(0, '', $Control_To_Interact_With_Is[$i]) ConsoleWrite($i-1 & "Info ........: " & $Control_To_Interact_With_Is[$i] & @CR) If $i=0 then $className = $Control_To_Interact_With_Is[$i] If $i=1 then $controlID = $Control_To_Interact_With_Is[$i] If $i=2 then $controlHandle = $Control_To_Interact_With_Is[$i] Next EndIf ;MsgBox(64,"Infos: ",$Control_To_Interact_With_Is[0] & @crlf & $Control_To_Interact_With_Is[1] & @crlf & $Control_To_Interact_With_Is[2] & @crlf) ;=============================================================================== ; Function Name: _CtrlGetByPos() ; Description: Get the Control ID or the ClassNameNN by the X and Y client coordinates ; Syntax: _CtrlGetByPos("Window Title", [Control Text], [X Client Coord], [Y Client Coord], [Return Type]) ; ; Parameter(s): $hWin = Window Name or Handle ; $sText = Text of the Control ; $iXPos = X Client Coord ; $iYPos = Y Client Coord ; $iReturnType = Return type (default = 0 (ClassNameNN)) ; 0 = ClassNameNN ; 1 = Control ID ; 2 = Control Handle ; 3 = All 3 ClassNameNN, Control ID, Control Handle ; ; ; Requirement(s): External: = None. ; Internal: = AutoIt Beta 3.1.130 (or which ever release SetError(0,0,0) was introduced) ; ; Return Value(s): On Success: = Returns Array List ; On Failure: = @error 1 (Control was found but there was an error with the DLLCall) ; On Failure: = @error 2 (No classes were found) ; ; Author(s): SmOke_N ; ; Note(s): Similar to LxP's here (This was made before I remembered he had done something similar) ; http://www.autoitscript.com/forum/index.php?showtopic=14323&hl= ; ; ; Example(s): ; Opt('WinTitleMatchMode', 4) ; _CtrlGetByPos('classname=SciTEWindow', '', 829, 504, 2) ;=============================================================================== Func _CtrlGetByPos($hWin, $sText = '', $iXPos = 0, $iYPos = 0, $iReturnType = 0) If IsString($hWin) Then $hWin = WinGetHandle($hWin) Local $sClassList = WinGetClassList($hWin), $hCtrlWnd Local $sSplitClass = StringSplit(StringTrimRight($sClassList, 1), @LF), $aReturn = '' For $iCount = UBound($sSplitClass) - 1 To 1 Step - 1 Local $nCount = 0 While 1 $nCount += 1 Local $aCPos = ControlGetPos($hWin, $sText, $sSplitClass[$iCount] & $nCount) If @error Then ExitLoop If $iXPos >= $aCPos[0] And $iXPos <= ($aCPos[0] + $aCPos[2]) _ And $iYPos >= $aCPos[1] And $iYPos <= ($aCPos[1] + $aCPos[3]) Then If $sSplitClass[$iCount] <> '' And Not $iReturnType Then Local $aClassNN[2] = [2, $sSplitClass[$iCount] & $nCount] Return $aClassNN EndIf If $sSplitClass[$iCount] <> '' And $iReturnType = 3 Then $hCtrlWnd = ControlGetHandle($hWin, $sText, $sSplitClass[$iCount] & $nCount) ControlFocus($hWin, $sText, $hCtrlWnd) $aReturn = DllCall('User32.dll', 'int', 'GetDlgCtrlID', 'hwnd', $hCtrlWnd) If @error = 0 And $aReturn[0] <> '' Then Local $aClassNN[4] = [4, $aReturn[0], $sSplitClass[$iCount] & $nCount, $hCtrlWnd] Return $aClassNN EndIf Local $aClassNN[2] = [2, $sSplitClass[$iCount] & $nCount] Return $aClassNN ElseIf $sSplitClass[$iCount] <> '' And $iReturnType = 2 Then Return ControlGetHandle($hWin, $sText, $sSplitClass[$iCount] & $nCount) ElseIf $sSplitClass[$iCount] <> '' And $iReturnType = 1 Then $hCtrlWnd = ControlGetHandle($hWin, $sText, $sSplitClass[$iCount] & $nCount) ControlFocus($hWin, $sText, $hCtrlWnd) $aReturn = DllCall('User32.dll', 'int', 'GetDlgCtrlID', 'hwnd', $hCtrlWnd) If @error = 0 And $aReturn[0] <> '' Then Local $aClassNN[2] = [2, $aReturn[0]] Return $aClassNN EndIf EndIf Return SetError(1, 0, 0) EndIf WEnd Next Return SetError(2, 0, 0) EndFunc And the "Active Window Info". On x=200 y=30 there is a classnameNN "ToolbarWindow323" (German Outlook express (Menu:Extras)). In the english version its the "tools" menu on x=140 y=40 Your script returns : ToolbarWindow321 Any idea? Thanks Dizzy Edited November 7, 2006 by Dizzy Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted November 7, 2006 Moderators Share Posted November 7, 2006 It has to be client coords, your using window coords. Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
PaulIA Posted November 7, 2006 Share Posted November 7, 2006 I am trying to automate some menu calls, part of the problem is that these menu calls only work correctly if I call the menu item by the control name using controlsend() . The other part of the problem is that these controls change names all to often when the product is built or updated. How else can I handle this issue?Regular Send() does not accurately call the items.If you have a handle to the menu, you can use the Menu module from Auto3Lib to manipulate the menu items. It does not depend on the control name. Auto3Lib: A library of over 1200 functions for AutoIt Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted November 7, 2006 Moderators Share Posted November 7, 2006 If you have a handle to the menu, you can use the Menu module from Auto3Lib to manipulate the menu items. It does not depend on the control name. - Didn't even read it was a menu ... (that's what you get when you look at something 5 minutes after you wake up).*side note* - I need to find the time to look at your library Paul, I thought it was for treeviews or something specific I guess is why I hadn't yet. Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
PaulIA Posted November 7, 2006 Share Posted November 7, 2006 *side note* - I need to find the time to look at your library Paul, I thought it was for treeviews or something specific I guess is why I hadn't yet.I need to get one of the Mods to change the subtitle. It started out as a library for controlling TreeViews, but it's kind of all over the place now Auto3Lib: A library of over 1200 functions for AutoIt 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