Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 09/08/2024 in all areas

  1. You might be better to use UIAutomation. Here the code to locate your button : #NoTrayIcon ; https://www.autoitscript.com/forum/topic/201683-ui-automation-udfs/ #include "Includes\CUIAutomation2.au3" #include <Constants.au3> Opt("MustDeclareVars", 1) If @OSVersion <> "WIN_7" Then Exit MsgBox ($MB_SYSTEMMODAL,"","This script only works on Win 7") Local $aMenu = _Systray_SelectOption("Name of your button here") ; <<<<<<<<<<<<<<<<<< change this Func _Systray_SelectOption($sButton) Local $hWnd = WinGetHandle('[Class:Shell_TrayWnd]') If Not $hWnd Then Return SetError(1) Local $hCtrl = ControlGetHandle($hWnd, '', "ToolbarWindow321") ; button must be visible If Not $hCtrl Then Return SetError(2) ; Create UI Automation object Local $oUIAutomation = ObjCreateInterface($sCLSID_CUIAutomation, $sIID_IUIAutomation, $dtagIUIAutomation) If Not IsObj($oUIAutomation) Then Return ConsoleWrite("$oUIAutomation ERR" & @CRLF) ConsoleWrite("$oUIAutomation OK" & @CRLF) ; Get Desktop element Local $pDesktop, $oDesktop $oUIAutomation.GetRootElement($pDesktop) $oDesktop = ObjCreateInterface($pDesktop, $sIID_IUIAutomationElement, $dtagIUIAutomationElement) If Not IsObj($oDesktop) Then Return ConsoleWrite("$oDesktop ERR" & @CRLF) ConsoleWrite("$oDesktop OK" & @CRLF) ; Get element by handle Local $pElement, $oElement $oUIAutomation.ElementFromHandle($hCtrl, $pElement) $oElement = ObjCreateInterface($pElement, $sIID_IUIAutomationElement, $dtagIUIAutomationElement) If Not IsObj($oElement) Then Return ConsoleWrite("$oElement ERR" & @CRLF) ConsoleWrite("$oElement OK" & @CRLF) ; Get condition (ControlType = Button) Local $pCondition, $oCondition $oUIAutomation.CreatePropertyCondition($UIA_ControlTypePropertyId, $UIA_ButtonControlTypeId, $pCondition) $oCondition = ObjCreateInterface($pCondition, $sIID_IUIAutomationPropertyCondition, $dtagIUIAutomationPropertyCondition) If Not IsObj($oCondition) Then Return ConsoleWrite("$oCondition ERR" & @CRLF) ConsoleWrite("$oCondition OK" & @CRLF) ; Find all buttons Local $pElementArray, $oElementArray, $iElements $oElement.FindAll($TreeScope_Children, $oCondition, $pElementArray) $oElementArray = ObjCreateInterface($pElementArray, $sIID_IUIAutomationElementArray, $dtagIUIAutomationElementArray) $oElementArray.Length($iElements) If Not IsObj($oElementArray) Then Return ConsoleWrite("$oElementArray ERR" & @CRLF) ConsoleWrite("$oElementArray OK" & @CRLF) ; Get array of buttons Local $aElements[$iElements] For $i = 0 To $iElements - 1 $oElementArray.GetElement($i, $pElement) $aElements[$i] = ObjCreateInterface($pElement, $sIID_IUIAutomationElement, $dtagIUIAutomationElement) Next ; Get name and position for each button Local $sValue Local $tRect = DllStructCreate("long Left;long Top;long Right;long Bottom") Local $tPoint = DllStructCreate("long X;long Y"), $bBool For $i = 0 To UBound($aElements) - 1 $aElements[$i].GetCurrentPropertyValue($UIA_NamePropertyId, $sValue) ConsoleWrite("Name = " & $sValue) $aElements[$i].CurrentBoundingRectangle($tRect) ConsoleWrite("/ L:" & $tRect.Left & " T:" & $tRect.Top & " R:" & $tRect.Right & " B:" & $tRect.Bottom & @CRLF) $aElements[$i].GetClickablePoint($tPoint, $bBool) If StringInStr($sValue, $sButton) Then MouseClick("Right", $tPoint.X, $tPoint.Y, 1, 1) ConsoleWrite("Found and clicked !" & @CRLF) ExitLoop EndIf Next EndFunc
    1 point
  2. For those of you that use Resource Hacker it has recently been updated and the OLD way of using it's commands has changed. I mainly use it to remove additional icon files from my executables but you can do other things with it also to alter your executables if you can't directly within AutoIT. Resource Hacker Version 4.5.30 Last updated: 27 November 2016 Resource Hacker Website Since the new versions changed the command structure it took me forever to figure out how to make this work automagically in my scripts again. Here is what I figured out and what I still don't know. This is the OLD command structure that no longer works with the newer and most recent version. #AutoIt3Wrapper_Outfile=NameOfFile.exe #AutoIt3Wrapper_Outfile_x64=NameOfFile.exe #AutoIt3Wrapper_Run_After="C:\Resource Hacker\ResourceHacker.exe" -delete %out%, %out%, ICON, 1, #AutoIt3Wrapper_Run_After="C:\Resource Hacker\ResourceHacker.exe" -delete %out%, %out%, ICON, 5, #AutoIt3Wrapper_Run_After="C:\Resource Hacker\ResourceHacker.exe" -delete %out%, %out%, ICON, 11, #AutoIt3Wrapper_Run_After="C:\Resource Hacker\ResourceHacker.exe" -delete %out%, %out%, ICONGROUP, 99, #AutoIt3Wrapper_Run_After="C:\Resource Hacker\ResourceHacker.exe" -delete %out%, %out%, ICONGROUP, 162, #AutoIt3Wrapper_Run_After="C:\Resource Hacker\ResourceHacker.exe" -delete %out%, %out%, ICONGROUP, 164, #AutoIt3Wrapper_Run_After="C:\Resource Hacker\ResourceHacker.exe" -delete %out%, %out%, ICONGROUP, 169, %out% is a Scite command, I am using that to write and compile my scripts from, Scite Editor. This is the name of your executable with the Path included. %outx64% is the same as above but for 64 bit versions of your executable if it is named different than the non 64 bit version. I just name both the same but it gets controlled by the "#AutoIt3Wrapper_UseX64=Y" directive if you want to use it or you can output both file versions using the compile utility "Ctrl+F7." Probably shouldn't name both the same name if you do that. The old version I was using you had to delete the Icons and the Icon Groups individually similar to above. In the new version this will give a fatal error, you are not allowed to directly access the Icons at all now. Instead you just delete the Icon Group and the icons associated to that group gets deleted automagically. In the new version a problem I discovered that I can't get around. If you have spaces in the path for your executable Resource Hacker refuses to do anything and fails with an error. Example: %out% = c:\your work folder\subfolder work\NameOfFile.exe <-- Spaces in path According to resource hacker help you are suppose to wrap these with double quotes. Doing this though that command line fails which stops further Resource Hacker commands if you have any. The error states something about the action doesn't exist or something to that extent. What action? No idea. In the older versions of Resource Hacker though this worked for me but the new version it won't if there is spaces in the path for your executable file. I got around this by directly naming the output file without a path, replacing the %out%, this saves it in the current working directory. I tried putting double quotes around %out% but again the command line failed so I gave up and just specifically named the file without a path. Here is the NEW command structure you must use for DELETE. #AutoIt3Wrapper_Run_After="C:\Resource Hacker\ResourceHacker.exe" -open fileName.exe -save fileName.exe -action delete -mask ICONGROUP,99, #AutoIt3Wrapper_Run_After="C:\Resource Hacker\ResourceHacker.exe" -open fileName.exe -save fileName.exe -action delete -mask ICONGROUP,162, #AutoIt3Wrapper_Run_After="C:\Resource Hacker\ResourceHacker.exe" -open fileName.exe -save fileName.exe -action delete -mask ICONGROUP,164, #AutoIt3Wrapper_Run_After="C:\Resource Hacker\ResourceHacker.exe" -open fileName.exe -save fileName.exe -action delete -mask ICONGROUP,169, 1: You must now explicitly Open AND Save the executable. You were doing that before but it's reworked now so there is more you have to add to the command. 2: For DELETING you have to use the actual command "-action" then followed by the action in this specific case Delete. "- action delete" 3: You have to tell Resource Hacker the Mask. I don't really know what that is but it seems to be the name of the resource like ICON or ICONGROUP followed by the name of the group like 99 or 164. There are THREE comma's you have to use in the Mask but only Two are used. I don't know what the third one is for but if you don't add the third comma it doesn't work. I add my own icons into my executable from within my script, not using Resource Hacker but the extra icons that are in the finished executable I don't want and I can't find a command to get rid of them from AutoIT side so that is why I use Resource Hacker. The four Icon Groups above remove ALL the additonal Icons from my executable leaving only my own icons in the file which makes it a bit smaller in size too. I hope you can benefit from my trial and error and head bashing to get this to work again. Also if you can figure out how to get %out% to work that would be great, I gave up on it.
    1 point
×
×
  • Create New...