Tasmania Posted September 26, 2007 Posted September 26, 2007 Anyone know how to send text to a textbox that has an everchanging name? I've changed the name variables three times now, and things just seem to always change whenever the application restarts, and sometimes, even when it doesn't restart. The text boxes are always in the same position, and I saw a shade of a reference to some sort of way to send text to a handle and have the handle based off of the position of the text box, but I'm new to the whole handles experience, so if anyone would be able to help me out I'd greatly appreciate it. An example of what I'm trying to do is: AutoIt Window Info shows the title as Order Maintenance - bft Class is Edit Instance is 12 ClassnameNN is Edit12 ID is 56 Text is "" Position is 212, 50 Size is 140, 21 ControlClick coords is 105, 11 I want to take and select the text box based on the position and enter text into it.
jvanegmond Posted September 26, 2007 Posted September 26, 2007 Maybe this helps:Opt("WinTitleMatchMode",2) ControlSend("Order Maintenance", "", "Edit12", "????SEND TEXT HERE????") I can't give more script on the information you gave me. It may help telling which program you are trying to automate, I'll download and install it if possible. github.com/jvanegmond
Tasmania Posted September 26, 2007 Author Posted September 26, 2007 I'm not sure you are able to download and install the application I am trying to automate, but if you are able to, hehe, well, you're more than welcome to.Anyway, there is a whole lot more information on this at my previous post, located here:http://www.autoitscript.com/forum/index.php?showtopic=53980I think I've worked out THAT specific bug, but I can't tell if I can't send text to the right text box. It has nothing to do with the window title, it's the control's ID and Name that change. I will x-ref some code for you, to show exactly what I mean.
Tasmania Posted September 26, 2007 Author Posted September 26, 2007 Yesterday, my code was as follows: expandcollapse popupControlSend("Item Maintenance", "", "[ID:512]", $inum)oÝ÷ Ù:k,!zr¢^vêfÉÊ&¦ë^«p¢¹Ú)zw¶¦bq«b¢{©Â§jëhÛÝ7ê)îÚ-âç]°'!ÉZmé^u«µé¢·î¶êÞçÞéÜz+]Ù赪iyªâØ^µìmnZ±«miÈ^u·¥£§vǩݫaz²ç]¢²Ê&zaz»^ÆÖèÆz-µçhØb²Ç+yéÍ£è®Ø^r^¶Âäyܲ׫u¬£ +Úk"!j÷¡ÈZZ"ßÛ"Ø^z{b橦Xjب«2¢ì"Yèµëaz·æ{h¶§{ßÛØÂ÷öÜ(®Kh룢¶«jwHÂ)e«Þ¶(¶èºZص©e =ý±¨qÞè¬)ÞÁë--ç×(uêey«^¶{ay· zyâaz·ë(çb±ÊÞ¥éÜëyÆ®±â«mzjmx-£ +í+"²Ëjëh×6#include <GUIConstants.au3> #Region ### START Koda GUI section ### Form=c:\documents and settings\uspjefe\desktop\projects\frmquestions.kxf $frmCInfo = GUICreate("Syte Line Automation", 419, 314, -1, -1) $grpInfo = GUICtrlCreateGroup(" Information ", 0, 0, 417, 241) $lblAttn = GUICtrlCreateLabel("&Attn:", 8, 17, 32, 17) $txtAttn = GUICtrlCreateInput("", 96, 17, 105, 21, BitOR($ES_UPPERCASE,$ES_AUTOHSCROLL)) $lblEmail = GUICtrlCreateLabel("&Email:", 8, 41, 38, 17) $txtEmail = GUICtrlCreateInput("", 96, 41, 105, 21, BitOR($ES_UPPERCASE,$ES_AUTOHSCROLL)) $lblPwo = GUICtrlCreateLabel("&PWO #:", 8, 65, 49, 17) $txtPwo = GUICtrlCreateInput("", 96, 65, 105, 21, BitOR($ES_UPPERCASE,$ES_AUTOHSCROLL)) $lblInum = GUICtrlCreateLabel("Full &Item Num:", 8, 89, 77, 17) $txtInum = GUICtrlCreateInput("", 96, 89, 105, 21, BitOR($ES_UPPERCASE,$ES_AUTOHSCROLL)) $lblSca = GUICtrlCreateLabel("&SCA # (No 0):", 8, 113, 76, 17) $txtSca = GUICtrlCreateInput("", 96, 113, 105, 21, BitOR($ES_UPPERCASE,$ES_AUTOHSCROLL)) GUICtrlSetLimit(-1, 7) $lblDesc = GUICtrlCreateLabel("&Description:", 8, 137, 66, 17) $txtDesc = GUICtrlCreateInput("", 96, 137, 105, 21, BitOR($ES_UPPERCASE,$ES_AUTOHSCROLL)) GUICtrlSetLimit(-1, 40) $lblRstdate = GUICtrlCreateLabel("&Request Date:", 8, 161, 79, 17) $dteRstdate = GUICtrlCreateDate("", 96, 161, 105, 21, $WS_TABSTOP) $lblType = GUICtrlCreateLabel("T&ype:", 8, 184, 37, 17) $cmbType = GUICtrlCreateCombo("CONCEPT", 96, 184, 105, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL,$CBS_UPPERCASE)) GUICtrlSetData(-1, "RECONCEPT|SAMPLE|RESAMPLE|ADDL SMPL|HEAT SEAL TOOL|BLISTR FRM TOOL") $lblProdCode = GUICtrlCreateLabel("Produc&t Code:", 8, 208, 78, 17) $cmbPcode = GUICtrlCreateCombo("SAM-CONCPT", 96, 208, 105, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL,$CBS_UPPERCASE)) GUICtrlSetData(-1, "SAM-SAMPL|SAM-ADDL|MAH-FAC|MAH-FAM|BFT-VAC|BFT-PRESS") $lblPO = GUICtrlCreateLabel("P&O Number:", 216, 17, 68, 17) $txtPO = GUICtrlCreateInput("N/C", 304, 17, 105, 21, BitOR($ES_UPPERCASE,$ES_AUTOHSCROLL)) $lblPOamt = GUICtrlCreateLabel("PO A&mount:", 216, 41, 67, 17) $txtPOamt = GUICtrlCreateInput("0", 304, 41, 105, 21, BitOR($ES_UPPERCASE,$ES_AUTOHSCROLL)) $lblPOdiscount = GUICtrlCreateLabel("PO Disco&unt:", 216, 64, 73, 17) $txtPOdiscount = GUICtrlCreateInput("", 304, 64, 105, 21, BitOR($ES_UPPERCASE,$ES_AUTOHSCROLL)) $lblPE = GUICtrlCreateLabel("Projec&t Enj:", 216, 89, 64, 17) $txtPE = GUICtrlCreateInput("", 304, 89, 105, 21, BitOR($ES_UPPERCASE,$ES_AUTOHSCROLL)) $lblPM = GUICtrlCreateLabel("Project &Mngr:", 216, 113, 73, 17) $txtPM = GUICtrlCreateInput("", 304, 113, 105, 21, BitOR($ES_UPPERCASE,$ES_AUTOHSCROLL)) $lblCharge = GUICtrlCreateLabel("&Charge:", 216, 137, 47, 17) $txtCharge = GUICtrlCreateInput("", 304, 137, 105, 21, BitOR($ES_UPPERCASE,$ES_AUTOHSCROLL)) $lblQty = GUICtrlCreateLabel("Quantit&y:", 216, 160, 52, 17) $txtQty = GUICtrlCreateInput("1.00", 304, 160, 105, 21, BitOR($ES_UPPERCASE,$ES_AUTOHSCROLL)) $lblMaterial = GUICtrlCreateLabel("Materia&l:", 216, 184, 50, 17) $txtMaterial = GUICtrlCreateInput("", 304, 184, 105, 21) $lblGauge = GUICtrlCreateLabel("&Gauge:", 216, 208, 45, 17) $txtGauge = GUICtrlCreateInput("", 304, 208, 105, 21, BitOR($ES_UPPERCASE,$ES_AUTOHSCROLL)) GUICtrlCreateGroup("", -99, -99, 1, 1) $lblExNotes = GUICtrlCreateLabel("Extra &Notes:", 8, 248, 68, 17) $edtExNotes = GUICtrlCreateEdit("", 80, 248, 241, 57, BitOR($ES_UPPERCASE,$ES_AUTOVSCROLL,$ES_AUTOHSCROLL,$ES_WANTRETURN,$WS_VSCROLL)) GUICtrlSetData(-1, "") $btnContinue = GUICtrlCreateButton("Contin&ue", 336, 248, 75, 25, 0) $btnExit = GUICtrlCreateButton("E&xit", 336, 280, 75, 25, 0) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### ; ********** Variables that are needed to start ********** $displayed = 0 $readonly = 0 ; ********** End variables that are needed to start ********** While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE ; Exit icon - upper right Exit Case $btnExit Exit Case $btnContinue GUISetState(@SW_HIDE) ExitLoop Case Not $txtInum If StringLen(GUICtrlRead($txtInum)) > 0 And $displayed <= 2 Then If StringInStr(GUICtrlRead($txtInum), "SAMPLE") Then GUICtrlSetData($cmbType, "SAMPLE") GUICtrlSetData($cmbPcode, "SAM-SAMPL") $displayed += 1 ElseIf StringInStr(GUICtrlRead($txtInum), "ADDSAM") Then GUICtrlSetData($cmbType, "ADDL SAMPL") GUICtrlSetData($cmbPcode, "SAM-ADDL") $displayed += 1 ElseIf StringInStr(GUICtrlRead($txtInum), "CONCEPT") Then GUICtrlSetData($cmbType, "CONCEPT") GUICtrlSetData($cmbPcode, "SAM-CONCPT") $displayed += 1 ElseIf StringInStr(GUICtrlRead($txtInum), "H") Then GUICtrlSetData($cmbType, "HEAT SEAL TOOL") GUICtrlSetData($cmbPcode, "MAH-FAC") $displayed += 1 ElseIf StringInStr(GUICtrlRead($txtInum), "FORMTOOL") Then GUICtrlSetData($cmbType, "BLISTER FORM TOOL") GUICtrlSetData($cmbPcode, "BFT-VAC") $displayed += 1 EndIf ElseIf StringLen(GUICtrlRead($txtInum)) = 0 And $displayed <= 3 Then $displayed = 0 EndIf EndSwitch WEnd ; ********** Variables that will NOT be changed ********** $attn = StringUpper(GUICtrlRead($txtAttn)) $email = StringUpper(GUICtrlRead($txtEmail)) $pwo = StringUpper(GUICtrlRead($txtPwo)) $inum = StringUpper(GUICtrlRead($txtInum)) $sca = StringUpper(GUICtrlRead($txtSca)) $date = GUICtrlRead($dteRstdate) $newdate = StringSplit($date, "/") If StringLen($newdate[2]) < 2 Then $day = "0" & $newdate[2] Else $day = $newdate[2] EndIf If StringLen($newdate[1]) < 2 Then $mon = "0" & $newdate[1] Else $mon = $newdate[1] EndIf $yr = StringRight($newdate[3], 2) $date = $mon & "/" & $day & "/" & $yr $type = StringUpper(GUICtrlRead($cmbType)) $pcode = StringUpper(GUICtrlRead($cmbPcode)) $po = StringUpper(GUICtrlRead($txtPO)) $poamt = StringUpper(GUICtrlRead($txtPOamt)) $podisc = StringUpper(GUICtrlRead($txtPOdiscount)) $pe = StringUpper(GUICtrlRead($txtPE)) $pm = StringUpper(GUICtrlRead($txtPM)) $charge = StringUpper(GUICtrlRead($txtCharge)) $desc = StringUpper(GUICtrlRead($txtDesc)) $exnotes = StringUpper(GUICtrlRead($edtExNotes)) $qty = StringUpper(GUICtrlRead($txtQty)) $gauge = StringUpper(GUICtrlRead($txtGauge)) $material = StringUpper(GUICtrlRead($txtMaterial)) ; Default location is going to be bft $loc = "bft" $newitem = 0 ; ********** End variables that will NOT be change ********** ; First thing we need to do is to see if we can find main menu for Syte Line If WinExists("Main Menu - dekb") Then WinActivate("Main Menu - dekb") ; Maximize the dekalb blister site ElseIf WinExists("Main Menu - bft") Then WinActivate("Main Menu - bft") ; Maximize the blister form tools site ElseIf WinExists("Main Menu - dekm") Then WinActivate("Main Menu - dekm") ; Maximize the dekalb machenery site Else Run("P:\dlc91c\bin\prowin32.exe -basekey INI -ininame p:\syteline6\symix.ini -pf p:\syteline.prd\dekbrun.pf -p menu\symix.p") WinWaitActive("ERP 6.01.00") Send("{SPACE}") WinWaitActive("Main Menu - dekb") EndIf If $type = "HEAT SEAL TOOL" Then If Not WinActive("Main Menu - dekm") Then Send("!fw") WinWaitActive("Select a Site/Entity") Send("dekm{ENTER}{ENTER}") WinWaitActive("Main Menu - dekm") $loc = "dekm" EndIf ElseIf Not WinActive("Main Menu - bft") Then Send("!fw") ; Wait until the select a site is active WinWaitActive("Select a Site/Entity") ; Go to blister form tools Send("BFT{ENTER}{ENTER}") ; Wait until the main menu loads WinWaitActive("Main Menu - bft") $loc = "bft" EndIf WinWaitActive("Main Menu - ") ; Now activate the customer order entry window ;WinMenuSelectItem("Main Menu - ", "", "&Customer", "&Customer Service", "&Order Maintenance") Send("!cco") ; Wait for the window to become active WinWaitActive("Order Maintenance - ") Send("!s") ; Select a new entry ;WinMenuSelectItem("Order Maintenance - ", "", "&Edit", "N&ew") Send("!ee") WinWaitActive("Order Maintenance") ; Figure out if there is a PO or Not If $po Not = "" Then ControlSend("Main Menu - ", "", "[POSITION:212, 50]" ,$po) Else MsgBox(16, "Error", "The PO Box is empty. Stopping script.") Exit EndIf #cs ; Now have the user enter in the customer MsgBox(64, "Notice", "Please enter the customer address and enter the shipping and contact information.") ControlClick("Order Maintenance - ", "", "[ID:76]") ; Wait for them to Continue WinWaitActive("Order Line Maintenance - ") Send("!d") ; Select a new entry ;WinMenuSelectItem("Order Line Maintenance - ", "", "&Edit", "N&ew") Send("!ee") WinWaitActive("Order Line Maintenance") ; Once at the new entry enter in the item description ControlSend("Order Line Maintenance - ", "", "[ID:363]", $inum, 1) Send("{TAB}") WinWaitActive("Validate", "", 2) If WinActive("Validate") Then Send("{SPACE}") $compname = InputBox("Company Name", "Please enter the company name:", "", " M", 190, 115) $newitem = 1 WinWaitClose("Company Name") WinActivate("Main Menu - ") ;WinMenuSelectItem("Main Menu - ", "", "&Material", "&Inventory", "&Item Maintenance") Send("!mii") WinWaitActive("Item Maintenance - ") ControlClick("Item Maintenance - ", "", "[ID:711]") ;WinMenuSelectItem("Item Maintenance - ", "", "&Edit", "N&ew") Send("!ee") WinWaitActive("Item Maintenance") ControlSend("Item Maintenance", "", "[ID:512]", $inum, 1) ControlSend("Item Maintenance", "", "[ID:514]", $compname & "-" & $desc, 1) ControlSend("Item Maintenance", "", "[ID:520]", "EA", 1) ControlSend("Item Maintenance", "", "[ID:554]", $pcode, 1) ControlClick("Item Maintenance", "", "[ID:622]") ControlSend("Item Maintenance", "", "[ID:664]", $pe, 1) ControlSend("Item Maintenance", "", "[ID:666]", $pm, 1) ControlSend("Item Maintenance", "", "[ID:668]", $pwo, 1) ;WinMenuSelectItem("Item Maintenance - ", "", "&Edit", "&Save") ;WinClose("Item Maintenance - ") ;If Not WinActive("Order Line Maintenance - ") Then ;WinActivate("Order Line Maintenance - ") ;EndIf EndIf ;#cs WinWaitActive("Information", "", 2) ControlClick("Information", "", "[ID:2]") If $qty > 1 Then ControlSend("Order Line Maintenance - ", "", "[ID:370]", $qty) EndIf ControlSend("Order Line Maintenance - ", "", "[ID:371]", $charge) ControlSend("Order Line Maintenance - ", "", "[ID:372]", $date) ControlClick("Order Line Maintenance - ", "", "[ID:374]") Send("{END}{ENTER}{ENTER}") If StringLen($exnotes) > 1 Then $exnotesyes = 1 Else $exnotesyes = 0 EndIf WinWaitActive("Order Line Maintenance - " & $loc & " - Notes") Switch $type Case "CONCEPT" Or "RECONCEPT" $send = "DESC: " & $desc & "{ENTER}{ENTER}" & $type & "{ENTER}{ENTER}SEE ATTACHED PWO/EMAIL{ENTER}{ENTER}" $send &= "SHIP VIA EMAIL CONCEPT PROJECT TO:{ENTER}" & $attn & "{ENTER}" & $email If $exnotesyes Then $send &= "{ENTER}{ENTER}" & $exnotes EndIf Send($send & "{TAB 2}{SPACE}") Case "SAMPLE" Or "RESAMPLE" $send = "DESC: " & $desc & "{ENTER}{ENTER}" & $type & "{ENTER}{ENTER}SEE ATTACHED PWO/EMAIL{ENTER}{ENTER}" $send &= "SHIP TO ATTN:{ENTER}" & $attn If $exnotesyes Then $send &= "{ENTER}{ENTER}" & $exnotes EndIf Send($send & "{TAB 2}{SPACE}") Case "ADDL SAMPL" $send = $qty & " ADDITIONAL SAMPLES{ENTER}{ENTER}DESC: " & $desc & "{ENTER}{ENTER}GAUGE/MATERIAL: " & $gauge & "/" & $material $send &= "{ENTER}{ENTER}SEE ATTACHED FORM/EMAIL{ENTER}{ENTER}SHIP TO ATTN:{ENTER}" & $attn If $exnotesyes Then $send &= "{ENTER}{ENTER}" & $exnotes EndIf Send($send & "{TAB 2}{SPACE}") Case "BLISTER FORM TOOL" Or "HEAT SINK TOOL" If $exnotesyes Then Send($send & "{TAB 2}{SPACE}") Else MsgBox(64, "Message", "You did not enter in any extra notes and this is a Blister Form Tool or Heat Sink Tool. Enter in the notes now.") EndIf Case Default MsgBox(64, "Message", "Unknown entry for 'Notes.' Please enter in notes now.") WinWaitClose("Order Line Maintenance - " & $loc & " - Notes") EndSwitch WinWaitActive("Order Line Maintenance - ") ControlSend("Order Line Maintenance - ", "", "[ID:376]", "EA") ControlSend("Order Line Maintenance - ", "", "[ID:406]", $desc, 1) Send("{TAB}") WinWaitActive("Validate", "OK", 1) If WinActive("Validate", "OK") Then ControlClick("Validate", "", "[ID:2]") EndIf WinWaitActive("Question", "OK", 1) If WinActive("Question", "OK") Then ControlClick("Question", "", "[ID:1]") EndIf If $po = "N/C" Then ControlSend("Order Line Maintenance - ", "", "[ID:439]", "100") Else ControlSend("Order Line Maintenance - ", "", "[ID:439]", $podisc) EndIf WinMenuSelectItem("Order Line Maintenance - ", "", "&Edit", "&Save") WinWaitActive("Warning", "OK", 1) If WinActive("Warning", "OK") Then MsgBox(48, "Error", "Credit hold. Unable to continue.") Exit EndIf WinMenuSelectItem("Order Line Maintenance - ", "", "&Reports", "&Order Reports", "Order &Verification") WinWaitActive("Order Verification - ") WinMenuSelectItem("Order Verification - ", "", "&Edit", "&Print") WinWaitActive("Success", "OK", 5) ControlClick("Success", "", "[ID:2]") WinMenuSelectItem("Order Verification - ", "", "&Edit", "&Update") WinWaitActive("Order Verification - ") ControlSend("Order Verification - ", "", "[ID:1606]", "F") ControlSend("Order Verification - ", "", "[ID:1607]", "C:\SYMWORK\" & $sca & ".DOC") Send("{F2}") WinMenuSelectItem("Order Verification - ", "", "&Edit", "&Print") WinWaitActive("Success", "OK", 5) ControlClick("Success", "", "[ID:2]") WinClose("Order Verification - ") ControlClick("Order Line Maintenance - ", "", "[ID:412]") WinWaitActive("Question", "OK", 3) ControlClick("Question", "", "[ID:1]") ControlClick("Order Line Maintenance - ", "", "[ID:412]") WinWaitActive("Job Orders - ") WinMenuSelectItem("Job Orders - ", "", "&Activities", "&Copy Routing/BOM") WinWaitActive("Job Orders - ") If $type = "CONCEPT" Or $type = "RECONCEPT" Then ControlSend("Copy Routing/BOM - ", "", "[ID:1071]", "CONCEPT ROUTING TEMPLATE") ElseIf $type = "SAMPLE" Or $type = "RESAMPLE" Then ControlSend("Copy Routing/BOM - ", "", "[ID:1071]", "SAMPLE ROUTING TEMPLATE") ElseIf $type = "ADDITIONAL SAMPLES" Then ControlSend("Copy Routing/BOM - ", "", "[ID:1071]", "ADDL SAMPLE ROUTING TEMPLATE") ElseIf $type = "HEAT SEAL TOOL" Then ControlSend("Copy Routing/BOM - ", "", "[ID:1071]", "HSTBOM") ElseIf $type = "BLISTER FORM TOOL" Then ControlSend("Copy Routing/BOM - ", "", "[ID:1071]", "FORM TOOL ROUTING TEMPLATE") EndIf If $type = "HEAT SEAL TOOL" Then ControlClick("Copy Routing/BOM - ", "", "[ID:1105]") WinWaitActive("Information", 5) Send("{SPACE}{SPACE}") Else WinWaitActive("Copy Routing/BOM - ") ControlSend("Copy Routing/BOM - ", "", "[ID:1079]", "Y") Send("{TAB}") ControlClick("Copy Routing/BOM - ", "", "[ID:1105]") WinWaitActive("Information", 5) Send("{SPACE}{SPACE}") EndIf WinClose("Copy Routing/BOM - ") ControlClick("Job Orders - ", "", "[ID:967]") WinWaitActive("Information", "PDM Information Sent", 5) ControlClick("Information", "", "[ID:2]") WinMenuSelectItem("Job Orders - ", "", "&Reports", "&Job Paperwork") WinWaitActive("Job Paperwork - ") WinMenuSelectItem("Job Paperwork - ", "", "&Edit", "&Update") WinWaitActive("Job Paperwork - ") ControlSend("Job Paperwork - ", "", "[ID:1688]", "Y") ControlSend("Job Paperwork - ", "", "[ID:1691]", "A") ControlSend("Job Paperwork - ", "", "[ID:1694]", "N") ControlSend("Job Paperwork - ", "", "[ID:1700]", "N") Send("{F2}") WinMenuSelectItem("Job Paperwork - ", "", "&Edit", "&Print") WinWaitActive("Success") ControlClick("Success", "", "[ID:2]") WinActivate("Job Paperwork - ") WinMenuSelectItem("Job Paperwork - ", "", "&Edit", "&Update") WinWaitActive("Job Paperwork - ") ControlSend("Job Paperwork - ", "", "[ID:1688]", "N") Send("{F2}") WinMenuSelectItem("Job Paperwork - ", "", "&Edit", "&Print") WinWaitActive("Success") ControlClick("Success", "", "[ID:2]") WinClose("Job Paperwork - ") WinClose("Job Orders - ") WinClose("Order Line Maintenance - ") WinClose("Order Maintenance - ") Sleep(1000) $boxlbl = MsgBox(36, "Box Label", "Do you need to create a box label?") If $boxlbl = 6 Then MsgBox(48, "Excel", "Please ensure that Microsoft Excel is in your task bar.") If WinExists("Microsoft Excel - BOX LABEL MAKER") Then WinMinimizeAll() $salesperson = InputBox("Salesperson", "Please enter the salesperson:", "", " M", 190, 115) If $newitem = 0 Then $compname = InputBox("Company Name", "Please enter the company name:", "", " M", 190, 115) EndIf $sca = GUICtrlRead($txtSca) $pwo = GUICtrlRead($txtPwo) $desc = GUICtrlRead($txtDesc) WinActivate("Microsoft Excel - BOX LABEL MAKER") WinSetState("Microsoft Excel - BOX LABEL MAKER", "", @SW_RESTORE) If Not WinActive("Microsoft Excel - BOX LABEL MAKER") Then MsgBox(16, "Error", "'Microsoft Excel - BOX LABEL MAKER' was not found. Exiting.") Exit EndIf Sleep(1250) Send("^g") WinWaitActive("Go To") Send("H1{ENTER}") Send($sca & "{ENTER}") Send("^g") WinWaitActive("Go To") Send("H2{ENTER}") Send($pwo & "{ENTER}") Send("^g") WinWaitActive("Go To") Send("H3{ENTER}") Send($compname & "{ENTER}") Send("^g") WinWaitActive("Go To") Send("H4{ENTER}") Send($desc & "{ENTER}") Send("^g") WinWaitActive("Go To") Send("H5{ENTER}") Send($salesperson & "{ENTER}") Send("^p") Sleep(1000) Send("{ENTER}") EndIf EndIf Sleep(1000) WinMinimizeAll() #ce
Siao Posted September 26, 2007 Posted September 26, 2007 Does the "Instance" number of a control change each run too? "be smart, drink your wine"
jvanegmond Posted September 26, 2007 Posted September 26, 2007 Does the "Instance" number of a control change each run too?The information in the first post is different from the information given in the screenshot, so I think you can safely assume that the instance number also is different each time.I guess you could only do this by either sending {TAB}'s to the window, but that would require the window to be activated. Or use a mouseclick.. github.com/jvanegmond
Tasmania Posted September 26, 2007 Author Posted September 26, 2007 (edited) Yes, much much moreso than ID does. Instance changes with each "new" item. Well, if I knew how to select a text box and send text based off of a handle, I'd immagine that I could easily do this. I don't really know. Edited September 26, 2007 by Tasmania
Siao Posted September 26, 2007 Posted September 26, 2007 You can get control handle by calling WindowFromPoint, but it needs that window to be active. Is that OK with you? "be smart, drink your wine"
Tasmania Posted September 26, 2007 Author Posted September 26, 2007 That's fine, but I did a quick search for WindowFromPoint in the help file and found nothing. What is this? Basically I just need to select the RELATIVE position of a text box to enter text into it, it doesn't matter if it has focus or not, however the script needs to be able to select the text box no matter where the window is placed on the desktop.
Siao Posted September 26, 2007 Posted September 26, 2007 (edited) Ok, the following does not require the window to be active:$sWinTitle = "Calculator" Run("Calc.exe") WinWait($sWinTitle) $h1 = ControlGetHandle($sWinTitle,"","[CLASS:Edit; INSTANCE:1]") $h2 = _ChildWindowFromPoint($sWinTitle, 12, 7) MsgBox(0,$sWinTitle & " Edit control handle", "Using ControlGetHandle(): "& @TAB&@TAB & $h1 & @CRLF & _ "Using _ChildWindowFromPoint(): " & @TAB & $h2) ControlSend($sWinTitle, "", $h2, "1234") ;=============================================================================== ; ; Function Name: _ChildWindowFromPoint() ; Description: Returns the handle of child window relative to the coords of the client area of the parent ; Parameter(s): $sWinTitle = Title or handle of parent window. ; $nX, $nY = relative coords to the client area of parent window ; Return Value(s): On Success - Handle ; On Failure - 0 ; ;=============================================================================== Func _ChildWindowFromPoint($sWinTitle, $nX, $nY) If IsHWnd($sWinTitle) Then $hWnd = $sWinTitle Else $hWnd = WinGetHandle($sWinTitle) If @error Then Return 0 EndIf $aRet = DLLCall("user32.dll", "hwnd", "ChildWindowFromPoint", "hwnd", $hWnd, "long", $nX, "long", $nY) If @error Then Return 0 Return $aRet[0] EndFunc Edited September 26, 2007 by Siao "be smart, drink your wine"
Tasmania Posted September 26, 2007 Author Posted September 26, 2007 I greatly appreciate your code and your time, however there is still one problem... $h1 = ControlGetHandle($sWinTitle,"","[CLASS:Edit; INSTANCE:1]") As far as I can tell, that line of code requires that the class and instance of the item you are attempting to discover the handle of never changes, however in my application both the class and instance are even moreso unstable than the ID. From what I know of the application that we run on, apparently the Class and Instance are re-created every time you enter a "new" item, and because of this, those are more apt to change because of a small thing being different here or there. As far as ID is concerned, I have not discovered if those are assigned based off of each time an instance of the application is created (IE they are reassigned each time the application opens) or if they are assigned based upon windows session (IE they are assigned at login). At any rate, the ID seemed very stable up until today, which is the point that I discovered my AutoIt no longer ran.
Siao Posted September 26, 2007 Posted September 26, 2007 (edited) The key in my previous post is the _ChildWindowFromPoint() function, which requires only parent window title and coordinates. The code above it is just an example to prove that the function works (the handle returned by both methods should be the same) and how to use it. Edited September 26, 2007 by Siao "be smart, drink your wine"
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