Leaderboard
Popular Content
Showing content with the highest reputation on 09/25/2021 in all areas
-
I have no clue what you want to achieve with this "script". A detailed description would be helpful. As you can notice yourself from the compiler messages, there are various syntax errors. For example, MouseGetPos is a function, so you have to set parentheses () even if you don't pass any values. Otherwise, it is treated as a variable that is currently neither declared nor has a value assignment. Here is a (quick & dirty) example, but it likely won't do what you want. #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_OutFile_Type=a3x #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** HotKeySet("{ESC}", "_Terminate") ; *** just in case of endless loop Local $4ever = 1, $ff = 1 Local $aNum ; Array Run("notepad.exe") If @error Then Exit MsgBox(BitOr(4096, 16), "Error : ", "Run Notepad fails -> Exit") Local $hWnd = WinWait("[CLASS:Notepad]", "", 10) WinActivate($hWnd) Do ; Info : Dimension Values for MouseGetPos ; None returns a two-element array containing the mouse coordinates : ; $aArray[0] = X coord (horizontal), $aArray[1] = Y coord (vertical) If ProcessExists("notepad.exe") Then $aNum = MouseGetPos() ClipPut(" X=" & $aNum[0] & " Y=" & $aNum[1] & @CRLF) ControlSend($hWnd, "", "Edit1", ClipGet(), 1) ; 1 = $SEND_RAW Sleep(500) $4ever += 1 Sleep(500) Until $4ever = 6 _Terminate() ; ------------------------------------------- Func _Terminate() WinClose($hWnd) ; answer "Quit Notepad dialog" : WinWaitActive("[CLASS:#32770]") Sleep(500) Send("{TAB}{ENTER}") Exit; EndFunc ;==>_Terminate EDIT : Local $a = 1 Local $b = 2 ; 1. Do not enclose $a, to which you want to assign a value, in parentheses. ; ($a) = $b ; <=== Error ; Use : $a = $b ConsoleWrite($a & @CRLF) $a = ($b) ConsoleWrite($a & @CRLF) $a = ($b) + 10 ConsoleWrite($a & @CRLF) ; 2. Calculations on the left side of the assignment also result in an error. ; $a + 10 = $b ; <=== Error ; ($a + 10) = $b ; <=== Error ; 3. It is different when using e.g. conditional statements : $a = 5 $b = $a + 5 If ($a + 10) > $b Then ConsoleWrite(($a + 10) & " is greater than " & $b & @CRLF) Else ConsoleWrite(($a + 10) & " is not greater than " & $b & @CRLF) EndIf P.S. Next time please post the source code (see the code tag < > in the header of the message window.) and not a screenshot.2 points
-
Convert GetRef function from VBScript to AutoIt
WilliamasKumeliukas and one other reacted to Danyfirex for a topic
Hello. Here is the Implementation of ISearchCompletedCallback If You understand how it works you will be able to implement BeginDownload required Interface callbacks. #include <WinAPICom.au3> Global Const $S_OK = 0x00000000 Global Const $E_NOINTERFACE = 0x80004002 Global Const $sIID_IUnknown = "{00000000-0000-0000-C000-000000000046}" Global Const $sIID_SearchCompletedCallback = "{88AEE058-D4B0-4725-A2F1-814A67AE964C}" Global Const $tagIUnknown = "QueryInterface hresult(ptr;ptr*);" & _ "AddRef dword();" & _ "Release dword();" Global Const $tagIDispatch = $tagIUnknown & _ "GetTypeInfoCount hresult(dword*);" & _ "GetTypeInfo hresult(dword;dword;ptr*);" & _ "GetIDsOfNames hresult(struct*;struct*;dword;dword;struct*);" & _ "Invoke hresult(uint;struct*;dword;word;struct*;struct*;ptr;uint*);" Global $oErrorHandler = ObjEvent("AutoIt.Error", "_ErrFunc") _Test() Exit Func _Test() _WinAPI_CoInitialize($COINIT_APARTMENTTHREADED) Local $oMUS = ObjCreate("Microsoft.Update.Session") Local $oSearch = $oMUS.CreateUpdateSearcher() Local $oCompleted, $tCompleted Local $dtagISearchCompletedCallback = "Invoke hresult(idispatch;ptr);" $oCompleted = __ObjectFromTag("__MyInterface_", $dtagISearchCompletedCallback, $tCompleted, Default, $sIID_SearchCompletedCallback) ;~ $oCompleted = __ObjectFromTag("__MyInterface_", $dtagISearchCompletedCallback, $tCompleted) Local $AsyncState = "Danyfirex Loves AutoIt" Local $sCriteria = "IsInstalled=0 or IsHidden=1 or IsPresent=1" ;Create Cast ObjectTag IUpdateSearcher Local $sTagSearch = $tagIDispatch & _Dummy("A", "", 8) & "BeginSearch hresult(bstr;ptr;variant;idispatch*);" & "EndSearch hresult(idispatch;idispatch*);" Local $oSearchCast = ObjCreateInterface($oSearch, "{8f45abf1-f9ae-4b95-a933-f0f66e5056ea}", $sTagSearch, False) Local $oJob = 0 ;~ $oJob = $oSearch.BeginSearch($sCriteria, $oCompleted, $Variant) ;this will not work $oSearchCast.BeginSearch($sCriteria, $oCompleted(), $AsyncState, $oJob) ;casted to make it work ConsoleWrite("$oJob.AsyncState: " & $oJob.AsyncState & @CRLF) While Not $oJob.IsCompleted Sleep(100) WEnd MsgBox(0, "ISearchCompletedCallback Invoke Reached", "Print Updates Title & Exit") Local $oSearchResult = 0 $oSearchCast.EndSearch($oJob, $oSearchResult) For $oUpdate In $oSearchResult.Updates ConsoleWrite(">" & $oUpdate.Title & @CRLF) Next $oSearchCast = 0 $oSearch = 0 $oMUS = 0 EndFunc ;==>_Test Func _Dummy($Name, $Parameters = "", $iTimes = 1) Local $sTag = "" For $i = 1 To $iTimes $sTag &= "DM_" & $Name & $i & " hresult(" & $Parameters & ");" Next Return $sTag EndFunc ;==>_Dummy Func __ObjectFromTag($sFunctionPrefix, $tagInterface, ByRef $tInterface, $bIsUnknown = Default, $sIID = "{00000000-0000-0000-C000-000000000046}") ; last param is IID_IUnknown by default If $bIsUnknown = Default Then $bIsUnknown = True Local $sInterface = $tagInterface ; copy interface description Local $tagIUnknown = "QueryInterface hresult(ptr;ptr*);" & _ "AddRef dword();" & _ "Release dword();" ; Adding IUnknown methods If $bIsUnknown Then $tagInterface = $tagIUnknown & $tagInterface ; Below line is really simple even though it looks super complex. It's just written weird to fit in one line, not to steal your attention Local $aMethods = StringSplit(StringTrimRight(StringReplace(StringRegExpReplace(StringRegExpReplace($tagInterface, "\w+\*", "ptr"), "\h*(\w+)\h*(\w+\*?)\h*(\((.*?)\))\h*(;|;*\z)", "$1\|$2;$4" & @LF), ";" & @LF, @LF), 1), @LF, 3) Local $iUbound = UBound($aMethods) Local $sMethod, $aSplit, $sNamePart, $aTagPart, $sTagPart, $sRet, $sParams, $hCallback ; Allocation $tInterface = DllStructCreate("int RefCount;int Size;ptr Object;ptr Methods[" & $iUbound & "];int_ptr Callbacks[" & $iUbound & "];ulong_ptr Slots[16]") ; 16 pointer sized elements more to create space for possible private props If @error Then Return SetError(1, 0, 0) For $i = 0 To $iUbound - 1 $aSplit = StringSplit($aMethods[$i], "|", 2) If UBound($aSplit) <> 2 Then ReDim $aSplit[2] $sNamePart = $aSplit[0] ; Replace COM types by matching dllcallback types $sTagPart = StringReplace(StringReplace(StringReplace(StringReplace($aSplit[1], "object", "idispatch"), "hresult", "long"), "bstr", "ptr"), "variant", "ptr") $sMethod = $sFunctionPrefix & $sNamePart $aTagPart = StringSplit($sTagPart, ";", 2) $sRet = $aTagPart[0] $sParams = StringReplace($sTagPart, $sRet, "", 1) $sParams = "ptr" & $sParams $hCallback = DllCallbackRegister($sMethod, $sRet, $sParams) DllStructSetData($tInterface, "Methods", DllCallbackGetPtr($hCallback), $i + 1) ; save callback pointer DllStructSetData($tInterface, "Callbacks", $hCallback, $i + 1) ; save callback handle Next DllStructSetData($tInterface, "RefCount", 1) ; initial ref count is 1 DllStructSetData($tInterface, "Size", $iUbound) ; number of interface methods DllStructSetData($tInterface, "Object", DllStructGetPtr($tInterface, "Methods")) ; Interface method pointers Return ObjCreateInterface(DllStructGetPtr($tInterface, "Object"), $sIID, $sInterface, $bIsUnknown) ; pointer that's wrapped into object EndFunc ;==>__ObjectFromTag Func __DeleteObjectFromTag(ByRef $tInterface) For $i = 1 To DllStructGetData($tInterface, "Size") DllCallbackFree(DllStructGetData($tInterface, "Callbacks", $i)) Next $tInterface = 0 EndFunc ;==>__DeleteObjectFromTag Func __MyInterface_QueryInterface($pSelf, $pRIID, $pObj) ; Ret: long Par: ptr;ptr* Local $sIID = StringFromGUID2($pRIID) If $sIID = $sIID_IUnknown Then DllStructSetData(DllStructCreate("ptr", $pObj), 1, $pSelf) Return $S_OK ElseIf $sIID = $sIID_SearchCompletedCallback Then DllStructSetData(DllStructCreate("ptr", $pObj), 1, $pSelf) Return $S_OK Else Return $E_NOINTERFACE EndIf EndFunc ;==>__MyInterface_QueryInterface Func StringFromGUID2($pGUID) Local $aReturn = DllCall('ole32.dll', 'int', 'StringFromGUID2', 'struct*', $pGUID, 'wstr', '', 'int', 65536) If @error Or Not $aReturn[0] Then Return SetError(@error + 20, @extended, '') Return SetExtended($aReturn[0], $aReturn[2]) EndFunc ;==>StringFromGUID2 Func __MyInterface_AddRef($pSelf) Return 1 EndFunc ;==>__MyInterface_AddRef Func __MyInterface_Release($pSelf) Return 1 EndFunc ;==>__MyInterface_Release Volatile Func __MyInterface_Invoke($pSelf, $oSearchJob, $pISearchCompletedCallbackArgs) ConsoleWrite("Invoke" & @CRLF) ConsoleWrite("Invoke - oSearchJob.AsyncState: " & $oSearchJob.AsyncState & @CRLF) Return $S_OK EndFunc ;==>__MyInterface_Invoke ; User's COM error function. Will be called if COM error occurs Func _ErrFunc($oError) ; Do anything here. ConsoleWrite(@ScriptName & " (" & $oError.scriptline & ") : ==> COM Error intercepted !" & @CRLF & _ @TAB & "err.number is: " & @TAB & @TAB & "0x" & Hex($oError.number) & @CRLF & _ @TAB & "err.windescription:" & @TAB & $oError.windescription & @CRLF & _ @TAB & "err.description is: " & @TAB & $oError.description & @CRLF & _ @TAB & "err.source is: " & @TAB & @TAB & $oError.source & @CRLF & _ @TAB & "err.helpfile is: " & @TAB & $oError.helpfile & @CRLF & _ @TAB & "err.helpcontext is: " & @TAB & $oError.helpcontext & @CRLF & _ @TAB & "err.lastdllerror is: " & @TAB & $oError.lastdllerror & @CRLF & _ @TAB & "err.scriptline is: " & @TAB & $oError.scriptline & @CRLF & _ @TAB & "err.retcode is: " & @TAB & "0x" & Hex($oError.retcode) & @CRLF & @CRLF) EndFunc ;==>_ErrFunc Saludos2 points -
SplashOff and Tooltip("") not working in toggle function
WhaleJesus reacted to mikell for a topic
I suppose you meant this Func ToggleST() $TooltipToggle = Not $TooltipToggle1 point -
@czardas : thank you for the information I actually found the solution: #include <GUIConstantsEx.au3> #include <WinAPI.au3> #include <APIConstants.au3> $GUI = GUICreate("Test", 800, 600) GUISetState() $LABEL1 = GUICtrlCreateLabel("under", 20, 20, 500, 300) GUICtrlSetBkColor(-1, 0xFF0000) $LABEL2 = GUICtrlCreateLabel("above", 40, 60, 500, 300) GUICtrlSetBkColor(-1, 0x00FF00) GuiCtrlSetOnTop($LABEL1) Do Sleep(50) Until GUIGetMsg() = -3 Exit Func GuiCtrlSetOnTop($iCtrlID) ;Need to include <WinAPI.au3> and <APIConstants.au3> Local $hWnd = $iCtrlID If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($iCtrlID) Return _WinAPI_SetWindowPos($hWnd, $HWND_BOTTOM, 0, 0, 0, 0, $SWP_NOMOVE + $SWP_NOSIZE + $SWP_NOCOPYBITS) EndFunc This method doesn't require to tell the position or the control to be drawn ontop. I made a quick snippet that you can include in your scripts.1 point