alexm963 Posted January 28, 2014 Share Posted January 28, 2014 (edited) Hello, I am trying to write a script to automate a process at work. I have most of it done but certain things change from system to system. Specifically a button whose instance changes depending on who is logged into our MRP software. However the ControlID remains the same no matter what. Unfortunately there is abother button with the same ControlID so I can't use just that. The button I need to click/press has an ID of 4099 and no text, the other has text that could change. I have been trying things like this: ControlClick( $IFS, "", "[iD:4099; CLASS:Button; TEXT:]") ControlClick( $IFS, "", "[iD:4099; CLASS:Button; TEXT:<>]") ControlClick( $IFS, "", "[iD:4099; CLASS:Button; TEXT:""]") So far none have worked. Is there a way to specify this item? Edited January 28, 2014 by alexm963 Link to comment Share on other sites More sharing options...
BrewManNH Posted January 28, 2014 Share Posted January 28, 2014 Us the Au3Info tool on the button, and post the Summary tab for both buttons. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
alexm963 Posted January 28, 2014 Author Share Posted January 28, 2014 (edited) Button I want to press: >>>> Window <<<< Title: Make To Stock and Batch Processing Class: Centura:MDIFrame Position: -4, -4 Size: 1608, 878 Style: 0x15CF0000 ExStyle: 0x00000100 Handle: 0x002406A8 >>>> Control <<<< Class: Button Instance: 23 ClassnameNN: Button23 Name: Advanced (Class): [CLASS:Button; INSTANCE:23] ID: 4099 Text: Position: 1567, 130 Size: 30, 30 ControlClick Coords: 16, 14 Style: 0x5002000B ExStyle: 0x00000000 Handle: 0x00050CB8 >>>> Mouse <<<< Position: 1583, 190 Cursor ID: 0 Color: 0xF8F8F9 >>>> StatusBar <<<< >>>> ToolsBar <<<< >>>> Visible Text <<<< Selection Options File Source Reference Output Channel Links Inventory Part Product Structure Query - Component Where Used Receive Shop Order Overview - Manufacturing Structures * * Buildable Use By-product Cost Distribution 1 17 Manufacturing Manufacturing 17 7/17/2013 17 * 17 ea VAW A Date A ACTIVE Customer Warranty Notes Document Text >>>> Hidden Text <<<< Search Select Search Domains Links Navigator IFS Navigator IFS Navigator; System Information 1 17 Manufacturing M 54236645 Objid Objversion Part No Site Revision No Structure Type: Alternative Line Item No Component Part Part Description Component Part Status Part Status Description UoM Qty per Assembly Operation No Component Scrap Scrap Factor Consumption Item Lead Time Offset Promise Planned Phantom Consume Charged Item Issue From Location Drawing Position No Source Create Last activity Notes Print UoM Note Id (untitled) Has Work Guidelines Value Analysis Func ID Value Analysis Func Type Structure Type Vim Structure Source Backflush of Purchased Components Std Planned Item Oper Cost Distribution Factor Gen OH Cost Distribution Factor Procedure Step 54236644 M 7/17/2013 IFS Applications - ComCenter &Clear &Hide Button I don't want Pressed >>>> Window <<<< Title: Make To Stock and Batch Processing Class: Centura:MDIFrame Position: -4, -4 Size: 1608, 878 Style: 0x15CF0000 ExStyle: 0x00000100 Handle: 0x002406A8 >>>> Control <<<< Class: Button Instance: 27 ClassnameNN: Button27 Name: Advanced (Class): [CLASS:Button; INSTANCE:27] ID: 4099 Text: Product Structure Position: 143, 40 Size: 115, 22 ControlClick Coords: 54, 9 Style: 0x5002000B ExStyle: 0x00000000 Handle: 0x00040CD0 >>>> Mouse <<<< Position: 197, 95 Cursor ID: 0 Color: 0xF0F0F0 >>>> StatusBar <<<< >>>> ToolsBar <<<< >>>> Visible Text <<<< Selection Options File Source Reference Output Channel Links Inventory Part Product Structure Query - Component Where Used Receive Shop Order Overview - Manufacturing Structures * * Buildable Use By-product Cost Distribution 1 17 Manufacturing Manufacturing 17 7/17/2013 17 * 17 ea VAW A Date A ACTIVE Customer Warranty Notes Document Text >>>> Hidden Text <<<< Search Select Search Domains Links Navigator IFS Navigator IFS Navigator; System Information 1 17 Manufacturing M 54236645 Objid Objversion Part No Site Revision No Structure Type: Alternative Line Item No Component Part Part Description Component Part Status Part Status Description UoM Qty per Assembly Operation No Component Scrap Scrap Factor Consumption Item Lead Time Offset Promise Planned Phantom Consume Charged Item Issue From Location Drawing Position No Source Create Last activity Notes Print UoM Note Id (untitled) Has Work Guidelines Value Analysis Func ID Value Analysis Func Type Structure Type Vim Structure Source Backflush of Purchased Components Std Planned Item Oper Cost Distribution Factor Gen OH Cost Distribution Factor Procedure Step 54236644 M 7/17/2013 IFS Applications - ComCenter &Clear &Hide Edited January 28, 2014 by alexm963 Link to comment Share on other sites More sharing options...
jdelaney Posted January 28, 2014 Share Posted January 28, 2014 (edited) You can use this, and modify it. Paste back in the output of your matching controls. You can make a seperate function to return the handle of the control that matches the ID and has no text. expandcollapse popupFunc Var_GetAllWindowsControls($hCallersWindow,$iControlID) ;~ $giSubFunctionCounter += 1 ; Get all list of controls $sClassList = WinGetClassList($hCallersWindow) ; Create array $aClassList = StringSplit($sClassList, @CRLF, 2) ; Sort array _ArraySort($aClassList) _ArrayDelete($aClassList, 0) ; Loop $iCurrentClass = "" $iCurrentCount = 1 $iTotalCounter = 1 For $i = 0 To UBound($aClassList) - 1 If $aClassList[$i] = $iCurrentClass Then $iCurrentCount += 1 Else $iCurrentClass = $aClassList[$i] $iCurrentCount = 1 EndIf $hControl = ControlGetHandle($hCallersWindow, "", "[CLASSNN:" & $iCurrentClass & $iCurrentCount & "]") $text = StringRegExpReplace(ControlGetText($hCallersWindow, "", $hControl), "[\n\r]", "{@CRLF}") $aPos = ControlGetPos($hCallersWindow, "", $hControl) $bVisible = ControlCommand($hCallersWindow, "", $hControl,"IsVisible") $bIsEnabled = ControlCommand($hCallersWindow, "", $hControl,"IsEnabled") $sControlID = _WinAPI_GetDlgCtrlID($hControl) If IsArray($aPos) Then ConsoleWrite( "Func=[Var_GetAllWindowsControls]: $bIsEnabled=[" & $bIsEnabled & "] $bVisible=[" & $bVisible & "] ControlCounter=[" & StringFormat("%3s", $iTotalCounter) & "] ControlID=[" & StringFormat("%5s", $sControlID) & "] Handle=[" & StringFormat("%10s", $hControl) & "] ClassNN=[" & StringFormat("%19s", $iCurrentClass & $iCurrentCount) & "] XPos=[" & StringFormat("%4s", $aPos[0]) & "] YPos=[" & StringFormat("%4s", $aPos[1]) & "] Width=[" & StringFormat("%4s", $aPos[2]) & "] Height=[" & StringFormat("%4s", $aPos[3]) & "] Text=[" & $text & "]." & @CRLF) Else ConsoleWrite( "Func=[Var_GetAllWindowsControls]: ControlCounter=[" & StringFormat("%3s", $iTotalCounter) & "] ControlID=[" & StringFormat("%5s", $sControlID) & "] Handle=[" & StringFormat("%10s", $hControl) & "] ClassNN=[" & StringFormat("%19s", $iCurrentClass & $iCurrentCount) & "] XPos=[winclosed] YPos=[winclosed] Width=[winclosed] Height=[winclosed] Text=[" & $text & "]." & @CRLF) EndIf If Not WinExists($hCallersWindow) Then ExitLoop $iTotalCounter += 1 Next ;~ $giSubFunctionCounter -= 1 EndFunc ;==>Var_GetAllWindowsControls Unfortunatly, if you use the ID, it seems that none of the other options are considered. In our app, we have several tabs, with distinct buttons (same ID) on each tab. I can use something like the above to loop through, and get the 'visible' instance of the button (the current tab's button). Obviously, this function is just for debugging, but can be used as a template to do what you need. Maybe make a function where you pass in ALL the arguments you want to match, including the ID, and return the handle where all states match...I'd use an array as the variable to house the states to match. Edited January 28, 2014 by jdelaney IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window. Link to comment Share on other sites More sharing options...
BrewManNH Posted January 28, 2014 Share Posted January 28, 2014 Use [CLASS:Button; INSTANCE:27] for one of them and [CLASS:Button; INSTANCE:23] for the other button. No conflict that way. Or you could even use [ClassnameNN:Button23} instead, they're basically the same. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
jdelaney Posted January 28, 2014 Share Posted January 28, 2014 Instance based is a quick workaround, but if your applicaiton has any complexity at all, those instances can change with user rights/ configurations. This will get what you need, and not be based on instances: expandcollapse popupLocal $aCriteria[3][2]=[["ID",4708],["IsVisible",True],["Text","Stat"]] $hWindow = WinGetHandle("YourWindow") ConsoleWrite(Var_GetWindowsControl_matching($hWindow,$aCriteria) & @CRLF) Exit Func Var_GetWindowsControl_matching($hCallersWindow,$aCallersCriteria) ;~ $giSubFunctionCounter += 1 ; Get all list of controls $sClassList = WinGetClassList($hCallersWindow) ; Create array $aClassList = StringSplit($sClassList, @CRLF, 2) ; Sort array _ArraySort($aClassList) _ArrayDelete($aClassList, 0) ; Loop $iCurrentClass = "" $iCurrentCount = 1 $iTotalCounter = 1 For $i = 0 To UBound($aClassList) - 1 If $aClassList[$i] = $iCurrentClass Then $iCurrentCount += 1 Else $iCurrentClass = $aClassList[$i] $iCurrentCount = 1 EndIf $hControl = ControlGetHandle($hCallersWindow, "", "[CLASSNN:" & $iCurrentClass & $iCurrentCount & "]") $bAllMatching=True For $j = 0 To UBound($aCriteria)-1 Switch $aCriteria[$j][0] Case "ID" If Int($aCriteria[$j][1]) <> Int(_WinAPI_GetDlgCtrlID($hControl)) Then $bAllMatching = False Case "IsVisible" If $aCriteria[$j][1] <> ControlCommand($hCallersWindow, "", $hControl,"IsVisible") Then $bAllMatching = False Case "Text" If String($aCriteria[$j][1]) <> String(ControlGetText($hCallersWindow, "", $hControl)) Then $bAllMatching = False Case Else $bAllMatching=False EndSwitch If Not $bAllMatching Then ExitLoop Next If $bAllMatching Then Return $hControl EndIf $iTotalCounter+=1 Next Return False EndFunc ;==>Var_GetAllWindowsControls Modify the array to suit your needs...add additional cases in the switch as required. IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window. Link to comment Share on other sites More sharing options...
alexm963 Posted January 28, 2014 Author Share Posted January 28, 2014 I'm getting an error when running it from SciTe. It doesn't recognize the 3 functions called for in the script. Do i need to add some #include lines for this? Link to comment Share on other sites More sharing options...
jdelaney Posted January 28, 2014 Share Posted January 28, 2014 (edited) Yes. Future reference, when it jumps to the function that isn't 'included' you can click it, press F1, and it will show you the file you need to include in the helpfile... #include <Array.au3> #include <WinAPI.au3> Edited January 28, 2014 by jdelaney IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window. Link to comment Share on other sites More sharing options...
alexm963 Posted January 28, 2014 Author Share Posted January 28, 2014 Ok well I got your script to run, but I was still having an issue.I found that there are several "sets" of buttons in our software. Unfortunately the first button of every "set" is ID 4097, therefore there are several ID 4099 buttons, and many with a blank TEXT field. I'll need to go back to the drawing board on this one. Link to comment Share on other sites More sharing options...
alexm963 Posted January 28, 2014 Author Share Posted January 28, 2014 Not sure If i should make a new thread for this or not, but the button is in a dialog box. Is there a way to specify that? Control ID 4099 in Dialog 7? Link to comment Share on other sites More sharing options...
jdelaney Posted January 28, 2014 Share Posted January 28, 2014 Add more params to narrow it down. You can also return all matches into an array, and do what you need with them. IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window. Link to comment Share on other sites More sharing options...
Zuflex Posted October 20, 2014 Share Posted October 20, 2014 Hello, Alexm963! Our company also using Ifs Applications. Its not ideal product, so I'm trying to facilitate its usage. Maybe I can help you with something? P.S. my skype: bodya_spirit 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