Leaderboard
Popular Content
Showing content with the highest reputation on 07/23/2021 in all areas
-
Object method with structure array as parameter
DonChunior and one other reacted to Nine for a topic
TheXman code did not work for me. Although this one is working perfectly fine : ... Local $oBackgroundCopyJob = ObjCreateInterface($pJob, $sIID_IBackgroundCopyJob, $tagIBackgroundCopyJob) ConsoleWrite(VarGetType($oBackgroundCopyJob) & @CRLF) ;$oBackgroundCopyJob.AddFile("http://www.autoitscript.com/autoit3/files/beta/update.dat", @ScriptDir & "\Test.tmp") Local $aFile = [["http://ipv4.download.thinkbroadband.com/5MB.zip", @ScriptDir & "\Test1.zip"], _ ["http://www.autoitscript.com/autoit3/files/beta/update.dat", @ScriptDir & "\Test2.txt"]] AddFileSet($oBackgroundCopyJob, $aFile) $oBackgroundCopyJob.Resume() ... Func AddFileSet(ByRef $obj, ByRef $aFileSet) Local $sStructDef = _StringRepeat("ptr;", UBound($aFileSet) * 2) Local $tStruct = DllStructCreate($sStructDef) Local $tFileInfo1[UBound($aFileSet)], $tFileInfo2[UBound($aFileSet)] For $i = 0 to UBound($aFileSet) - 1 $tFileInfo1[$i] = DllStructCreate("wchar[" & StringLen($aFileSet[$i][0]) + 1 & "];") $tFileInfo2[$i] = DllStructCreate("wchar[" & StringLen($aFileSet[$i][1]) + 1 & "];") DllStructSetData($tFileInfo1[$i], 1, $aFileSet[$i][0]) DllStructSetData($tFileInfo2[$i], 1, $aFileSet[$i][1]) DllStructSetData($tStruct, $i*2+1, DllStructGetPtr($tFileInfo1[$i])) DllStructSetData($tStruct, $i*2+2, DllStructGetPtr($tFileInfo2[$i])) Next _WinAPI_DisplayStruct($tStruct, $sStructDef) $obj.AddFileSet(UBound($aFileSet), $tStruct) EndFunc2 points -
During code troubleshooting, the data display functions _ArrayDisplay(), _DebugArrayDisplay() and _WinAPI_DisplayStruct() can be useful to provide a quick visual overview of the contents of arrays and DllStructs. However, these functions each have their own built-in message loop, which will block the code in the main script. In many cases the code in the main script cannot stand to be blocked in this way and will therefore fail. That is, the troubleshooting functions themselves cause an error. And that, of course, isn't an appropriate situation. This example shows how to execute the data display functions in their own processes, to avoid blocking the code in the main script. Other Examples Unblocking a Blocked Message Handler Unblocking a Blocked Message Handler is about several data display functions that mutually block each other, and how to get around this problem. But the example is not about how to avoid the main script from being blocked. In this new example, data display functions will not block each other nor will they block the main script. The IdeaThe main issue in running a data display function in its own process is passing data to the function. The idea is to use a system global ROT object to pass data from the main script to the data display function. The two major advantages of using a ROT object are that it's a very fast data passing method and that the method preserves data types. However, a ROT object can only be used to pass COM compatible data types. An array is such a COM compatible data type (an AutoIt array is not directly COM compatible, but internally it is stored as a safearray of variants that is COM compatible). A DllStruct isn't COM compatible (nor is it processed by internal COM conversions). To pass a DllStruct, we must first convert data to binary data, which is COM compatible. Once the binary data has been passed, it must again be converted back to a DllStruct. The technique is discussed in the DllStruct section of IPC Techniques through ROT Objects. The CodeThe code is implemented as a complete UDF, NonBlockingDataDisplay.au3. The essential code for creating ROT objects is contained in IRunningObjectTable.au3. AccVars.au3 as well as Variant.au3 and SafeArray.au3 contains code to convert a DllStruct to binary data. Two functions at bottom of the new UDF handles the details of DllStruct to binary conversion. RunArrayDisplay() is the UDF function to execute _ArrayDisplay() in a standalone process: Func RunArrayDisplay( _ $sPath, _ ; Path to Includes ended with "\" $aArray, _ $iFlags = 0, _ ; 0 -> 32 bit code, 1 -> 64 bit code $sTitle = "ArrayDisplay", _ $sHeader = Default ) ; Create data transfer object (ROT-object) Local $sDataTransferObject = "DataTransferObject" & ROT_CreateGUID() ROT_RegisterObject( Default, $sDataTransferObject ) ; Default => Object = Dictionary object Local $oDataTransferObject = ObjGet( $sDataTransferObject ) ; Dictionary object ; Add data to transfer object $oDataTransferObject.Add( "$aArray", $aArray ) $oDataTransferObject.Add( "$sTitle", $sTitle ) $oDataTransferObject.Add( "$sHeader", $sHeader ) ; Run _ArrayDisplay() in another process $g_aDataDisplayProgPids[$g_iDataDisplayProgPids] = BitAND( $iFlags, 1 ) _ ? Run( @AutoItExe & " /AutoIt3ExecuteScript " & $sPath & '"RunArrayDisplay64.au3" ' & $sDataTransferObject ) _ ; 64 bit code : Run( @AutoItExe & " /AutoIt3ExecuteScript " & $sPath & '"RunArrayDisplay32.au3" ' & $sDataTransferObject ) ; 32 bit code $g_iDataDisplayProgPids += 1 EndFunc The function executes Includes\RunArrayDisplay64.au3: #AutoIt3Wrapper_UseX64=Y #include <Array.au3> RunDataDisplay() Func RunDataDisplay() ; Get data transfer object Local $sDataTransferObject = $CmdLine[1] ; Get data from transfer object Local $oDataTransferObject = ObjGet( $sDataTransferObject ) Local $aArray = $oDataTransferObject.Item( "$aArray" ) Local $sTitle = $oDataTransferObject.Item( "$sTitle" ) Local $sHeader = $oDataTransferObject.Item( "$sHeader" ) ; Show array _ArrayDisplay( $aArray, $sTitle, "", 0, Default, $sHeader ) EndFunc Examples\RunArrayDisplay64.au3 is the example that demonstrates the use of RunArrayDisplay(). Run the example in SciTE with F5. #AutoIt3Wrapper_Au3Check_Parameters=-d -w- 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 #AutoIt3Wrapper_UseX64=Y Opt( "MustDeclareVars", 1 ) #include "..\Includes\NonBlockingDataDisplay.au3" Example() Func Example() ; Create array Local $aArray[1000][10] For $i = 0 To 1000 - 1 For $j = 0 To 9 $aArray[$i][$j] = $i & "/" & $j Next Next ; Display array RunArrayDisplay( "..\Includes\", $aArray, 1 ) ; 1 -> 64 bit code ; Modify array For $j = 0 To 9 $aArray[0][$j] = "Zero/" & $j Next ; Display array RunArrayDisplay( "..\Includes\", $aArray, 1, "ArrayDisplay 2", "C 0|C 1|C 2|C 3|C 4|C 5|C 6|C 7|C 8|C 9" ) ; The script isn't blocked While Sleep( 1000 ) ConsoleWrite( "The script isn't blocked" & @CRLF ) WEnd EndFunc ExamplesIn the Examples folder, there are three more examples. RunArrayDisplay32.au3 is a 32 bit version of RunArrayDisplay64.au3. RunDebugArrayDisplay64.au3 demonstrates the use of RunDebugArrayDisplay() in the UDF. A prerequisite for running the example is that you're using an AutoIt version that includes _DebugArrayDisplay(). The AutoIt version isn't checked in the code. RunDisplayStruct64.au3 demonstrates the use of RunDisplayStruct() in the UDF. The example is based on the example of _WinAPI_DisplayStruct() in the help file. 7z-fileThe 7z-file contains source code for UDFs and examples. You need AutoIt 3.3.12 or later. Tested on Windows 7 and Windows 10. Comments are welcome. Let me know if there are any issues. NonBlockingDataDisplay.7z1 point
-
Line 9 ? My line ? Man, you are good !1 point
-
Autoit WinMenuSelectItem not working on ImageJ
Wellwellwell reacted to Nine for a topic
In help file under WinMenuSelectItem : Try using _GUICtrlMenu_GetMenu and the other functions to parse the actual text of the menu. If you cannot grasp the text then you will have to use UIAutomation.1 point -
If you mean the background then set alpha channel of _GDIPlus_GraphicsClear($hGraphics, 0x7F7F7F7F) (ARGB) accordingly. Here 0x7F is semi-transparent.1 point
-
Object method with structure array as parameter
DonChunior reacted to TheXman for a topic
@DonChunior I haven't looked through your whole bits.au3 udf file, but I do see one issue. Your definition if the BG_FILE_INFO struct is not correct. You aren't currently using it in your UDF but when/if you do, it will cause problems as it is currently defined. It is currently defined as: ; BG_FILE_INFO structure (https://docs.microsoft.com/en-us/windows/win32/api/bits/ns-bits-bg_file_info) Global Const $tagBG_FILE_INFO = "struct;wchar remoteName[2201];wchar localName[261];endstruct" it should be something like: Const $tagBG_FILE_INFO = _ "struct; " & _ "ptr remoteName;" & _ "ptr localName;" & _ "endstruct;" Below is a quick example that I created that will create an array of BG_FILE_INFO structs. It is based on an interpretation of the AddFileSet example code from the Microsoft site. It is commented pretty well but does not have any error checking. It is just a quick script to show another way that the struct array can be created. Because AutoIt does not make it easy to get pointer information of normally declared variables, the next best thing is to declare structs to hold the variables. That will give you access to their pointers. So as you will see, in order to get pointers to the remote and local names of the file set, I create an array of structs for the names. Other than that, the code should be pretty straight forward. I haven't tested it with your UDF. I'll leave that part of the fun to you. #AutoIt3Wrapper_AU3Check_Parameters=-w 3 -w 4 -w 5 -w 6 -d #include <Constants.au3> #include <WinAPIDiag.au3> #include <Array.au3> Const $gtagBG_FILE_INFO = _ "struct; " & _ "ptr remoteName;" & _ "ptr localName;" & _ "endstruct;" Global $gaFileSet = _ [ _ ["http://ipv4.download.thinkbroadband.com/1GB.zip", "C:\Temp\1GB.zip"], _ ["http://ipv4.download.thinkbroadband.com/512MB.zip", "C:\Temp\512MB.zip"] _ ] Global $gtBG_FILE_INFO_ARRAY = "" ;Get BG_FILE_INFO_ARRAY $gtBG_FILE_INFO_ARRAY = get_bg_file_info_array_struct_example($gaFileSet) ;Display BG_FILE_INFO_ARRAY _WinAPI_DisplayStruct( _ $gtBG_FILE_INFO_ARRAY, _ StringFormat("ptr[%i]", UBound($gaFileSet) * 2), _ "BG_FILE_INFO Array" _ ) Func get_bg_file_info_array_struct_example($aFileSet) Local $tBG_FILE_INFO = "", $tByteBuffer = "", $tBG_FILE_INFO_ARRAY = "" Local $iBG_FILE_INFO_SIZE = 0 Local $pArrayItemPointer = 0 Local $xWcharString = Binary("") Local $atRemoteNames[0], $atLocalNames[0] ;For each file set For $i = 0 To UBound($aFileSet) - 1 ;Add remote name to array of remote name structs $xWcharString = StringToBinary($aFileSet[$i][0], $SB_UTF16LE) $tByteBuffer = DllStructCreate(StringFormat("byte data[%i];", BinaryLen($xWcharString))) $tByteBuffer.data = $xWcharString _ArrayAdd($atRemoteNames, $tByteBuffer) ;Add local name to array of local name structs $xWcharString = StringToBinary($aFileSet[$i][1], $SB_UTF16LE) $tByteBuffer = DllStructCreate(StringFormat("byte data[%i];", BinaryLen($xWcharString))) $tByteBuffer.data = $xWcharString _ArrayAdd($atLocalNames, $tByteBuffer) Next ;Create a bg_file_info struct to get size of struct $tBG_FILE_INFO = DllStructCreate($gtagBG_FILE_INFO) $iBG_FILE_INFO_SIZE = DllStructGetSize($tBG_FILE_INFO) ;Create byte buffer to hold array of bg_file_info structs $tBG_FILE_INFO_ARRAY = DllStructCreate(StringFormat("byte buffer[%i]", $iBG_FILE_INFO_SIZE * UBound($aFileSet))) ;For each file set For $i = 0 To UBound($aFileSet) - 1 ;Add a populated bg_file_info struct to the array of bg_file_info structs $pArrayItemPointer = DllStructGetPtr($tBG_FILE_INFO_ARRAY) + ($iBG_FILE_INFO_SIZE * $i) $tBG_FILE_INFO = DllStructCreate($gtagBG_FILE_INFO, $pArrayItemPointer) $tBG_FILE_INFO.remoteName = DllStructGetPtr($atRemoteNames[$i]) $tBG_FILE_INFO.localName = DllStructGetPtr($atLocalNames[$i]) Next ;Sanity check - Display values from the bg_file_info array to make sure they were loaded properly For $i = 0 To UBound($aFileSet) - 1 ;Point to bg_file_info struct item within the bg_file_info array $pArrayItemPointer = DllStructGetPtr($tBG_FILE_INFO_ARRAY) + ($iBG_FILE_INFO_SIZE * $i) $tBG_FILE_INFO = DllStructCreate($gtagBG_FILE_INFO, $pArrayItemPointer) ;Get & display the remote name pointed to by the remote name pointer $tByteBuffer = DllStructCreate("byte data[1000];", $tBG_FILE_INFO.remoteName) ConsoleWrite(StringFormat("Remote name %2i = %s", $i + 1, BinaryToString($tByteBuffer.data, $SB_UTF16LE)) & @CRLF) ;Get & display the local name pointed to by the local name pointer $tByteBuffer = DllStructCreate("byte data[1000];", $tBG_FILE_INFO.localName) ConsoleWrite(StringFormat("Local name %2i = %s", $i + 1, BinaryToString($tByteBuffer.data, $SB_UTF16LE)) & @CRLF) Next Return $tBG_FILE_INFO_ARRAY EndFunc Console output: (this output was just a sanity check for me to know that the information in the arrays were correct) Remote name 1 = http://ipv4.download.thinkbroadband.com/1GB.zip Local name 1 = C:\Temp\1GB.zip Remote name 2 = http://ipv4.download.thinkbroadband.com/512MB.zip Local name 2 = C:\Temp\512MB.zip1 point -
Ok... so I led you astray with the format of the command to restore the active tab. The one parameter needs to be formatted as a JSON string, so instead of this -- $sTabHandle = _WD_Window($sSession, 'window') do this -- $sTabHandle = '{"handle":"' & _WD_Window($sSession, "window") & '"}' You can then pass this string to the subsequent call to _WD_Window to establish the new active tab. P.S. This is something that you should have been able to figured out yourself by looking at the DemoWindows function in wd_demo.au3 😉1 point
-
I found another way to change the color without loosing proper anti-aliasing. For this solution GDI+ v1.1 (Win7+) is required. #include <Array.au3> #include <GDIPlus.au3> #include <WinAPISysWin.au3> #include <WinAPIShellEx.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Example_1() Func _SetBkIcon($ControlID, $iForeground, $iBackground, $sIcon, $iIndex, $iWidth, $iHeight) Local Static $STM_SETIMAGE = 0x0172 Local $hBitmap, $hGfx, $hImage, $hIcon, $hBkIcon $hIcon = _WinAPI_ShellExtractIcon($sIcon, $iIndex, $iWidth, $iHeight) $hImage = _GDIPlus_BitmapCreateFromHICON32($hIcon) Local $r = BitShift(BitAND($iForeground, 0xFF0000), 16), $g = BitShift(BitAND($iForeground, 0xFF00), 8), $b = BitAND($iForeground, 0xFF) Local $hEffect = _GDIPlus_EffectCreateColorCurve($GDIP_AdjustExposure, $GDIP_CurveChannelRed, $r) ;GDI+ v1.1 is needed -> Win7+ _GDIPlus_BitmapApplyEffect($hImage, $hEffect) _GDIPlus_EffectDispose($hEffect) $hEffect = _GDIPlus_EffectCreateColorCurve($GDIP_AdjustExposure, $GDIP_CurveChannelGreen, $g) _GDIPlus_BitmapApplyEffect($hImage, $hEffect) _GDIPlus_EffectDispose($hEffect) $hEffect = _GDIPlus_EffectCreateColorCurve($GDIP_AdjustExposure, $GDIP_CurveChannelBlue, $b) _GDIPlus_BitmapApplyEffect($hImage, $hEffect) _GDIPlus_EffectDispose($hEffect) If $iBackground Then $hBitmap = _GDIPlus_BitmapCreateFromScan0($iWidth, $iHeight) $hGfx = _GDIPlus_ImageGetGraphicsContext($hBitmap) _GDIPlus_GraphicsClear($hGfx, $iBackground) _GDIPlus_GraphicsDrawImageRect($hGfx, $hImage, 0, 0, $iWidth, $iHeight) _GDIPlus_ImageDispose($hImage) $hImage = _GDIPlus_ImageClone($hBitmap) _GDIPlus_GraphicsDispose($hGfx) _GDIPlus_ImageDispose($hBitmap) EndIf $hBkIcon = _GDIPlus_HICONCreateFromBitmap($hImage) GUICtrlSendMsg($ControlID, $STM_SETIMAGE, $IMAGE_ICON, $hBkIcon) _WinAPI_RedrawWindow(GUICtrlGetHandle($ControlID)) _WinAPI_DeleteObject($hIcon) _WinAPI_DeleteObject($hBkIcon) _GDIPlus_ImageDispose($hImage) Return SetError(0, 0, 1) EndFunc ;==>_SetBkIcon Func Example_1() Local $hGui = GUICreate("GDI+", 512, 256) GUISetState(@SW_SHOW) If Not _GDIPlus_Startup() Or @extended < 6 Then MsgBox($MB_SYSTEMMODAL, "ERROR", "GDIPlus.dll v1.1 not available") Return EndIf ; Original Icon GUICtrlCreateIcon(@ScriptDir & "\git.ico", -1, 0, 0, 256, 256) ; Only Recolor Background GUICtrlCreateIcon("", -1, 256, 0, 256, 256) _SetBkIcon(-1, 0xFFABCDEF, 0xFFFFFF00, @ScriptDir & "\git.ico", -1, 256, 256) Do Until GUIGetMsg() = $GUI_EVENT_CLOSE GUIDelete($hGui) EndFunc ;==>Example_1 Works best with monochrome like images. Btw, when you use $hImage = _GDIPlus_BitmapCreateFromHICON32($hIcon) in your example it will work, too.1 point
-
WebDriver UDF - Help & Support (III)
seadoggie01 reacted to Danp2 for a topic
Not sure what you mean here. Are you asking at what point you can access the data being returned from _WD_ElementAction? If so, the answer is "whenever your script proceeds to the next line in your script" You are doing more than just sending Enter. Where is "lp/sv1020/1aug" being sent to? If an element in the browser, which one? Did you try using _WD_SetElementValue here? <rant> FWIW, It gets frustrating when people (not just you 😉) ask for help, but aren't voluntarily providing sufficient information so that we can offer solutions / recommendations. Sometimes it feels like I'm like I'm "pulling teeth" to get the necessary details. </rant> P.S. It is actually possible to send Enter to an element using Webdriver commands. I think this has come up previously on the forum (you can try searching on _WD_Action and the 'actions' command), but it's not for the faint of heart.1 point -
Object method with structure array as parameter
DonChunior reacted to Nine for a topic
Try something like this : #include <WinAPIDiag.au3> Local $aFileSet[][] = [["RemoteName1", "LocalName1"], ["RemoteName2", "LocalName2"], ["RemoteName3", "LocalName3"]] Local $sStructDef For $i = 0 To UBound($aFileSet) - 1 $sStructDef &= "char r" & $i+1 & "[" & StringLen($aFileSet[$i][0])+1 & "];char l" & $i+1 & "[" & StringLen($aFileSet[$i][1])+1 & "];" Next ConsoleWrite($sStructDef & @CRLF) $tStruct = DllStructCreate($sStructDef) For $i = 0 To UBound($aFileSet) - 1 DllStructSetData($tStruct, "r" & $i+1, $aFileSet[$i][0]) DllStructSetData($tStruct, "l" & $i+1, $aFileSet[$i][1]) Next _WinAPI_DisplayStruct($tStruct, $sStructDef) $pStruct = DllStructGetPtr($tStruct)1 point -
This applies for all code, anything you store in your program can be easily extracted and decrypted... even big companies which specialize in anti-tampering technology fail. This is a fundamental flaw which arises from the fact that you want the machine to know the secret but not the user, in other words, you can't have your cake and eat it too1 point
-
Trying to create an alerts based on a txt file
Loc reacted to JLogan3o13 for a topic
There are, as usual, 1000 ways to skin the proverbial cat. If this is a txt file as you state, you could do something like the following: #include <Array.au3> Local $file = @DesktopDir & "\Schedule.txt" $schedule = FileReadLine($file, -1) $aSchedule = StringSplit($schedule, ";") _ArrayDisplay($aSchedule) Note that you could easily do this in fewer lines, but wanted to show the steps. You could also do something like this, if you have no need to re-use the file path: #include <Array.au3> Local $aSchedule = StringSplit(FileReadLine(@DesktopDir & "\Schedule.txt", -1), ";") _ArrayDisplay($aSchedule) Once you have the information you want (Day/Time/Event) you can use these items to create a task using the Windows Task Scheduler and point it to a script that brings up your MsgBox. Search the forum; there are tons of posts on creating tasks.1 point