Leaderboard
Popular Content
Showing content with the highest reputation on 01/25/2019 in all areas
-
IDL to AU3 generator
Earthshine reacted to junkew for a topic
Working on a new version of iuiautomation and uia wrappers I needed a better way of getting my interface's Concept version 0.6 to generate based on idl file an au3 file with the definitions. As allways its more complicated then I thought ;-) due to small differences in the idl files on closing braces, separating inheritance colon inconsistencies in the idl tool that generates them so most likely its better to write a lexer/parser then the search/replace I do now Alternatives typelibinspector but could not generate them all at once aiowrappergenerator was generating for aio and not for objcreateinterface based on tli interfaces / xml but seemed incomplete Known issues Enums without given constant values to be filled in manually Enum adding fix first parameter to have a $ Empty interfaces fail on _ to be replaced with "" propput and propget deal with methods with same name Must be wrapped in main function $i counting to be done differently Working on the typedef's and replacements of identifiers in the string (some are replaced) enum automatically is a long typedefs are automatically assumed an int (which is not perfect but a start) struct like POINT pt is now generated as int Testing/debugging Choices done get_ and put_ prefixing only for put_ as that will have less impact on existing scripts that do not use get_ like ControlViewWalker, Current.. properties etc. So instead of Global Const $sIID_IUIAutomationCacheRequest = "{B32A92B5-BC25-4078-9C08-D7EE95C48E03}" Global $dtagIUIAutomationCacheRequest = _ "AddProperty hresult(int);" & _ "AddPattern hresult(int);" & _ "Clone hresult(ptr*);" & _ "get_TreeScope hresult(long*);" & _ "put_TreeScope hresult(long);" & _ "get_TreeFilter hresult(ptr*);" & _ "put_TreeFilter hresult(ptr);" & _ "get_AutomationElementMode hresult(long*);" & _ "put_AutomationElementMode hresult(long);" it will be like (see for example TreeScope and put_TreeScope) Global Const $sIID_IUIAutomationCacheRequest = "{b32a92b5-bc25-4078-9c08-d7ee95c48e03}" Global $dtagIUIAutomationCacheRequest= _ "AddProperty hresult(struct);" & _ "AddPattern hresult(int);" & _ "Clone hresult(ptr*);" & _ "TreeScope hresult(long*);" & _ "put_TreeScope hresult(long);" & _ "TreeFilter hresult(ptr*);" & _ "put_TreeFilter hresult(ptr);" & _ "AutomationElementMode hresult(long*);" & _ "put_AutomationElementMode hresult(long);" Prerequisites Win 10 SDK installed at location as given in constants to have IDL file Output File with same name as idl in scriptdir with extension au3 having the definitions for OBJCreateInterface Example output ;~ // ;~ // IUIAutomation ;~ // ;~[object, uuid(30cbe57d-d9d0-452a-ab13-7ac5ac4825ee), pointer_default(unique)] ;~interface IUIAutomation : IUnknown Global Const $sIID_IUIAutomation = "{30cbe57d-d9d0-452a-ab13-7ac5ac4825ee}" Global $dtag_IUIAutomation= _ "CompareElements hresult(IUIAutomationElement*el1,IUIAutomationElement*el2,int*);" & _ "CompareRuntimeIds hresult(SAFEARRAY(int)runtimeId1,SAFEARRAY(int)runtimeId2,intareSame);" & _ "GetRootElement hresult(IUIAutomationElement**);" & _ "ElementFromHandle hresult(UIA_inthwnd,IUIAutomationElement**);" & _ "ElementFromPoint hresult(intpt,IUIAutomationElement**);" & _ "GetFocusedElement hresult(IUIAutomationElement**);" & _ "GetRootElementBuildCache hresult(IUIAutomationCacheRequest*cacheRequest,IUIAutomationElement**);" & _ "ElementFromHandleBuildCache hresult(UIA_inthwnd,IUIAutomationCacheRequest*cacheRequest,IUIAutomationElement**);" & _ "ElementFromPointBuildCache hresult(intpt,IUIAutomationCacheRequest*cacheRequest,IUIAutomationElement**);" & _ "GetFocusedElementBuildCache hresult(IUIAutomationCacheRequest*cacheRequest,IUIAutomationElement**);" & _ "CreateTreeWalker hresult(IUIAutomationCondition*pCondition,IUIAutomationTreeWalker**);" & _ "ControlViewWalker hresult(IUIAutomationTreeWalker**);" & _ "ContentViewWalker hresult(IUIAutomationTreeWalker**);" & _ "RawViewWalker hresult(IUIAutomationTreeWalker**);" & _ "RawViewCondition hresult(IUIAutomationCondition**);" & _ "ControlViewCondition hresult(IUIAutomationCondition**);" & _ "ContentViewCondition hresult(IUIAutomationCondition**);" & _ "CreateCacheRequest hresult(IUIAutomationCacheRequest**);" & _ "CreateTrueCondition hresult(IUIAutomationCondition**);" & _ "CreateFalseCondition hresult(IUIAutomationCondition**);" & _ "CreatePropertyCondition hresult(intpropertyId,variantvalue,IUIAutomationCondition**);" & _ "CreatePropertyConditionEx hresult(intpropertyId,variantvalue,longflags,IUIAutomationCondition**);" & _ "CreateAndCondition hresult(IUIAutomationCondition*condition1,IUIAutomationCondition*condition2,IUIAutomationCondition**);" & _ "CreateAndConditionFromArray hresult(SAFEARRAY(IUIAutomationCondition)conditions,IUIAutomationCondition**);" & _ "CreateAndConditionFromNativeArray hresult(IUIAutomationCondition**conditions,intconditionCount,IUIAutomationCondition**);" & _ "CreateOrCondition hresult(IUIAutomationCondition*condition1,IUIAutomationCondition*condition2,IUIAutomationCondition**);" & _ "CreateOrConditionFromArray hresult(SAFEARRAY(IUIAutomationCondition)conditions,IUIAutomationCondition**);" & _ "CreateOrConditionFromNativeArray hresult(IUIAutomationCondition**conditions,intconditionCount,IUIAutomationCondition**);" & _ "CreateNotCondition hresult(IUIAutomationCondition*condition,IUIAutomationCondition**);" & _ "AddAutomationEventHandler hresult(inteventId,IUIAutomationElement*element,longscope,IUIAutomationCacheRequest*cacheRequest,IUIAutomationEventHandler*);" & _ "RemoveAutomationEventHandler hresult(inteventId,IUIAutomationElement*element,IUIAutomationEventHandler*);" & _ "AddPropertyChangedEventHandlerNativeArray hresult(IUIAutomationElement*element,longscope,IUIAutomationCacheRequest*cacheRequest,IUIAutomationPropertyChangedEventHandler*handler,int*propertyArray,int);" & _ "AddPropertyChangedEventHandler hresult(IUIAutomationElement*element,longscope,IUIAutomationCacheRequest*cacheRequest,IUIAutomationPropertyChangedEventHandler*handler,SAFEARRAY(PROPERTYID));" & _ "RemovePropertyChangedEventHandler hresult(IUIAutomationElement*element,IUIAutomationPropertyChangedEventHandler*);" & _ "AddStructureChangedEventHandler hresult(IUIAutomationElement*element,longscope,IUIAutomationCacheRequest*cacheRequest,IUIAutomationStructureChangedEventHandler*);" & _ "RemoveStructureChangedEventHandler hresult(IUIAutomationElement*element,IUIAutomationStructureChangedEventHandler*);" & _ "AddFocusChangedEventHandler hresult(IUIAutomationCacheRequest*cacheRequest,IUIAutomationFocusChangedEventHandler*);" & _ "RemoveFocusChangedEventHandler hresult(IUIAutomationFocusChangedEventHandler*);" & _ "RemoveAllEventHandlers hresult);" & _ "IntNativeArrayToSafeArray hresult(int*array,intarrayCount,SAFEARRAY(int)*);" & _ "IntSafeArrayToNativeArray hresult(SAFEARRAY(int)intArray,int**array,int*);" & _ "RectTovariant hresult(intrc,variant*);" & _ "variantToRect hresult(variantvar,int*);" & _ "SafeArrayToRectNativeArray hresult(SAFEARRAY(double)rects,int**rectArray,int*);" & _ "CreateProxyFactoryEntry(IUIAutomationProxyFactory hresult*factory,IUIAutomationProxyFactoryEntry);" & _ "ProxyFactoryMapping(IUIAutomationProxyFactoryMapping hresult);" & _ "GetPropertyProgrammaticName(int hresultproperty,int*);" & _ "GetPatternProgrammaticName(int hresultpattern,int*);" & _ "PollForPotentialSupportedPatterns(IUIAutomationElement hresult*pElement,SAFEARRAY(int)*patternIds,SAFEARRAY(BSTR)patternNames);" & _ "PollForPotentialSupportedProperties(IUIAutomationElement hresult*pElement,SAFEARRAY(int)*propertyIds,SAFEARRAY(BSTR)propertyNames);" & _ "CheckNotSupported(variant hresultvalue,intisNotSupported);" & _ "ReservedNotSupportedValue(IUnknown hresult**notSupportedValue);" & _ "ReservedMixedAttributeValue(IUnknown hresult**mixedAttributeValue);" & _ "ElementFromIAccessible hresult(IAccessible*accessible,intchildId,IUIAutomationElement**);" & _ "ElementFromIAccessibleBuildCache hresult(IAccessible*accessible,intchildId,IUIAutomationCacheRequest*cacheRequest,IUIAutomationElement**);" ;~} Script #include <FileConstants.au3> #include <MsgBoxConstants.au3> #include <StringConstants.au3> #include <Array.au3> ;~ testit() ;~ Exit Local $IDLFolder="C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\um\" Local $IDLFileName="UIAutomationClient.idl" Local $IDLFullFileName = $IDLFolder & $IDLFileName Local $IDLArray = FileReadToArray($IDLFullFileName) Local $iLineCount = @extended Local $IDLAU3FullFileName=@ScriptDir & "\" & $IDLFileName $IDLAU3FullFileName=stringreplace($IDLAU3FullFileName,".idl",".au3") If @error Then MsgBox($MB_SYSTEMMODAL, "", "There was an error reading the file. @error: " & @error) ; An error occurred reading the current script file. exit EndIf Local $hFileOpen = FileOpen($IDLAU3FullFileName, $FO_OVERWRITE ) If $hFileOpen = -1 Then MsgBox($MB_SYSTEMMODAL, "", "An error occurred whilst writing the new au3 file.") exit EndIf ;~TODO: Naming prefixing Global $interfaceName Global $GUID Global $i=0 while $i < $iLineCount - 1 ;~ consolewrite($i) $tLine=$IDLArray[$i] $blockType=0 if stringleft($tLine,2)="//" then $blockType=1 if stringleft($tLine,4)="cpp_" then $blockType=1 if stringleft($tLine,1)="#" then $blockType=1 if stringleft($tLine,6)="import" then $blockType=1 if stringleft($tLine,4)="midl" then $blockType=1 if $blockType=1 Then writeCommentedLine() continueloop; EndIf if stringleft($tLine,4)="enum" then $blockType=2 handleEnumBlock() EndIf if stringinstr($tLine, "module ") > 0 then $blockType=3 handleModuleBlock() EndIf if stringinstr($tLine, "[object") > 0 then $blockType=4 handleObjectBlock() EndIf if stringinstr($tLine, "interface ") > 0 then $blockType=5 handleInterfaceBlock() EndIf if $blockType=0 Then writeUnhandledLine() EndIf WEnd func writeUnhandledLine() filewriteline($hFileOpen,";~" & $tline) $i=$i+1 EndFunc func writeCommentedLine() $tLineOut=stringstripws($tLine, $STR_STRIPLEADING + $STR_STRIPTRAILING) if $tLineOut <> "" Then $tLineOut=";~" & $tLineOut filewriteline($hFileOpen, $tLineOut) $i=$i+1 EndFunc func handleEnumBlock() writeCommentedLine() ;~ Copy enum line $tLine=$IDLArray[$i] writeCommentedLine() ;~ Copy curly brace line $tLine=$IDLArray[$i] while stringstripws($tLine, $STR_STRIPLEADING + $STR_STRIPTRAILING) <> "};" $tPos=getPosFirstNonWhiteSpace($tLine) if ($tpos=0) or (stringmid($tLine,$tPos+1,2)="//") Then writeCommentedLine() Else $tLine=stringleft($tLine,$tPos) & "Global Const $" & stringmid($tline,$tPos+1) $tLine=stringreplace($tLine, ",","") $tLine=stringreplace($tLine, "| ","+ $") writeEnumLine() EndIf $tLine=$IDLArray[$i] WEnd EndFunc func writeEnumLine() filewriteline($hFileOpen, $tline) $i=$i+1 EndFunc func handleModuleBlock() writeCommentedLine() ;~ Copy module line $tLine=$IDLArray[$i] writeCommentedLine() ;~ Copy curly brace line $tLine=$IDLArray[$i] $tValue=stringstripws($tLine, $STR_STRIPLEADING + $STR_STRIPTRAILING) ;~ Some end with }; and some with } while stringleft($tValue,1) <> "}" $tPos=getPosFirstNonWhiteSpace($tLine) if ($tpos=0) or (stringmid($tLine,$tPos+1,2)="//") Then if ($tpos=0) then $i=$i+1 ;~ Do no output Else writeCommentedLine() EndIf Else $tLine=stringreplace($tline,"const long ", "Global Const $") $tLine=stringreplace($tLine, ";","") writeModuleLine() EndIf $tLine=$IDLArray[$i] $tValue=stringstripws($tLine, $STR_STRIPLEADING + $STR_STRIPTRAILING) WEnd writeCommentedLine() ;~ Copy curly closing brace line EndFunc func writeModuleLine() filewriteline($hFileOpen, $tline) $i=$i+1 EndFunc func handleObjectBlock() writeCommentedLine() $tPos=stringinstr($tLine,"(") $tPos2=stringinstr($tLine,")") $GUID=stringmid($tLine,$tpos+1, $tPos2-1 - $tpos) ;~ consolewrite($GUID & @CRLF) EndFunc func handleInterfaceBlock() if stringright($tLine,1)=";" Then writeCommentedLine() ;~ Copy Interface line its just a definition line Return EndIf writeCommentedLine() ;~ Copy interface line $interfaceName=getInterfaceName() writeInterFaceLine1() $tLine=$IDLArray[$i] ;~ writeCommentedLine() ;~ Copy curly brace line $i=$i+1 ;~ Do no output $tLine=$IDLArray[$i] $tValue=stringstripws($tLine, $STR_STRIPLEADING + $STR_STRIPTRAILING) ;~ Some end with }; and some with } while stringleft($tValue,1) <> "}" $tPos=getPosFirstNonWhiteSpace($tLine) if ($tpos=0) or (stringmid($tLine,$tPos+1,2)="//") Then if ($tpos=0) then $i=$i+1 ;~ Do no output Else $i=$i+1 ;~ Do no output, AU3 does not like it in multiline strings ;~ writeCommentedLine() EndIf Else while stringright($tLine,1) <> ";" $i=$i+1 $tLine=$tLine & stringstripws($IDLArray[$i], $STR_STRIPLEADING + $STR_STRIPTRAILING) wend writeInterfaceLine() EndIf $tLine=$IDLArray[$i] $tValue=stringstripws($tLine, $STR_STRIPLEADING + $STR_STRIPTRAILING) WEnd ;~ consolewrite($IDLArray[$i-1] & @CRLF) ;~ consolewrite($IDLArray[$i] & @CRLF) ;~ consolewrite($IDLArray[$i+1] & @CRLF) writeCommentedLine() ;~ Copy curly closing brace line EndFunc func writeInterFaceLine1() $tOutputLine="Global Const $sIID_" & getInterfaceName() & " = " $tOutputLine=$tOutputLine & """" $tOutputLine=$tOutputLine & "{" & $GUID & "}" $tOutputLine=$tOutputLine & """" filewriteline($hFileOpen, $tOutputLine) $toutputLine = "Global $dtag" & getInterfaceName() & "= _" & @CRLF filewriteline($hFileOpen, $tOutputLine) EndFunc func writeInterfaceLine() $tmpLine=stringstripws($tLine, $STR_STRIPLEADING + $STR_STRIPTRAILING) if stringleft($tmpLine,1)="}" Then filewriteline($hFileOpen, $tmpLine) $i=$i+1 return EndIf ;~ Handle get/put properties prefix local $strPrefix="" if stringinstr($tmpLine,"[propget]")>0 then ;~ no prefix for the get as its more logical/natural in AutoIt to do it without (as oppossed to C where get_ is more logical ;~ $strPrefix="get_" ;~ consolewrite($tmpLine & @CRLF) $tmpLine=stringreplace($tmpLine, "[propget] ", "", 0, $STR_CASESENSE) EndIf if stringinstr($tmpLine,"[propput]")>0 then ;~ prefix for the put as it can get in conflict with the get duplicate name $strPrefix="put_" ;~ consolewrite($tmpLine & @CRLF) $tmpLine=stringreplace($tmpLine, "[propput] ", "", 0, $STR_CASESENSE) EndIf ; $tmpLine ="HRESULT FindAll ([in] enum TreeScope scope,[in] IUIAutomationCondition * condition, [out, retval] IUIAutomationElementArray ** found );" ;~ $tmpLine="[propget] HRESULT PropertyId ([out, retval] PROPERTYID * propertyId );" ;~ $tmpLine="HRESULT GetCurrentPropertyValue ([in] PROPERTYID propertyId,[out, retval] VARIANT * retVal);" ;~ $tmpLine="HRESULT FindAllBuildCache ([in] enum TreeScope scope,[in] IUIAutomationCondition * condition,[in] IUIAutomationCacheRequest * cacheRequest,[out, retval] IUIAutomationElementArray ** found );" $tmpLine=stringreplace($tmpLine, "HRESULT", "hresult", 0, $STR_CASESENSE) $tmpLine=stringreplace($tmpLine, "VARIANT", "variant", 0, $STR_CASESENSE) $tmpLine=stringreplace($tmpLine, "BSTR", "bstr", 0, $STR_CASESENSE) $tmpLine=stringreplace($tmpLine, "BOOL", "bool", 0, $STR_CASESENSE) $tmpLine=stringreplace($tmpLine, "void", "none", 0, $STR_CASESENSE) ;~ Some where we are sure it should not be an int $tmpLine=stringreplace($tmpLine, "POINT", "struct", 0, $STR_CASESENSE) $tmpLine=stringreplace($tmpLine, "PROPERTYID", "struct", 0, $STR_CASESENSE) $tmpLine=stringreplace($tmpLine, "RECT", "struct", 0, $STR_CASESENSE) $tmpLine=stringreplace($tmpLine, "UIA_HWND", "hwnd", 0, $STR_CASESENSE) ;~ Some cleanup for parsing later $tmpLine=stringreplace($tmpLine, "(", " (") $tmpLine=stringreplace($tmpLine, " (", " (") $tmpLine=stringreplace($tmpLine, " );", ");") ;~ remove the pointer references for in/out parameters if stringinstr($tmpLine,"[in")>0 then $tmpLine=stringreplace($tmpLine, "[propget] ", "", 0, $STR_CASESENSE) $tmpLine=stringreplace($tmpLine, "**", "SINGLESTAR") $tmpLine=stringreplace($tmpLine, "*", "") $tmpLine=stringreplace($tmpLine, "SINGLESTAR", "*") EndIf ;~ For out parameter we keep the pointer * if stringinstr($tmpLine,"[out")>0 then $tmpLine=stringreplace($tmpLine, "[propget] ", "", 0, $STR_CASESENSE) $tmpLine=stringreplace($tmpLine, "**", "SINGLESTAR") ;~ $tmpLine=stringreplace($tmpLine, "*", "") $tmpLine=stringreplace($tmpLine, "SINGLESTAR", "*") EndIf $tmpLine=StringRegExpReplace($tmpLine,"[A-Z]+ ","int ") ;~ TODO: assumption full uppercase is a TYPEDEF frequently int but definitily not sure $tmpLine=StringRegExpReplace($tmpLine,"enum [A-Za-z_]+ ","long ") ;~ An enum followed by an identifier is normally a long $tmpLine=StringRegExpReplace($tmpLine,"\[.*?] "," ") ;~ [in, out] stuff followed by space we normally ignore, space we keep for separator ;~ reshuffle and remove varnames $aArray=stringsplit($tmpLine," ") if ($aArray[0] < 2) then _arraydisplay($aArray) consolewrite(stringstripws($tLine, $STR_STRIPLEADING + $STR_STRIPTRAILING)) consolewrite($tmpLine) EndIf $tOutputLine= $strPrefix & $aArray[2] & " " & $aArray[1] For $j = 3 To $aArray[0] $strAppend= $aArray[$j] if (stringright($aArray[$j],1))= "," then $strAppend= ";" if (stringright($aArray[$j],1))= ";" then if $aArray[$j]<>"();" then $strAppend= ");" EndIf $strAppend=getnewtype($strAppend) $tOutputLine= $tOutputLine & $strAppend Next ;~ $tOutputLine= $tOutputLine & $aarray[$aArray[0]] $tOutputline = @TAB & """" & $tOutputLine & """" $tValue=stringstripws($IDLArray[$i+1], $STR_STRIPLEADING + $STR_STRIPTRAILING) ;~ sometimes its not just 1 line ahead for closing but 2 lines ahead if $tValue="" then $tValue=stringstripws($IDLArray[$i+2], $STR_STRIPLEADING + $STR_STRIPTRAILING) endif if (stringleft($tValue,1) <> "}") then $tOutputLine= $tOutputLine & " & _ " filewriteline($hFileOpen, $tOutputLine) $i=$i+1 EndFunc func getPosFirstNonWhiteSpace($str) Local $aArray = StringToASCIIArray($str) for $i=0 to ubound($aArray)-1 if $aArray[$i]<>32 Then return $i Next return 0 EndFunc func getInterfaceName() $tmpLine=stringstripws($tLine, $STR_STRIPLEADING + $STR_STRIPTRAILING) $tArr=stringsplit($tmpLine," ") $tName=$tarr[2] if stringright($tname,1)=":" then $tName=stringleft($tname,stringlen($tname)-1) return $tname EndFunc func testIt() ;~ $tmpline="HRESULT SetFocus ( );" ; $tmpLine ="HRESULT FindAll ([in] enum TreeScope scope,[in] IUIAutomationCondition * condition, [out, retval] IUIAutomationElementArray ** found );" $tmpLine="[propget] HRESULT PropertyId ([out, retval] PROPERTYID * propertyId );" ;~ $tmpLine="HRESULT GetCurrentPropertyValue ([in] PROPERTYID propertyId,[out, retval] VARIANT * retVal);" ;~ $tmpLine="HRESULT FindAllBuildCache ([in] enum TreeScope scope,[in] IUIAutomationCondition * condition,[in] IUIAutomationCacheRequest * cacheRequest,[out, retval] IUIAutomationElementArray ** found );" $strPrefix="" if stringinstr($tmpLine,"[propget]")>0 then $strPrefix="get_" if stringinstr($tmpLine,"[propput]")>0 then $strPrefix="put_" consolewrite($strPrefix) ;~ consolewrite($tOutputline & @CRLF) ;~ consolewrite($tmpLine) ;~ _arraydisplay($aArray) EndFunc func getNewType($str) $retVal=stringregexp($str, "[A-Za-z0-9_]+", $STR_REGEXPMATCH) ;~ if stringleft($str,"3") = "ret" then consolewrite($retVal & $str & @CRLF) if $retval=0 then return $str $tStr=$str & "," $objTypes="none,byte,boolean,short,word,ushort,int,long,bool,dword," & _ "ulong,uint,hresult,int64,uint64,ptr,hwnd,handle,float," & _ "double,int_ptr,long_ptr,lresult,lparam,uint_ptr,ulong_ptr,"& _ "dword_ptr,wparam,str,wstr,bstr,variant,idispatch,object," & _ "clsid,struct,*,**" if stringinstr($objtypes,$tstr)>0 Then return $str return "ptr" EndFunc1 point -
There is an issue, while using the function SendSciTE_Command by @Jos, if more than one instance of SciTE is open. Each instance of SciTE has its own DirectorExtension window, so we must choose the right one. Here is a way to solve this: ; by BugFix Func _GetHwndDirectorExtension() Local $hActive = WinGetHandle('[ACTIVE]') Local $PIDActive = WinGetProcess($hActive) Local $aExtension = WinList("DirectorExtension") Local $PIDExt For $i = 1 To $aExtension[0][0] $PIDExt = WinGetProcess($aExtension[$i][1]) If $PIDExt = $PIDActive Then Return $aExtension[$i][1] Next EndFunc ; by Jos Func SendSciTE_Command($_sCmd) Local $WM_COPYDATA = 74 Local $WM_GETTEXT = 0x000D Local $WM_GETTEXTLENGTH = 0x000E224 Local Const $SCI_GETLINE = 2153 ;~ Local $Scite_hwnd = WinGetHandle("DirectorExtension") ; Get SciTE DIrector Handle Local $Scite_hwnd = _GetHwndDirectorExtension() ; Get SciTE DIrector Handle Local $My_Hwnd = GUICreate("AutoIt3-SciTE interface") ; Create GUI to receive SciTE info Local $My_Dec_Hwnd = Dec(StringTrimLeft($My_Hwnd, 2)) ; Convert my Gui Handle to decimal $_sCmd = ":" & $My_Dec_Hwnd & ":" & $_sCmd ; Add dec my gui handle to commandline to tell SciTE where to send the return info Local $CmdStruct = DllStructCreate('Char[' & StringLen($_sCmd) + 1 & ']') DllStructSetData($CmdStruct, 1, $_sCmd) Local $COPYDATA = DllStructCreate('Ptr;DWord;Ptr') DllStructSetData($COPYDATA, 1, 1) DllStructSetData($COPYDATA, 2, StringLen($_sCmd) + 1) DllStructSetData($COPYDATA, 3, DllStructGetPtr($CmdStruct)) DllCall('User32.dll', 'None', 'SendMessage', 'HWnd', $Scite_hwnd, _ 'Int', $WM_COPYDATA, 'HWnd', $My_Hwnd, _ 'Ptr', DllStructGetPtr($COPYDATA)) GUIDelete($My_Hwnd) EndFunc ;==>SendSciTE_Command Func MY_WM_COPYDATA($hWnd, $msg, $wParam, $lParam) Local $COPYDATA = DllStructCreate('Ptr;DWord;Ptr', $lParam) Local $SciTECmdLen = DllStructGetData($COPYDATA, 2) Local $CmdStruct = DllStructCreate('Char[' & $SciTECmdLen+1 & ']',DllStructGetData($COPYDATA, 3)) ;~ Local $CmdStruct = DllStructCreate('Char[255]', DllStructGetData($COPYDATA, 3)) $SciTECmd = StringLeft(DllStructGetData($CmdStruct, 1), $SciTECmdLen) EndFunc ;==>MY_WM_COPYDATA1 point
-
[solved] Set icon on hidden window
argumentum reacted to Subz for a topic
The following works: https://www.autoitscript.com/forum/topic/168698-changing-a-windows-icon/?do=findComment&comment=1233266 #include <WinAPI.au3> AutoItWinSetTitle(StringTrimRight(@ScriptName, 4) & "|PID:" & @AutoItPID) WinSetState(StringTrimRight(@ScriptName, 4) & "|PID:" & @AutoItPID, "", @SW_SHOW) TraySetIcon(StringLeft(@AutoItExe, StringInStr(@AutoItExe, "\", 0, -1)) & "Icons\au3.ico") ControlSetText(StringTrimRight(@ScriptName, 4) & "|PID:" & @AutoItPID, "", "Edit1", '@Compiled = ' & (@Compiled = 1)) Local $hGui = WinGetHandle(AutoItWinGetTitle()) _WinSetIcon($hGui, "C:\Windows\Notepad.exe") While 1 Sleep(50) WEnd Func _WinSetIcon($hWnd, $sFile, $iIndex = 0) Local $tIcons = DllStructCreate("ptr Data") DllCall("shell32.dll", "uint", "ExtractIconExW", "wstr", $sFile, "int", $iIndex, "struct*", 0, "struct*", $tIcons, "uint", 1) If @error Then Return SetError(1, 0, 0) Local $hIcon = DllStructGetData($tIcons, "Data") _SendMessage($hWnd, 0x0080, 1, $hIcon ) ;$WM_SETICON = 0x0080 _WinAPI_DestroyIcon($hIcon) Return 1 EndFunc1 point -
Sample code creation through Detail info listview page The Detail info listview page is also the default listview page. This makes sample code creation easy and fast. But not all code can be created this way. In many cases, there is a need to use the Sample code main menu. Sample code is created by selecting one or more rows in a single listview group. Right-click a selected row and click Create sample code. The code is displayed in the listview code page. Click Create sample code in the picture above to generate this code: ; --- Find window/control --- ConsoleWrite( "--- Find window/control ---" & @CRLF ) Local $pCondition0 $oUIAutomation.CreatePropertyCondition( $UIA_ClassNamePropertyId, "Notepad", $pCondition0 ) If Not $pCondition0 Then Return ConsoleWrite( "$pCondition0 ERR" & @CRLF ) ConsoleWrite( "$pCondition0 OK" & @CRLF ) Local $pWindow, $oWindow $oDesktop.FindFirst( $TreeScope_Descendants, $pCondition0, $pWindow ) $oWindow = ObjCreateInterface( $pWindow, $sIID_IUIAutomationElement, $dtagIUIAutomationElement ) If Not IsObj( $oWindow ) Then Return ConsoleWrite( "$oWindow ERR" & @CRLF ) ConsoleWrite( "$oWindow OK" & @CRLF ) Click the selected treeview item in the left pane window to return to the detail information and add more sample code. Or paste the code into the code editor. Create sample code also copies the code to clipboard. Only selected rows that specifically belongs to the listview group in which a row is right-clicked are included in sample code. The only exception to this are the groups "Element Properties (identification)" and "Element Properties (session unique)". For these two groups, selected rows from both groups are included in sample code. This makes it possible to use session unique properties in window identification: Click Create sample code in the picture to generate this code: ; --- Find window/control --- ConsoleWrite( "--- Find window/control ---" & @CRLF ) Local $pCondition0, $pCondition1, $pAndCondition1 $oUIAutomation.CreatePropertyCondition( $UIA_ClassNamePropertyId, "Notepad", $pCondition0 ) $oUIAutomation.CreatePropertyCondition( $UIA_NativeWindowHandlePropertyId, 0x0000000000050314, $pCondition1 ) $oUIAutomation.CreateAndCondition( $pCondition0, $pCondition1, $pAndCondition1 ) If Not $pAndCondition1 Then Return ConsoleWrite( "$pAndCondition1 ERR" & @CRLF ) ConsoleWrite( "$pAndCondition1 OK" & @CRLF ) Local $pWindow, $oWindow $oDesktop.FindFirst( $TreeScope_Descendants, $pAndCondition1, $pWindow ) $oWindow = ObjCreateInterface( $pWindow, $sIID_IUIAutomationElement, $dtagIUIAutomationElement ) If Not IsObj( $oWindow ) Then Return ConsoleWrite( "$oWindow ERR" & @CRLF ) ConsoleWrite( "$oWindow OK" & @CRLF ) See Automating Notepad with sample code - step by step and Automating Notepad with sample code - all at once for examples of creating sample code.1 point
-
Automating Notepad with Sample code - all at once In an automation task like the Notepad example above, it's much faster to create all sample code at once than it is to create the sample code in a step-by-step procedure. For pattern methods, it's also faster to create sample code by selecting the method through the Pattern... item in the Sample code menu in UIASpy than it is to create pattern method sample code through the detail information listview page. But to use the pattern listview page you need to know which pattern to use. The advantage of using the detail information listview page is that it only shows the patterns and pattern methods that are applicable to the specific control. These are all the steps in the Notepad example: Add initial code Open Notepad Sleep( 1000 ) Get Notepad window Fill Edit control Identify Edit control Execute SetValue pattern method Open File menu Identify File menu Execute Invoke pattern method Sleep( 100 ) Click Save As... menu item Identify Save As... menu item Execute Invoke pattern method Sleep( 1000 ) Get Save As window Fill Edit control (File name) Identify Edit control Execute SetValue pattern method Click Save button Identify Save button Execute Invoke pattern method Corrections And this is sample code for all the steps in the entire Notepad example. Examples\Notepad\Windows 7, 10\3) Sample code - all at once\1) Before corrections.au3: #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 ;#AutoIt3Wrapper_UseX64=n ; If target application is running as 32 bit code ;#AutoIt3Wrapper_UseX64=y ; If target application is running as 64 bit code #include "CUIAutomation2.au3" Opt( "MustDeclareVars", 1 ) Example() Func Example() ; 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 ) EndFunc ; --- Find window/control --- ConsoleWrite( "--- Find window/control ---" & @CRLF ) Local $pCondition0 $oUIAutomation.CreatePropertyCondition( $UIA_ClassNamePropertyId, "Notepad", $pCondition0 ) If Not $pCondition0 Then Return ConsoleWrite( "$pCondition0 ERR" & @CRLF ) ConsoleWrite( "$pCondition0 OK" & @CRLF ) Local $pWindow, $oWindow $oDesktop.FindFirst( $TreeScope_Descendants, $pCondition0, $pWindow ) $oWindow = ObjCreateInterface( $pWindow, $sIID_IUIAutomationElement, $dtagIUIAutomationElement ) If Not IsObj( $oWindow ) Then Return ConsoleWrite( "$oWindow ERR" & @CRLF ) ConsoleWrite( "$oWindow OK" & @CRLF ) ; --- Find window/control --- ConsoleWrite( "--- Find window/control ---" & @CRLF ) Local $pCondition1 $oUIAutomation.CreatePropertyCondition( $UIA_AutomationIdPropertyId, "15", $pCondition1 ) If Not $pCondition1 Then Return ConsoleWrite( "$pCondition1 ERR" & @CRLF ) ConsoleWrite( "$pCondition1 OK" & @CRLF ) Local $pEdit, $oEdit $oParent.FindFirst( $TreeScope_Descendants, $pCondition1, $pEdit ) $oEdit = ObjCreateInterface( $pEdit, $sIID_IUIAutomationElement, $dtagIUIAutomationElement ) If Not IsObj( $oEdit ) Then Return ConsoleWrite( "$oEdit ERR" & @CRLF ) ConsoleWrite( "$oEdit OK" & @CRLF ) ; --- Value Pattern (action) Object --- ConsoleWrite( "--- Value Pattern (action) Object ---" & @CRLF ) Local $pValuePattern, $oValuePattern $oEdit.GetCurrentPattern( $UIA_ValuePatternId, $pValuePattern ) $oValuePattern = ObjCreateInterface( $pValuePattern, $sIID_IUIAutomationValuePattern, $dtagIUIAutomationValuePattern ) If Not IsObj( $oValuePattern ) Then Return ConsoleWrite( "$oValuePattern ERR" & @CRLF ) ConsoleWrite( "$oValuePattern OK" & @CRLF ) $oValuePattern.SetValue(bstr) ; --- Find window/control --- ConsoleWrite( "--- Find window/control ---" & @CRLF ) Local $pCondition2, $pCondition3, $pAndCondition3 $oUIAutomation.CreatePropertyCondition( $UIA_ControlTypePropertyId, $UIA_MenuItemControlTypeId, $pCondition2 ) $oUIAutomation.CreatePropertyCondition( $UIA_NamePropertyId, "File", $pCondition3 ) $oUIAutomation.CreateAndCondition( $pCondition2, $pCondition3, $pAndCondition3 ) If Not $pAndCondition3 Then Return ConsoleWrite( "$pAndCondition3 ERR" & @CRLF ) ConsoleWrite( "$pAndCondition3 OK" & @CRLF ) Local $pMenuItem, $oMenuItem $oParent.FindFirst( $TreeScope_Descendants, $pAndCondition3, $pMenuItem ) $oMenuItem = ObjCreateInterface( $pMenuItem, $sIID_IUIAutomationElement, $dtagIUIAutomationElement ) If Not IsObj( $oMenuItem ) Then Return ConsoleWrite( "$oMenuItem ERR" & @CRLF ) ConsoleWrite( "$oMenuItem OK" & @CRLF ) ; --- Invoke Pattern (action) Object --- ConsoleWrite( "--- Invoke Pattern (action) Object ---" & @CRLF ) Local $pInvokePattern, $oInvokePattern $oMenuItem.GetCurrentPattern( $UIA_InvokePatternId, $pInvokePattern ) $oInvokePattern = ObjCreateInterface( $pInvokePattern, $sIID_IUIAutomationInvokePattern, $dtagIUIAutomationInvokePattern ) If Not IsObj( $oInvokePattern ) Then Return ConsoleWrite( "$oInvokePattern ERR" & @CRLF ) ConsoleWrite( "$oInvokePattern OK" & @CRLF ) $oInvokePattern.Invoke() Sleep( 1000 ) ; --- Find window/control --- ConsoleWrite( "--- Find window/control ---" & @CRLF ) Local $pCondition4, $pCondition5, $pAndCondition5 $oUIAutomation.CreatePropertyCondition( $UIA_AutomationIdPropertyId, "4", $pCondition4 ) $oUIAutomation.CreatePropertyCondition( $UIA_ControlTypePropertyId, $UIA_MenuItemControlTypeId, $pCondition5 ) $oUIAutomation.CreateAndCondition( $pCondition4, $pCondition5, $pAndCondition5 ) If Not $pAndCondition5 Then Return ConsoleWrite( "$pAndCondition5 ERR" & @CRLF ) ConsoleWrite( "$pAndCondition5 OK" & @CRLF ) Local $pMenuItem, $oMenuItem $oParent.FindFirst( $TreeScope_Descendants, $pAndCondition5, $pMenuItem ) $oMenuItem = ObjCreateInterface( $pMenuItem, $sIID_IUIAutomationElement, $dtagIUIAutomationElement ) If Not IsObj( $oMenuItem ) Then Return ConsoleWrite( "$oMenuItem ERR" & @CRLF ) ConsoleWrite( "$oMenuItem OK" & @CRLF ) ; --- Invoke Pattern (action) Object --- ConsoleWrite( "--- Invoke Pattern (action) Object ---" & @CRLF ) Local $pInvokePattern, $oInvokePattern $oMenuItem.GetCurrentPattern( $UIA_InvokePatternId, $pInvokePattern ) $oInvokePattern = ObjCreateInterface( $pInvokePattern, $sIID_IUIAutomationInvokePattern, $dtagIUIAutomationInvokePattern ) If Not IsObj( $oInvokePattern ) Then Return ConsoleWrite( "$oInvokePattern ERR" & @CRLF ) ConsoleWrite( "$oInvokePattern OK" & @CRLF ) $oInvokePattern.Invoke() Sleep( 1000 ) ; --- Find window/control --- ConsoleWrite( "--- Find window/control ---" & @CRLF ) Local $pCondition6 $oUIAutomation.CreatePropertyCondition( $UIA_ClassNamePropertyId, "#32770", $pCondition6 ) If Not $pCondition6 Then Return ConsoleWrite( "$pCondition6 ERR" & @CRLF ) ConsoleWrite( "$pCondition6 OK" & @CRLF ) Local $pWindow, $oWindow $oParent.FindFirst( $TreeScope_Descendants, $pCondition6, $pWindow ) $oWindow = ObjCreateInterface( $pWindow, $sIID_IUIAutomationElement, $dtagIUIAutomationElement ) If Not IsObj( $oWindow ) Then Return ConsoleWrite( "$oWindow ERR" & @CRLF ) ConsoleWrite( "$oWindow OK" & @CRLF ) ; --- Find window/control --- ConsoleWrite( "--- Find window/control ---" & @CRLF ) Local $pCondition7 $oUIAutomation.CreatePropertyCondition( $UIA_AutomationIdPropertyId, "1001", $pCondition7 ) If Not $pCondition7 Then Return ConsoleWrite( "$pCondition7 ERR" & @CRLF ) ConsoleWrite( "$pCondition7 OK" & @CRLF ) Local $pEdit, $oEdit $oParent.FindFirst( $TreeScope_Descendants, $pCondition7, $pEdit ) $oEdit = ObjCreateInterface( $pEdit, $sIID_IUIAutomationElement, $dtagIUIAutomationElement ) If Not IsObj( $oEdit ) Then Return ConsoleWrite( "$oEdit ERR" & @CRLF ) ConsoleWrite( "$oEdit OK" & @CRLF ) ; --- Value Pattern (action) Object --- ConsoleWrite( "--- Value Pattern (action) Object ---" & @CRLF ) Local $pValuePattern, $oValuePattern $oEdit.GetCurrentPattern( $UIA_ValuePatternId, $pValuePattern ) $oValuePattern = ObjCreateInterface( $pValuePattern, $sIID_IUIAutomationValuePattern, $dtagIUIAutomationValuePattern ) If Not IsObj( $oValuePattern ) Then Return ConsoleWrite( "$oValuePattern ERR" & @CRLF ) ConsoleWrite( "$oValuePattern OK" & @CRLF ) $oValuePattern.SetValue(bstr) ; --- Find window/control --- ConsoleWrite( "--- Find window/control ---" & @CRLF ) Local $pCondition8, $pCondition9, $pAndCondition9 $oUIAutomation.CreatePropertyCondition( $UIA_AutomationIdPropertyId, "1", $pCondition8 ) $oUIAutomation.CreatePropertyCondition( $UIA_ControlTypePropertyId, $UIA_ButtonControlTypeId, $pCondition9 ) $oUIAutomation.CreateAndCondition( $pCondition8, $pCondition9, $pAndCondition9 ) If Not $pAndCondition9 Then Return ConsoleWrite( "$pAndCondition9 ERR" & @CRLF ) ConsoleWrite( "$pAndCondition9 OK" & @CRLF ) Local $pButton, $oButton $oParent.FindFirst( $TreeScope_Descendants, $pAndCondition9, $pButton ) $oButton = ObjCreateInterface( $pButton, $sIID_IUIAutomationElement, $dtagIUIAutomationElement ) If Not IsObj( $oButton ) Then Return ConsoleWrite( "$oButton ERR" & @CRLF ) ConsoleWrite( "$oButton OK" & @CRLF ) ; --- Invoke Pattern (action) Object --- ConsoleWrite( "--- Invoke Pattern (action) Object ---" & @CRLF ) Local $pInvokePattern, $oInvokePattern $oButton.GetCurrentPattern( $UIA_InvokePatternId, $pInvokePattern ) $oInvokePattern = ObjCreateInterface( $pInvokePattern, $sIID_IUIAutomationInvokePattern, $dtagIUIAutomationInvokePattern ) If Not IsObj( $oInvokePattern ) Then Return ConsoleWrite( "$oInvokePattern ERR" & @CRLF ) ConsoleWrite( "$oInvokePattern OK" & @CRLF ) $oInvokePattern.Invoke() ; Code corrections: ; CUIAutomation2.au3 path ; Code to open target appl ; Create undeclared variables ; Delete double declared variables ; Correct $pWindow, $pParent and $pControl names ; Correct $oWindow, $oParent and $oControl names The code isn't immediately executable. It's necessary to make some corrections. Most corrections are listed at the bottom of the code as comments. Note that all condition variables are created properly. They need no corrections. This is the code after corrections. Examples\Notepad\Windows 7, 10\3) Sample code - all at once\2) After corrections.au3: #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 ;#AutoIt3Wrapper_UseX64=n ; If target application is running as 32 bit code ;#AutoIt3Wrapper_UseX64=y ; If target application is running as 64 bit code #include "..\..\..\..\Includes\CUIAutomation2.au3" Opt( "MustDeclareVars", 1 ) Example() Func Example() ; Open Notepad Run( "Notepad" ) Sleep( 1000 ) ; 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 Notepad window --- ConsoleWrite( "--- Get Notepad window ---" & @CRLF ) Local $pCondition0 $oUIAutomation.CreatePropertyCondition( $UIA_ClassNamePropertyId, "Notepad", $pCondition0 ) If Not $pCondition0 Then Return ConsoleWrite( "$pCondition0 ERR" & @CRLF ) ConsoleWrite( "$pCondition0 OK" & @CRLF ) Local $pNotepad, $oNotepad $oDesktop.FindFirst( $TreeScope_Descendants, $pCondition0, $pNotepad ) $oNotepad = ObjCreateInterface( $pNotepad, $sIID_IUIAutomationElement, $dtagIUIAutomationElement ) If Not IsObj( $oNotepad ) Then Return ConsoleWrite( "$oNotepad ERR" & @CRLF ) ConsoleWrite( "$oNotepad OK" & @CRLF ) ; --- Fill Edit control --- ConsoleWrite( "--- Fill Edit control ---" & @CRLF ) Local $pCondition1 $oUIAutomation.CreatePropertyCondition( $UIA_AutomationIdPropertyId, "15", $pCondition1 ) If Not $pCondition1 Then Return ConsoleWrite( "$pCondition1 ERR" & @CRLF ) ConsoleWrite( "$pCondition1 OK" & @CRLF ) Local $pEdit, $oEdit $oNotepad.FindFirst( $TreeScope_Descendants, $pCondition1, $pEdit ) $oEdit = ObjCreateInterface( $pEdit, $sIID_IUIAutomationElement, $dtagIUIAutomationElement ) If Not IsObj( $oEdit ) Then Return ConsoleWrite( "$oEdit ERR" & @CRLF ) ConsoleWrite( "$oEdit OK" & @CRLF ) Local $pValuePattern, $oValuePattern $oEdit.GetCurrentPattern( $UIA_ValuePatternId, $pValuePattern ) $oValuePattern = ObjCreateInterface( $pValuePattern, $sIID_IUIAutomationValuePattern, $dtagIUIAutomationValuePattern ) If Not IsObj( $oValuePattern ) Then Return ConsoleWrite( "$oValuePattern ERR" & @CRLF ) ConsoleWrite( "$oValuePattern OK" & @CRLF ) $oValuePattern.SetValue( "HelloWorld" ) ; --- Open File menu --- ConsoleWrite( "--- Open File menu ---" & @CRLF ) Local $pCondition2, $pCondition3, $pAndCondition3 $oUIAutomation.CreatePropertyCondition( $UIA_ControlTypePropertyId, $UIA_MenuItemControlTypeId, $pCondition2 ) $oUIAutomation.CreatePropertyCondition( $UIA_NamePropertyId, "File", $pCondition3 ) ; <<<<<<<<<<<<<<<<<<<<<<<< $oUIAutomation.CreateAndCondition( $pCondition2, $pCondition3, $pAndCondition3 ) If Not $pAndCondition3 Then Return ConsoleWrite( "$pAndCondition3 ERR" & @CRLF ) ConsoleWrite( "$pAndCondition3 OK" & @CRLF ) Local $pMenuItem, $oMenuItem $oNotepad.FindFirst( $TreeScope_Descendants, $pAndCondition3, $pMenuItem ) $oMenuItem = ObjCreateInterface( $pMenuItem, $sIID_IUIAutomationElement, $dtagIUIAutomationElement ) If Not IsObj( $oMenuItem ) Then Return ConsoleWrite( "$oMenuItem ERR" & @CRLF ) ConsoleWrite( "$oMenuItem OK" & @CRLF ) Local $pInvokePattern, $oInvokePattern $oMenuItem.GetCurrentPattern( $UIA_InvokePatternId, $pInvokePattern ) $oInvokePattern = ObjCreateInterface( $pInvokePattern, $sIID_IUIAutomationInvokePattern, $dtagIUIAutomationInvokePattern ) If Not IsObj( $oInvokePattern ) Then Return ConsoleWrite( "$oInvokePattern ERR" & @CRLF ) ConsoleWrite( "$oInvokePattern OK" & @CRLF ) $oInvokePattern.Invoke() Sleep( 100 ) ; --- Click Save As... menu item --- ConsoleWrite( "--- Click Save As... menu item ---" & @CRLF ) Local $pCondition4, $pCondition5, $pAndCondition5 $oUIAutomation.CreatePropertyCondition( $UIA_AutomationIdPropertyId, "4", $pCondition4 ) $oUIAutomation.CreatePropertyCondition( $UIA_ControlTypePropertyId, $UIA_MenuItemControlTypeId, $pCondition5 ) $oUIAutomation.CreateAndCondition( $pCondition4, $pCondition5, $pAndCondition5 ) If Not $pAndCondition5 Then Return ConsoleWrite( "$pAndCondition5 ERR" & @CRLF ) ConsoleWrite( "$pAndCondition5 OK" & @CRLF ) $oNotepad.FindFirst( $TreeScope_Descendants, $pAndCondition5, $pMenuItem ) $oMenuItem = ObjCreateInterface( $pMenuItem, $sIID_IUIAutomationElement, $dtagIUIAutomationElement ) If Not IsObj( $oMenuItem ) Then Return ConsoleWrite( "$oMenuItem ERR" & @CRLF ) ConsoleWrite( "$oMenuItem OK" & @CRLF ) $oMenuItem.GetCurrentPattern( $UIA_InvokePatternId, $pInvokePattern ) $oInvokePattern = ObjCreateInterface( $pInvokePattern, $sIID_IUIAutomationInvokePattern, $dtagIUIAutomationInvokePattern ) If Not IsObj( $oInvokePattern ) Then Return ConsoleWrite( "$oInvokePattern ERR" & @CRLF ) ConsoleWrite( "$oInvokePattern OK" & @CRLF ) $oInvokePattern.Invoke() Sleep( 1000 ) ; --- Get Save As window --- ConsoleWrite( "--- Get Save As window ---" & @CRLF ) Local $pCondition6 $oUIAutomation.CreatePropertyCondition( $UIA_ClassNamePropertyId, "#32770", $pCondition6 ) If Not $pCondition6 Then Return ConsoleWrite( "$pCondition6 ERR" & @CRLF ) ConsoleWrite( "$pCondition6 OK" & @CRLF ) Local $pSaveAsWin, $oSaveAsWin $oNotepad.FindFirst( $TreeScope_Descendants, $pCondition6, $pSaveAsWin ) $oSaveAsWin = ObjCreateInterface( $pSaveAsWin, $sIID_IUIAutomationElement, $dtagIUIAutomationElement ) If Not IsObj( $oSaveAsWin ) Then Return ConsoleWrite( "$oSaveAsWin ERR" & @CRLF ) ConsoleWrite( "$oSaveAsWin OK" & @CRLF ) ; --- Fill Edit control (File name) --- ConsoleWrite( "--- Fill Edit control (File name) ---" & @CRLF ) Local $pCondition7 $oUIAutomation.CreatePropertyCondition( $UIA_AutomationIdPropertyId, "1001", $pCondition7 ) If Not $pCondition7 Then Return ConsoleWrite( "$pCondition7 ERR" & @CRLF ) ConsoleWrite( "$pCondition7 OK" & @CRLF ) $oSaveAsWin.FindFirst( $TreeScope_Descendants, $pCondition7, $pEdit ) $oEdit = ObjCreateInterface( $pEdit, $sIID_IUIAutomationElement, $dtagIUIAutomationElement ) If Not IsObj( $oEdit ) Then Return ConsoleWrite( "$oEdit ERR" & @CRLF ) ConsoleWrite( "$oEdit OK" & @CRLF ) $oEdit.GetCurrentPattern( $UIA_ValuePatternId, $pValuePattern ) $oValuePattern = ObjCreateInterface( $pValuePattern, $sIID_IUIAutomationValuePattern, $dtagIUIAutomationValuePattern ) If Not IsObj( $oValuePattern ) Then Return ConsoleWrite( "$oValuePattern ERR" & @CRLF ) ConsoleWrite( "$oValuePattern OK" & @CRLF ) $oValuePattern.SetValue( "HelloWorld.txt" ) ; --- Click Save button --- ConsoleWrite( "--- Click Save button ---" & @CRLF ) Local $pCondition8, $pCondition9, $pAndCondition9 $oUIAutomation.CreatePropertyCondition( $UIA_AutomationIdPropertyId, "1", $pCondition8 ) $oUIAutomation.CreatePropertyCondition( $UIA_ControlTypePropertyId, $UIA_ButtonControlTypeId, $pCondition9 ) $oUIAutomation.CreateAndCondition( $pCondition8, $pCondition9, $pAndCondition9 ) If Not $pAndCondition9 Then Return ConsoleWrite( "$pAndCondition9 ERR" & @CRLF ) ConsoleWrite( "$pAndCondition9 OK" & @CRLF ) Local $pButton, $oButton $oSaveAsWin.FindFirst( $TreeScope_Descendants, $pAndCondition9, $pButton ) $oButton = ObjCreateInterface( $pButton, $sIID_IUIAutomationElement, $dtagIUIAutomationElement ) If Not IsObj( $oButton ) Then Return ConsoleWrite( "$oButton ERR" & @CRLF ) ConsoleWrite( "$oButton OK" & @CRLF ) $oButton.GetCurrentPattern( $UIA_InvokePatternId, $pInvokePattern ) $oInvokePattern = ObjCreateInterface( $pInvokePattern, $sIID_IUIAutomationInvokePattern, $dtagIUIAutomationInvokePattern ) If Not IsObj( $oInvokePattern ) Then Return ConsoleWrite( "$oInvokePattern ERR" & @CRLF ) ConsoleWrite( "$oInvokePattern OK" & @CRLF ) $oInvokePattern.Invoke() EndFunc When executing the code, it should perform all Notepad automation tasks and generate this output in SciTE. SciTE output: $oUIAutomation OK $oDesktop OK --- Get Notepad window --- $pCondition0 OK $oNotepad OK --- Fill Edit control --- $pCondition1 OK $oEdit OK $oValuePattern OK --- Open File menu --- $pAndCondition3 OK $oMenuItem OK $oInvokePattern OK --- Click Save As... menu item --- $pAndCondition5 OK $oMenuItem OK $oInvokePattern OK --- Get Save As window --- $pCondition6 OK $oSaveAsWin OK --- Fill Edit control (File name) --- $pCondition7 OK $oEdit OK $oValuePattern OK --- Click Save button --- $pAndCondition9 OK $oButton OK $oInvokePattern OK1 point
-
Great program. Thank you VERY MUCH for it. I prefer _AD_GetObjectAttribute by email address as it's easier to remember to my users and is unique for each user at my work. so instead of FQDN or sAMAccountName I use email address so I added the following line in Func _AD_GetObjectAttribute($sObject, $sAttribute) below line: If StringMid($sObject, 3, 1) = "=" Then $sProperty = "distinguishedName" ; FQDN provided I added: if StringInStr($sObject, "@") > 0 then $sProperty = "mail" Thanks again for the great work!1 point
-
Help With StringSplit
AutoPM reacted to FrancescoDiMuro for a topic
@AutoPM You're welcome P.S.: By the way, if you want to use an online RegEx editor, try to use this website (it tells almost everything your pattern does with your test string).1 point -
Help With StringSplit
AutoPM reacted to FrancescoDiMuro for a topic
@AutoPM The pattern is described as follows: ^: anchor to match from the start of the string; (?:\/\/)?: non-capturing group. It doesn't "capture" (but matches!) the starting //, which need to be escaped with / (each of them), but their existance it's optional (?); ([^\/]+): capturing group. It "captures" anything that is not a slash, from 1 to anything; (?:\/): non-capturing group. It doesn't "capture" (but matches!) the slash; (.+): capturing group. It "captures"everything, except the new line (without the modifier ?s ("DotAll")), from 1 to anything; $: anchor to match at the end of the string.1 point -
Help With StringSplit
pixelsearch reacted to FrancescoDiMuro for a topic
@AutoPM You can use SRE too: #include <Array.au3> #include <StringConstants.au3> Global $arrStrings[5] = ["//www.autoitscript.com/forum/forum/2-autoit-general-help-and-support/", _ "www.autoitscript.com/forum/forum/2-autoit-general-help-and-support/", _ "www.abcd.efgh.com/", _ "//www.somethingelse.com.de.eu.com/abcdefgh", _ "www.a.b.c.d.e.f.g.h.com/something/somethingelse/anythingelse"], _ $strPattern = "^(?:\/\/)?([^\/]+)(?:\/)(.+)$", _ $arrResult For $strString In $arrStrings $arrResult = StringRegExp($strString, $strPattern, $STR_REGEXPARRAYGLOBALMATCH) _ArrayDisplay($arrResult) Next1 point -
delete lines containing
FrancescoDiMuro reacted to AnonymousX for a topic
@mikell Thank you!!! Exactly what I was trying to do. Appreciate the explanation too. Edit: you maybe interested to know with your help I was able to create a script that runs through 365 files, each with over 200,000 lines of data, and pinpoint all the key information into a separate file (about 300,000 lines long). With a program execution time of about 5mins. Man I love AutoIT and it's community! Thanks everyone else as well1 point -
MapIt Quest
KingOfNothing reacted to Xandy for a topic
Added a fun feature: NPCs fall from the world if NPC_Position aWorld[0][x][y][tile] = 0. The first layer of tile in world, if it is empty under NPC, NPC status is falling. A blank first layer tile is also treated as a wall by the default NPC_Movement_Type. So NPCs probably won't step off the world, but you can delete the tile under them. Just saying.1 point -
Looking at your latest query, it appears that you want to find missing songs based solely on the sh1 value. If this is true, then the following example is a different way to achieve your goal. The current query that you are using, with "cross join", is rather difficult to keep extending to meet your expanding needs. I used the table data from your last post. As I'm sure you know, all of the sha1 values are the same. So when you run the example, it will show that there are no missing songs based on sha1. I added some additional information to the console so that you can see what the example is doing. #include <Constants.au3> #include <SQLite.au3> example() Func example() Const $SQLITE_DLL = "c:\program files\sqlite\sqlite3.dll" ;<-- Change to the location of your sqlite dll ; From a list of all distinct sha1/song/id3 values for a given set of ; selected devices, this query finds all sha1 values that don't already ; exist on a specified device. So to find the result for all selected ; devices, this query needs to be UNION'd once for each selected device. ; (See the generated query in the console output) Const $SQL_QUERY_TEMPLATE = _ "SELECT <device> [device], song [missing song], id3, sha1" & @CRLF & _ "FROM (SELECT DISTINCT id3, song, sha1 from songs WHERE device IN (<selected_devices>))" & @CRLF & _ "WHERE sha1 NOT IN (SELECT sha1 FROM songs WHERE device = <device>)" & @CRLF Local $a2DResult, $aSelectedDevices[0] Local $iRows = 0, $iCols = 0 Local $sSelectedDevices = "", $sSqlQuery = "" ;Init sqlite and create a memory db _SQLite_Startup($SQLITE_DLL, False, 1) If @error Then Exit MsgBox($MB_ICONERROR, "SQLite Error", "Unable to start SQLite. Check existence of DLL") _SQLite_Open() ;Create a songs table _SQLite_Exec(-1, "BEGIN TRANSACTION;") _SQLite_Exec(-1, _ "CREATE TABLE songs (device, song, id3, sha1);" & _ "INSERT INTO songs VALUES " & _ "('Device A', 'Song 1', 'id3-1', '1x2323'), ('Device A', 'Song 3', 'id3-1', '1x2323'), ('Device A', 'Song 4', 'id3-4', '1x2323'), ('Device A', 'Song 5', 'id3-5', '1x2323'), " & _ "('Device B', 'Song 1', 'id3-1', '1x2323'), ('Device B', 'Song 2', 'id3-2', '1x2323'), ('Device B', 'Song 4', 'id3-4', '1x2323'), " & _ "('Device C', 'Song 2', 'id3-2', '1x2323'), ('Device C', 'Song 3', 'id3-2', '1x2323'), ('Device C', 'Song 4', 'id3-4', '1x2323'), ('Device C', 'Song 5', 'id3-5', '1x2323'), " & _ "('Device D', 'Song 1', 'id3-1', '1x2323'), ('Device D', 'Song 2', 'id3-2', '1x2323'), ('Device D', 'Song 3', 'id3-1', '1x2323'); " _ ) _SQLite_Exec(-1, "COMMIT;") ;Create an array of selected devices to be queried _ArrayAdd($aSelectedDevices, "Device A|Device B|Device D") ;Build "selected devices" string to be used by the query For $i = 0 To UBound($aSelectedDevices) - 1 If $i > 0 Then $sSelectedDevices &= "," $sSelectedDevices &= _SQLite_Escape($aSelectedDevices[$i]) Next ConsoleWrite(@CRLF & "Selected Devices: " & $sSelectedDevices & @CRLF) ;Build SQL Query UNIONs (one for each selected device) For $i = 0 To UBound($aSelectedDevices) - 1 If $i > 0 Then $sSqlQuery &= "UNION" & @CRLF $sSqlQuery &= StringReplace($SQL_QUERY_TEMPLATE, "<device>", _SQLite_Escape($aSelectedDevices[$i])) Next $sSqlQuery = StringReplace($sSqlQuery, "<selected_devices>", $sSelectedDevices) ConsoleWrite(@CRLF & "Generated SQL Query: " & @CRLF & $sSqlQuery) ;Execute query and display the results _SQLite_GetTable2d(-1, $sSqlQuery, $a2DResult, $iRows, $iCols) If $iRows > 0 Then ConsoleWrite(@CRLF & "Selected Devices: " & $sSelectedDevices & @CRLF & @CRLF) _SQLite_Display2DResult($a2DResult, 15) Else ConsoleWrite(@CRLF & "WARNING: No missing songs found" & @CRLF) EndIf ;Close db and shutdown sqlite _SQLite_Close() _SQLite_Shutdown() EndFunc1 point
-
New version - 13 Jan 2019 - Added: 2 new functions to hide/show and existing marquee. New UDF and example script in zip in first post. M231 point
-
thx for the explanation. Deal is great The new UIA UDF will be based on the UIA IDL files of Win10 SDK, (So I think 2-3 files) generated by the converter https://www.autoitscript.com/forum/topic/197177-idl-to-au3-generator/ Little in doubt if the generator is just good enough and some manual changes to be done afterward on generated au3 files (alternative is to build IDL lexer/parser but more work or use OAIdl.Idl to make an .au3 file and use the typelib info to generate then the au3 files) UIAWrappers will be then based on definitions of step 1 improved on finding on single propertyconditions (input you gave in this thread and UIA thread) where no regex finding is needed Extended simplespy with some addition coding examples when spied on object fixed/cleaned examples1 point
-
Based on something you wrote in 2014 in UIAutomation thread I am curious on if this still is a valid statement? why? Any example where this has to be done on a propertycondition? I am working on (MIDL to AU3 converter) instead of CUIAutomation2.au3 we will have UIAutomationClient.au3 based on the IDL UIAutomationClient.IDL and then I will generate ;~ HRESULT CreatePropertyCondition ([in] PROPERTYID propertyId, [in] VARIANT value, [out, retval] IUIAutomationCondition ** newCondition ); "CreatePropertyCondition hresult(struct;variant;ptr*);"1 point
-
Hi, There have been far too many occasions recently where the Mod team have been trying to determine whether a particular thread is legal and a member has posted offering help to the OP. If the Mods are concerned about a thread, please refrain from posting within it - and certainly do not offer anything at all useful - until the all-clear has been given. After this announcement has been posted, we will regard any future instances as unfriendly acts and the poster can expect to be sanctioned - you have been warned. M231 point
-
Detecting NTFS symlinks
AndrewSchultz reacted to Alomax for a topic
Thanks to many of you already who have posted example scripts and good questions that have already helped me on this project (unbeknownst to you). I have written a program that updates and maintains a list of programs and games across a network. Some of them are copied from a central server to the clients, others are symlinked. They are all checked every time the computer starts up to make sure their version is current and critical files are present. I have however run into a quirk that I cannot find a solution for. When an update is determined to be required, programs that are symlinked are simply deleted locally and re-linked using a file list from the server. When an update is required for a program that is flagged as "copy", I call robocopy with flags telling it only to update files that are newer or not present. The odd quirk that I have just found is that I have a game that I tried to run as a symlink, but it didn't like running multiple instances (locks data files during runtime). So I switched its flag to copy. However the script scans the directory, which is linked back to the master copy, and sees that everything is already up to date, because it's looking at itself. What I need is a function to determine if a local file/directory is "real" or a symbolic link. I've looked through the help file but I can't find anything, and apparently nobody's posted anything about it on the forum, or I'm using the wrong keywords to search.1 point -
Detecting NTFS symlinks
AndrewSchultz reacted to guinness for a topic
Search the Forum for _IsJunction.1 point