Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 08/30/2020 in all areas

  1. HankHell

    Simple RGB Game

    made this quite a while back and never bothered to post it... was having a discussion with a friend I was talking to about code and figured I might as well post it.... to win: click on the squares in the order of R, G, B. Game lasts 100 seconds. Score is deducted for pressing the wrong color #include <GUIConstants.au3> Global $button1 Global $button2 Global $time Global $counter = 1 Global $colorstate1 = 1 Global $colorstate2 = 1 Global $colorstate3 = 1 HotKeySet("{ESC}", "Close") Global $score = 0 $randomness1 = Random(1, 450) $randomnumber1 = Round($randomness1) $randomness2 = Random(1, 350) $randomnumber2 = Round($randomness2) $randomness3 = Random(1, 450) $randomnumber3 = Round($randomness3) $randomness4 = Random(1, 350) $randomnumber4 = Round($randomness4) $randomness5 = Random(1, 450) $randomnumber5 = Round($randomness5) $randomness6 = Random(1, 350) $randomnumber6 = Round($randomness6) Global $posx1 = $randomnumber1 Global $posy1 = $randomnumber2 Global $posx2 = $randomnumber3 Global $posy2 = $randomnumber4 Global $posx3 = $randomnumber5 Global $posy3 = $randomnumber6 GUICreate("random", 600, 500, @DesktopWidth / 4, @DesktopHeight / 4) $scorelabel = GUICtrlCreateLabel("Score: ", 150, 10) $scoregui = GUICtrlCreateLabel("", 200, 10, 100, 18) $timegui = GUICtrlCreateLabel("", 100, 450, 100, 18) GUICtrlSetColor($timegui, 0x085785) GUISetState(@SW_SHOW) $button1 = GUICtrlCreateButton("", $posx1, $posy1, 50, 50) $button2 = GUICtrlCreateButton("", $posx2, $posy2, 50, 50) $button3 = GUICtrlCreateButton("", $posx3, $posy3, 50, 50) GUICtrlSetBkColor($button1, 0x0000FF) GUICtrlSetBkColor($button2, 0x00FF00) GUICtrlSetBkColor($button3, 0xFF0000) While 1 If $counter = 1 Then Timer() EndIf SwitchCheck() WEnd Func Timer() $time += 1 GUICtrlSetData($timegui, $time) If $time = 10000 Then $counter = 0 GUICtrlSetState($button1, $GUI_DISABLE) GUICtrlSetState($button2, $GUI_DISABLE) GUICtrlSetState($button3, $GUI_DISABLE) GUICtrlCreateLabel("GAME OVER", 100, 435, 100, 15) EndIf EndFunc Func SwitchCheck() $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $button1 RandomFunc() $score -= 10 GUICtrlSetData($scoregui, $score) $colorstate1 += 1 If $colorstate1 = 1 Then GUICtrlSetBkColor($button1, 0x0000FF) EndIf If $colorstate1 = 2 Then GUICtrlSetBkColor($button1, 0xFF0000) EndIf If $colorstate1= 3 Then GUICtrlSetBkColor($button1, 0x00FF00) $colorstate1 = 0 EndIf $colorstate2 += 1 If $colorstate2 = 1 Then GUICtrlSetBkColor($button2, 0x00FF00) EndIf If $colorstate2 = 2 Then GUICtrlSetBkColor($button2, 0x0000FF) EndIf If $colorstate2 = 3 Then GUICtrlSetBkColor($button2, 0xFF0000) $colorstate2 = 0 EndIf $score += 3 GUICtrlSetData($scoregui, $score) $colorstate3 += 1 If $colorstate3 = 1 Then GUICtrlSetBkColor($button3, 0xFF0000) EndIf If $colorstate3 = 2 Then GUICtrlSetBkColor($button3, 0x00FF00) EndIf If $colorstate3 = 3 Then GUICtrlSetBkColor($button3, 0x0000FF) $colorstate3 = 0 EndIf Case $button2 RandomFunc() $score -= 20 GUICtrlSetData($scoregui, $score) $colorstate2 += 1 If $colorstate2 = 1 Then GUICtrlSetBkColor($button2, 0x00FF00) EndIf If $colorstate2 = 2 Then GUICtrlSetBkColor($button2, 0x0000FF) EndIf If $colorstate2 = 3 Then GUICtrlSetBkColor($button2, 0xFF0000) $colorstate2 = 0 EndIf $colorstate1 += 1 If $colorstate1 = 1 Then GUICtrlSetBkColor($button1, 0x0000FF) EndIf If $colorstate1 = 2 Then GUICtrlSetBkColor($button1, 0xFF0000) EndIf If $colorstate1= 3 Then GUICtrlSetBkColor($button1, 0x00FF00) $colorstate1 = 0 EndIf $score += 3 GUICtrlSetData($scoregui, $score) $colorstate3 += 1 If $colorstate3 = 1 Then GUICtrlSetBkColor($button3, 0xFF0000) EndIf If $colorstate3 = 2 Then GUICtrlSetBkColor($button3, 0x00FF00) EndIf If $colorstate3 = 3 Then GUICtrlSetBkColor($button3, 0x0000FF) $colorstate3 = 0 EndIf Case $button3 RandomFunc() $score += 3 GUICtrlSetData($scoregui, $score) $colorstate3 += 1 If $colorstate3 = 1 Then GUICtrlSetBkColor($button3, 0xFF0000) EndIf If $colorstate3 = 2 Then GUICtrlSetBkColor($button3, 0x00FF00) EndIf If $colorstate3 = 3 Then GUICtrlSetBkColor($button3, 0x0000FF) $colorstate3 = 0 EndIf $colorstate2 += 1 If $colorstate2 = 1 Then GUICtrlSetBkColor($button2, 0x00FF00) EndIf If $colorstate2 = 2 Then GUICtrlSetBkColor($button2, 0x0000FF) EndIf If $colorstate2 = 3 Then GUICtrlSetBkColor($button2, 0xFF0000) $colorstate2 = 0 EndIf $colorstate1 += 1 If $colorstate1 = 1 Then GUICtrlSetBkColor($button1, 0x0000FF) EndIf If $colorstate1 = 2 Then GUICtrlSetBkColor($button1, 0xFF0000) EndIf If $colorstate1= 3 Then GUICtrlSetBkColor($button1, 0x00FF00) $colorstate1 = 0 EndIf EndSwitch EndFunc Func RandomFunc() $RandomNumber = Random(1, 3) $RandomNumber = Round($RandomNumber) If $RandomNumber = 1 Then $randomness1 = Random(1, 450) $randomnumber1 = Round($randomness1) $randomness2 = Random(1, 350) $randomnumber2 = Round($randomness2) GUICtrlSetPos($button1, $randomnumber1, $randomnumber2) $Randomnumber = 2 EndIf If $RandomNumber = 2 Then $randomness1 = Random(1, 450) $randomnumber1 = Round($randomness1) $randomness2 = Random(1, 350) $randomnumber2 = Round($randomness2) GUICtrlSetPos($button2, $randomnumber1, $randomnumber2) $Randomnumber = 3 EndIf If $RandomNumber = 3 Then $randomness1 = Random(1, 450) $randomnumber1 = Round($randomness1) $randomness2 = Random(1, 350) $randomnumber2 = Round($randomness2) GUICtrlSetPos($button3, $randomnumber1, $randomnumber2) $Randomnumber = 1 EndIf ;--------------- If $RandomNumber = 1 Then $randomness1 = Random(1, 450) $randomnumber1 = Round($randomness1) $randomness2 = Random(1, 350) $randomnumber2 = Round($randomness2) GUICtrlSetPos($button1, $randomnumber1, $randomnumber2) $Randomnumber = 2 EndIf If $RandomNumber = 2 Then $randomness1 = Random(1, 450) $randomnumber1 = Round($randomness1) $randomness2 = Random(1, 350) $randomnumber2 = Round($randomness2) GUICtrlSetPos($button2, $randomnumber1, $randomnumber2) $Randomnumber = 3 EndIf EndFunc Func Close() Exit EndFunc
    2 points
  2. Gianni

    Simple RGB Game

    A nice fun toy thanks for sharing vaguely reminds me of this documentary: (https://www.autoitscript.com/forum/topic/189136-cool-stuff-on-youtube/?do=findComment&comment=1374877) ... if you allow, speaking of the code, with a little revision it could be tweaked a bit ... #include <GUIConstants.au3> #include <Array.au3> HotKeySet("{ESC}", "Close") Global $iWinWidth = 600, $iWinHeight = 400, $iButtonXSide = 100, $iButtonYSide = Int(($iButtonXSide / 16) * 9), $sWinTitle = "RGB Game", $iTimeout = 10000 ; 10 seconds Global $aX[Int($iWinWidth / $iButtonXSide)], $aY[Int($iWinHeight / $iButtonYSide)], $iNdx = 0, $aPoints[3], $score, $iTimer, $iProgressHeight = 15 For $i = 0 To (Int($iWinWidth / $iButtonXSide) - 1) * $iButtonXSide Step $iButtonXSide $aX[$iNdx] = $i $iNdx += 1 Next $iNdx = 0 For $i = 0 To (Int($iWinHeight / $iButtonYSide) - 1) * $iButtonYSide Step $iButtonYSide $aY[$iNdx] = $i $iNdx += 1 Next Global $hGUI = GUICreate($sWinTitle, $iWinWidth, $iWinHeight + $iProgressHeight, @DesktopWidth / 4, @DesktopHeight / 5) Global $idProgressbar = GUICtrlCreateProgress(0, $iWinHeight + 1, $iWinWidth, $iProgressHeight) Global $button1 = GUICtrlCreateButton("R", 0, 0, $iButtonXSide, $iButtonYSide) Global $button2 = GUICtrlCreateButton("G", 0, 0, $iButtonXSide, $iButtonYSide) Global $button3 = GUICtrlCreateButton("B", 0, 0, $iButtonXSide, $iButtonYSide) GUICtrlSetBkColor($button1, 0xFF0000) GUICtrlSetBkColor($button2, 0x00FF00) GUICtrlSetBkColor($button3, 0x0000FF) GUISetState(@SW_SHOW) ; --- Main loop --- Do ; New match _RandomizeButtons() $aPoints[0] = 1 $aPoints[1] = -1 $aPoints[2] = -1 $score = 0 $iTimer = TimerInit() GUICtrlSetData($idProgressbar, 100) While TimerDiff($iTimer) < $iTimeout ; play until timeout Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Close() Case $button1 _SetNext(0) Case $button2 _SetNext(1) Case $button3 _SetNext(2) EndSwitch GUICtrlSetData($idProgressbar, 100 - (100 / $iTimeout * TimerDiff($iTimer))) WinSetTitle($hGUI, '', $sWinTitle & ' (Score: ' & StringFormat("%02d", $score) & ' points)') WEnd Until MsgBox(36 + 8192 + 65536, "Game over", "you have scored " & $score & " points" & @CRLF & @CRLF & "do you want to try again?") <> 6 Func _SetNext($ChosenColor) $score += $aPoints[$ChosenColor] ConsoleWrite($score & @CRLF) _ArrayPush($aPoints, $aPoints[UBound($aPoints) - 1], 1) ; rotate scores by 1 _RandomizeButtons() EndFunc ;==>_SetNext Func _RandomizeButtons() _ArrayShuffle($aX) _ArrayShuffle($aY) GUICtrlSetPos($button1, $aX[0], $aY[0]) GUICtrlSetPos($button2, $aX[1], $aY[1]) GUICtrlSetPos($button3, $aX[2], $aY[2]) EndFunc ;==>_RandomizeButtons Func Close() Exit EndFunc ;==>Close
    2 points
  3. Here is a bit faster/cleaner version It should be a bit easier to understand too #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_UseX64=y #AutoIt3Wrapper_AU3Check_Parameters=-d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** ;Au3CallByName, Bilgus Global $Au3_CallByName = 0 Global $hKernel32 = DllOpen("Kernel32.dll") OnAutoItExitRegister(__CallByNameCleanup) Func __CallByNameCleanup() Au3_CallByName_Init(False) ;Unload DllClose($hKernel32) EndFunc ;==>__CallByNameCleanup ; Takes a pointer to the v-table in a class and replaces specified member Id in it to a new one. Func __HookVTableEntry($pVtable, $iVtableOffset, $pHook, ByRef $pOldRet) ;;https://www.autoitscript.com/forum/topic/107678-hooking-into-the-idispatch-interface/ Local Const $PAGE_READWRITE = 0x04 Local $tpVtable = DllStructCreate("ptr", $pVtable) Local $szPtr = DllStructGetSize($tpVtable) Local $pFirstEntry, $pEntry, $tEntry, $aCall, $flOldProtect, $bStatus ; Dereference the vtable pointer $pFirstEntry = DllStructGetData($tpVtable, 1) $pEntry = $pFirstEntry + ($iVtableOffset * $szPtr) ;vtable is a big array of pointers ; Make the memory free for all. Yay! $aCall = DllCall($hKernel32, "int", "VirtualProtect", "ptr", $pEntry, "long", $szPtr, "dword", $PAGE_READWRITE, "dword*", 0) If @error Or Not $aCall[0] Then ConsoleWriteError("Error: Failed To hook vTable" & @CRLF) Return False EndIf $flOldProtect = $aCall[4] $tEntry = DllStructCreate("ptr", $pEntry) $pOldRet = DllStructGetData($tEntry, 1) If $pOldRet <> $pHook Then DllStructSetData($tEntry, 1, $pHook) $bStatus = True Else ;Already Hooked ConsoleWriteError("Error: vTable is already hooked" & @CRLF) $bStatus = False EndIf ;put the memory protect back how we found it DllCall($hKernel32, "int", "VirtualProtect", "ptr", $pEntry, "long", $szPtr, "dword", $flOldProtect, "dword*", 0) Return $bStatus EndFunc ;==>__HookVTableEntry ; Everytime autoit wants to call a method, get or set a property in a object it needs to go to ; IDispatch::GetIDsFromNames. This is our version of that function, note that by defining this ourselves ; we can fool autoit to believe that the object supports a lot of different properties/methods. Func __IDispatch_GetIDsFromNames($pSelf, $riid, $rgszNames, $cNames, $lcid, $rgDispId) Local Const $DISP_E_UNKNOWNNAME = 0x80020006, $DISPID_UNKNOWN = -1 Local Static $pGIFN = __Pointer_GetIDsFromNames() Local $hRes ;Call the original GetIDsFromNames $hRes = DllCallAddress("LRESULT", $pGIFN, "ptr", $pSelf, "ptr", $riid, _ "struct*", $rgszNames, "dword", $cNames, "dword", $lcid, "ptr", $rgDispId) If @error Then ConsoleWriteError("Error: GetIDsFromNames: " & @error & @CRLF) Return $DISP_E_UNKNOWNNAME EndIf ; Autoit didnt find the name now its our turn If $DISPID_UNKNOWN = DllStructGetData(DllStructCreate("long[" & $cNames & "]", $rgDispId), 1, 1) Then ;$rgszNames is a pointer to an array[$cNames] of names -- Autoit only asks for one member $cNames = 1 Local $tName = DllStructCreate("wchar[64]", DllStructGetData(DllStructCreate("ptr[" & $cNames & "]", $rgszNames), 1, 1)) Local $sName = DllStructGetData($tName, 1) ;We just prepend CBN_CB_ to the function name and try to call it $hRes = Call("CBN_CB_" & $sName, $sName, $pGIFN, $pSelf, $riid, $rgszNames, $cNames, $lcid, $rgDispId) If Not @error And $hRes <> Default Then Return $hRes ; User handled the function ;Call the original GetIDsFromNames $hRes = DllCallAddress("LRESULT", $pGIFN, "ptr", $pSelf, "ptr", $riid, _ "struct*", $rgszNames, "dword", $cNames, "dword", $lcid, "ptr", $rgDispId) If @error Then ConsoleWrite("Error: GetIDsFromNames: " & @error & @CRLF) Return $DISP_E_UNKNOWNNAME EndIf EndIf Return $hRes[0] EndFunc ;==>__IDispatch_GetIDsFromNames Func __Pointer_GetIDsFromNames($ptr = 0) ;Stores pointer to the original 'GetIDsFromNames' Local Static $pOldGIFN = $ptr If $ptr <> 0 Then $pOldGIFN = $ptr Return $pOldGIFN EndFunc ;==>__Pointer_GetIDsFromNames Func Au3_CallByName_Init($bHook = True, $classname = "shell.application") Local Const $iOffset_GetIDsFromNames = 5 ;vtable index Local Static $IDispatch_GetIDsFromNames_Callback = 0 Local $oObject, $pObject, $pHook, $pOldGIFN If $bHook Then If $IDispatch_GetIDsFromNames_Callback = 0 Then $IDispatch_GetIDsFromNames_Callback = DllCallbackRegister("__IDispatch_GetIDsFromNames", _ "LRESULT", "ptr;ptr;ptr;dword;dword;ptr") EndIf $pHook = DllCallbackGetPtr($IDispatch_GetIDsFromNames_Callback) Else $pHook = __Pointer_GetIDsFromNames() If $pHook <= 0 Then Return ;Already Unloaded EndIf $oObject = ObjCreate($classname) $pObject = DllStructSetData(DllStructCreate("ptr"), 1, $oObject) If __HookVTableEntry($pObject, $iOffset_GetIDsFromNames, $pHook, $pOldGIFN) Then __Pointer_GetIDsFromNames($pOldGIFN) ;Save the original pointer to GetIDsFromNames If Not $bHook Then DllCallbackFree($IDispatch_GetIDsFromNames_Callback) $IDispatch_GetIDsFromNames_Callback = 0 EndIf Else ;Error EndIf $oObject = 0 EndFunc ;==>Au3_CallByName_Init ;|||||||||===========||||||||| ;||||||||| CallBacks ||||||||| Func CBN_CB_Au3_CallByName($sName, $pGIFN, $pSelf, $riid, $rgszNames, $cNames, $lcid, $rgDispId) Local Const $DISP_E_UNKNOWNNAME = 0x80020006 ConsoleWrite(">Call By Name: " & $sName & " -> " & $Au3_CallByName & @crlf) Local Static $tpMember = DllStructCreate("ptr") If $Au3_CallByName Then Local $hRes, $tMember ;ConsoleWrite("CallByName: " & $Au3_CallByName & @CRLF) $tMember = DllStructCreate("wchar[" & StringLen($Au3_CallByName) + 1 & "]") DllStructSetData($tMember, 1, $Au3_CallByName) DllStructSetData($tpMember, 1, DllStructGetPtr($tMember)) $rgszNames = $tpMember $Au3_CallByName = 0 ;Call the original GetIDsFromNames $hRes = DllCallAddress("LRESULT", $pGIFN, "ptr", $pSelf, "ptr", $riid, _ "struct*", $rgszNames, "dword", $cNames, "dword", $lcid, "ptr", $rgDispId) If @error Then ConsoleWrite("Error: Call By Name: " & @error & @CRLF) Return $DISP_E_UNKNOWNNAME EndIf Return $hRes[0] EndIf Return Default ;Default handler EndFunc ;||||||||| CallBacks ||||||||| ;|||||||||===========||||||||| ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;TESTS; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Global $oDictionary = ObjCreate("Scripting.Dictionary") Au3_CallByName_Init() Sleep(1000) For $i = 1 To 3 $Au3_CallByName = "Add" $oDictionary.Au3_CallByName("test1:" & $i, "Dictionary Item: " & $i) Next $Au3_CallByName = "keys" For $sKey In $oDictionary.Au3_CallByName() For $j = 0 To 1 $Au3_CallByName = ($j = 0) ? "Item" : "Exists" ConsoleWrite($sKey & "[" & $Au3_CallByName & "] -> " & $oDictionary.Au3_CallByName($sKey) & @CRLF) Next Next Au3_CallByName_Init(False) ;Unload (Not Strictly Needed, Done on Script Close) Same Idea but now we only go looking for our function if Autoit indicates that it doesn't exist
    2 points
  4. Trying to figure out how to do CallByName on AutoIt COM objects due to the lack of being able to set properties within an Execute() statement Several Ideas were Tried https://www.autoitscript.com/forum/topic/200129-set-object-properties-with-propertyname-and-value-taken-from-an-array/ I think this is the best; Patching the vtable of IDispatch so we can intercept a Fake function call ($obj.Au3_CallByName) use it like this Local $oDictionary = ObjCreate("Scripting.Dictionary") ; EXAMPLE Au3_CallByname_Init() ; (you can optionally provide a classname here but we patch the main Idispatch interface so really no need) $Au3_CallByName = "Add" ; Method we want to call $oDictionary.Au3_CallByName("Test", "Value") Au3_CallByname_Init(False) ; (Not Strictly Needed unhooked on exit) NOTE: Au3_CallByname_Init() doesn't have to be called at the top of the script, just call it before you need to call by name... Code + Example #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_UseX64=y #AutoIt3Wrapper_AU3Check_Parameters=-d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** ;Au3CallByName, Bilgus Global $Au3_CallByName = 0 Local $hKernel32 = DllOpen("Kernel32.dll") OnAutoItExitRegister(__CallByNameCleanup) Func __CallByNameCleanup() Au3_CallByName_Init(False) ;Unload DllClose($hKernel32) EndFunc ;==>__CallByNameCleanup ; Takes a pointer to the v-table in a class and replaces specified member Id in it to a new one. Func __HookVTableEntry($pVtable, $iVtableOffset, $pHook, ByRef $pOldRet) ;;https://www.autoitscript.com/forum/topic/107678-hooking-into-the-idispatch-interface/ Local Const $PAGE_READWRITE = 0x04 Local $tpVtable = DllStructCreate("ptr", $pVtable) Local $szPtr = DllStructGetSize($tpVtable) Local $pFirstEntry, $pEntry, $tEntry, $aCall, $flOldProtect, $bStatus ; Dereference the vtable pointer $pFirstEntry = DllStructGetData($tpVtable, 1) $pEntry = $pFirstEntry + ($iVtableOffset * $szPtr) ; Make the memory free for all. Yay! $aCall = DllCall($hKernel32, "int", "VirtualProtect", "ptr", $pEntry, "long", $szPtr, "dword", $PAGE_READWRITE, "dword*", 0) If @error Or Not $aCall[0] Then ConsoleWriteError("Error: Failed To hook vTable" & @CRLF) Return False EndIf $flOldProtect = $aCall[4] $tEntry = DllStructCreate("ptr", $pEntry) $pOldRet = DllStructGetData($tEntry, 1) If $pOldRet <> $pHook Then DllStructSetData($tEntry, 1, $pHook) $bStatus = True Else ;Already Hooked ConsoleWriteError("Error: vTable is already hooked" & @CRLF) $bStatus = False EndIf ;put the memory protect back how we found it DllCall($hKernel32, "int", "VirtualProtect", "ptr", $pEntry, "long", $szPtr, "dword", $flOldProtect, "dword*", 0) Return $bStatus EndFunc ;==>__HookVTableEntry ; Everytime autoit wants to call a method, get or set a property in a object it needs to go to ; IDispatch::GetIDsFromNames. This is our version of that function, note that by defining this ourselves ; we can fool autoit to believe that the object supports a lot of different properties/methods. Func __IDispatch_GetIDsFromNames($pSelf, $riid, $rgszNames, $cNames, $lcid, $rgDispId) Local Const $CSTR_EQUAL = 0x02 Local Const $LOCALE_SYSTEM_DEFAULT = 0x800 Local Const $DISP_E_UNKNOWNNAME = 0x80020006 Local Static $pGIFN = __Pointer_GetIDsFromNames() Local Static $tpMember = DllStructCreate("ptr") If $Au3_CallByName Then Local $hRes, $aCall, $tMember ;autoit only asks for one member $aCall = DllCall($hKernel32, 'int', 'CompareStringW', 'dword', $LOCALE_SYSTEM_DEFAULT, 'dword', 0, 'wstr', "Au3_CallByName", 'int', -1, _ 'struct*', DllStructGetData(DllStructCreate("ptr[" & $cNames & "]", $rgszNames), 1, 1), 'int', -1) If Not @error And $aCall[0] = $CSTR_EQUAL Then ;ConsoleWrite("CallByName: " & $Au3_CallByName & @CRLF) $tMember = DllStructCreate("wchar[" & StringLen($Au3_CallByName) + 1 & "]") DllStructSetData($tMember, 1, $Au3_CallByName) DllStructSetData($tpMember, 1, DllStructGetPtr($tMember)) $rgszNames = $tpMember $Au3_CallByName = 0 EndIf EndIf ;Call the original GetIDsFromNames $hRes = DllCallAddress("LRESULT", $pGIFN, "ptr", $pSelf, "ptr", $riid, _ "struct*", $rgszNames, "dword", $cNames, "dword", $lcid, "ptr", $rgDispId) If @error Then ConsoleWrite("Error: GetIDsFromNames: " & @error & @CRLF) Return $DISP_E_UNKNOWNNAME EndIf Return $hRes[0] EndFunc ;==>__IDispatch_GetIDsFromNames Func __Pointer_GetIDsFromNames($ptr = 0) Local Static $pOldGIFN = $ptr If $ptr <> 0 Then $pOldGIFN = $ptr Return $pOldGIFN EndFunc ;==>__Pointer_GetIDsFromNames Func Au3_CallByName_Init($bHook = True, $classname = "shell.application") Local Const $iOffset_GetIDsFromNames = 5 Local Static $IDispatch_GetIDsFromNames_Callback = 0 Local $oObject, $pObject, $pHook, $pOldGIFN If $bHook Then If $IDispatch_GetIDsFromNames_Callback = 0 Then $IDispatch_GetIDsFromNames_Callback = DllCallbackRegister("__IDispatch_GetIDsFromNames", "LRESULT", "ptr;ptr;ptr;dword;dword;ptr") EndIf $pHook = DllCallbackGetPtr($IDispatch_GetIDsFromNames_Callback) Else $pHook = __Pointer_GetIDsFromNames() If $pHook <= 0 Then Return ;Already Unloaded EndIf $oObject = ObjCreate($classname) $pObject = DllStructSetData(DllStructCreate("ptr"), 1, $oObject) If __HookVTableEntry($pObject, $iOffset_GetIDsFromNames, $pHook, $pOldGIFN) Then __Pointer_GetIDsFromNames($pOldGIFN) ;Save the original pointer to GetIDsFromNames If Not $bHook Then DllCallbackFree($IDispatch_GetIDsFromNames_Callback) $IDispatch_GetIDsFromNames_Callback = 0 EndIf Else ;Error EndIf $oObject = 0 EndFunc ;==>Au3_CallByName_Init ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;TESTS; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Au3_CallByName_Init() #include <ie.au3> Global $oRegistrationInfo = _IECreate() Global $aRegistrationInfo[] = ['Left=10', 'Top= 10', 'Width=450', 'Height=600'] Global $oObject = $oRegistrationInfo Local $oDictionary = ObjCreate("Scripting.Dictionary") Local $oDictionary2 = ObjCreate("Scripting.Dictionary") ;Au3_CallByName_Init($oObject) __TS_TaskPropertiesSet($oObject, $aRegistrationInfo) MsgBox(0, "Info", "Press OK to exit") $oRegistrationInfo.quit $oRegistrationInfo = 0 $oObject = 0 Sleep(1000) For $i = 1 To 10 $Au3_CallByName = "Add" $oDictionary.Au3_CallByName("test1:" & $i, "Dictionary Item: " & $i) Next $Au3_CallByName = "keys" For $sKey In $oDictionary.Au3_CallByName() For $j = 0 To 1 $Au3_CallByName = ($j = 0) ? "Item" : "Exists" ConsoleWrite($sKey & " -> " & $oDictionary.Au3_CallByName($sKey) & @CRLF) Next Next Au3_CallByName_Init(False) ;Unload Au3_CallByName_Init() Local $aRegistrationInfo[] = ['Left=1000', 'Width=450'] ConsoleWrite(@CRLF & "NEW IE" & @CRLF & @CRLF) $oRegistrationInfo = _IECreate() __TS_TaskPropertiesSet($oRegistrationInfo, $aRegistrationInfo) MsgBox(0, "Info", "Press OK to exit") $oRegistrationInfo.quit For $i = 1 To 10 $Au3_CallByName = "Add" $oDictionary2.Au3_CallByName("test2:" & $i, "Dictionary Item: " & $i) Next $Au3_CallByName = "keys" For $sKey In $oDictionary2.Au3_CallByName() For $j = 0 To 1 $Au3_CallByName = ($j = 0) ? "Item" : "Exists" ConsoleWrite($sKey & " -> " & $oDictionary2.Au3_CallByName($sKey) & @CRLF) Next Next Au3_CallByName_Init(False) ;Unload (Not Strictly Needed, Done on Script Close) Func __TS_TaskPropertiesSet(ByRef $oObject, $aProperties) Local $aTemp If IsArray($aProperties) Then For $i = 0 To UBound($aProperties) - 1 $aTemp = StringSplit($aProperties[$i], "=", 2) ; 2 -> $STR_NOCOUNT) If @error Then ContinueLoop ConsoleWrite("Command: $oObject." & $aTemp[0] & " = " & $aTemp[1] & @CRLF) $Au3_CallByName = $aTemp[0] $oObject.Au3_CallByName = $aTemp[1] ConsoleWrite("Result : " & Hex(@error) & @CRLF) ; If @error Then Return SetError(1, @error, 0) Next EndIf EndFunc ;==>__TS_TaskPropertiesSet
    1 point
  5. tarretarretarre

    Autoit Serialize

    About Serialize Serialize a given value to get it's string representation, that you can later unSerialize back to its original value. Including nested arrays and objects. This is useful for storing and transferring data between applications. 2021-02-14 update: you can now serialize and unSerialize data in JavaScript as well. Checkout the official npm package or the github repo. This makes it possible to pass data between AutoIt and JavaScript applications. Eventually I will make an package for PHP aswell. Limitations Mutli dim arrays are not supported Examples Basic example #include "Serialize.au3" #include <Array.au3> ; Define some data Global $array = [1,2,3] ; Serialize Global $serialized = _Serialize($array) MsgBox(64, "Serialized data", $serialized) ; Unserialize Global $unSerialized = _UnSerialize($serialized) _ArrayDisplay($unSerialized) Objects and nesting #include "Serialize.au3" #include <Array.au3> ; Define some data Global $preArray = [1, 2, 3] Global $array = [5, 6, $preArray] Global $obj = ObjCreate("Scripting.Dictionary") $obj.add("firstName", "Tarre") $obj.add("age", 29) $obj.add("array", $array) $obj.add("active", True) ; Serialize Global $serialized = _Serialize($obj) MsgBox(64, "Serialized data", $serialized) ; Unserialize Global $unSerialized = _UnSerialize($serialized) MsgBox(64, "Unserialized data", "firstName = " & $unSerialized.item("firstName") & @LF & "age = " & $unSerialized.item("age") & @LF & "active = " & $unSerialized.item("active")) Global $array = $unSerialized.item("array") Global $preArray = $array[2] _ArrayDisplay($array, "$array") _ArrayDisplay($preArray, "$preArray") The code is also available on Github Autoit-Serialize-1.0.0.zip
    1 point
  6. I made an initial update to the script in my previous post. Although it now pulls all of the "irregular" table data without throwing any errors, the exact placement of the spanned rows and columns are not maintained as they are when using the _HtmlTableGetWriteToArray() function. I doubt I will continue to work on it since it really serves no purpose for me until I come across such a table in the course of my scripting. And if I need a quick fix, _HtmlTableGetWriteToArray() is always there to save the day.
    1 point
  7. CarlD

    Simple RGB Game

    Nice. A good mind-clearing exercise. (Playing the game, I mean.)
    1 point
  8. Beege

    Tiny CPU Bar

    Here is a small and simple little script for creating a tiny cpu indicator bar that sits right above the taskbar like in the pic below. I got the idea from an android phone app called micro cpu and liked the concept. _TinyCPU.au3
    1 point
  9. I jumped from AutoIT into PHP. They're extremely similar. For me all I had to really do most of the time was lookup what function in autoit was similar to what in PHP. AutoIt / PHP StringLen / Strlen FileWrite / FilePutContents FileRead / FileGetContents DirCreate / MkDir FileDelete / Unlink StringLower / StrToLower and all of those functions have the SAME arguments as AutoIt. I had a working registration script in probably an hour first time with PHP. ; \/ AutoIt \/ $name = "Eude" $loves = "Cake" If ($name == "Eude") Then If ($loves == "not Cake") Then Else ConsoleWrite($name & " loves " & $loves) EndIf EndIf ; \/ PHP \/ $name = 'Eude'; $loves = 'Cake'; If ($name == 'Eude') { If ($loves == 'not cake') { } else { echo $name . ' loves ' . $loves; } }
    1 point
  10. price98, Welcome to the AutoIt forums. However, we do not just produce code for you - we help you get your code working properly. Think of the old saying: "Give a man a fish, you feed him for a day; give a man a net and you feed him forever". We try to be net makers and repairers, not fishmongers. So I suggest you look at the examples in the Help file for GUICreate, GUICtrlCreateButton, GUICtrlCreateInput & GUICtrlCreateList to get your GUI started - and _FileListToArray to get the files on your desktop. Have a go at producing something yourself and then post it (see here how to do it) - even if it does not do what you require. We can then start helping you to get it working as you wish. M23
    1 point
  11. I used Electron (I'm a 99% fish in this matter) and it's realy simple to use. The most interesting for me has always been the game code I found in Path of Exile. Particularly interesting is the random ratio (RNG) in PoE when using currency. I recommend looking at this. Path of Exile By far the most groundbreaking discovery in the world of MMOs was the Path of Exile and a breath of freshness experienced by the gaming scene. Millions of people played simultaneously, all trying to beat Shaper and the Elder. What is the common denominator for all these players is love for Exalted orbs and the rest of the orbs. Exalted orb (the most popular orb in the game) consists of three or four faces, and has a golden color. I like to buy Exalted orbs buy exalted orbs
    0 points
×
×
  • Create New...