Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 11/21/2021 in all areas

  1. StructuresWith the Marshal.StructureToPtr( Object, IntPtr, Boolean ) method, a structure can be copied from C#/VB.NET to AutoIt. With the Marshal.PtrToStructure(IntPtr, Type) method, a structure can be copied from AutoIt to C#/VB.NET. This is demonstrated in Example01 in \Examples\5) Structures\: #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 <StructureConstants.au3> #include "..\..\Includes\DotNetAll.au3" Example() Func Example() Local $oNetCode = DotNet_LoadCScode( FileRead( "Example01.cs" ), "System.dll" ) Local $oTestClass = DotNet_CreateObject( $oNetCode, "TestClass" ) Local $pPtr = $oTestClass.Test1() Local $tPoint = DllStructCreate( $tagPOINT, $pPtr ) ConsoleWrite( "AutoIt: The value of first point is " & $tPoint.X & " and " & $tPoint.Y & @CRLF ); $tPoint.X = 3 $tPoint.Y = 4 ConsoleWrite( "AutoIt: The value of new point is " & $tPoint.X & " and " & $tPoint.Y & @CRLF ); $oTestClass.Test2() EndFunc using System; using System.Runtime.InteropServices; public struct Point { public int x; public int y; } class TestClass { // Global in class IntPtr pnt; public String Test1() { // Create a point struct Point p; p.x = 1; p.y = 2; Console.WriteLine( "CSharp: The value of first point is " + p.x + " and " + p.y ); // Initialize unmanged memory to hold the struct pnt = Marshal.AllocHGlobal( Marshal.SizeOf(p) ); // Copy the struct to unmanaged memory Marshal.StructureToPtr( p, pnt, false ); // Return memory pointer to AutoIt return pnt.ToString(); } public void Test2() { // Create another point Point anotherP; // Set this Point to the value of the Point in unmanaged memory anotherP = (Point)Marshal.PtrToStructure( pnt, typeof(Point) ); Console.WriteLine( "CSharp: The value of new point is " + anotherP.x + " and " + anotherP.y ); // Free the unmanaged memory Marshal.FreeHGlobal( pnt ); } } Example02 and Example03Example03 uses a structure that contains strings, integers and floating point numbers (doubles). In the example, 50,000, 100,000 and 250,000 instances of this structure are generated and copied from .NET to AutoIt. The purpose is to get an idea of how fast such structures can be copied with this data copying technique. The data copying technique is compared to the data passing technique used in Using C# and VB Code. Example02 passes 2d arrays from .NET to AutoIt where the columns match the data fields in the structure. In the example, arrays with 50,000, 100,000 and 250,000 rows are generated and passed. Both Example02 and Example03 are based on existing code to generate random data of types Strings, Integers, Floats, Dates, Times and Rows/Cols. See e.g. Real C# and VB examples. See also Random2dArray.txt. Example02 implementation #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 <Array.au3> #include "Random2dArray.au3" Example( 100, "sifdtr", "abcdefghijklmnopqrstuvwxyz" ) Example( 50000, "sifdtr", "abcdefghijklmnopqrstuvwxyz" ) Example( 100000, "sifdtr", "abcdefghijklmnopqrstuvwxyz" ) Example( 250000, "sifdtr", "abcdefghijklmnopqrstuvwxyz" ) Func Example( _ $iRows, _ ; Number of rows in the array $aColumns, _ ; Number of columns and data types in the array, see 1) in docu $sSource = "" ) ; Character source for string columns, random strings are created from these characters ; Load .NET code, create object Local $oNetCode = DotNet_LoadVBcode( FileRead( "Example02.vb" ), "System.dll" ) Local $oRand2dArrayClass = DotNet_CreateObject( $oNetCode, "Rand2dArrayClass" ) ; Check $aColumns array Local $iError = CheckColumnsArray( $aColumns ) If $iError Then Return SetError($iError,0,0) ; Define $aColTypes array Local $iColumns = UBound( $aColumns ) Local $aColTypes[6][$iColumns+1] ; Update $aColTypes and $aColumns For $i = 0 To $iColumns - 1 If CalcColTypes( $i, $aColumns, $aColTypes, $iRows, $sSource ) Then ContinueLoop $aColumns[$i][2] += 1 ; Because of .NET Random class ; Convert duplicates as a percentage to number of unique rows $aColumns[$i][3] = $iRows - Int( $iRows * $aColumns[$i][3] / 100 ) If $aColumns[$i][3] And $aColumns[$i][3] < $iRows Then $aColumns[$i][3] -= 1 Next ; Visual code verification If $iRows = 100 Then Local $aArray100 = $oRand2dArrayClass.Rand2dArray( $iRows, $aColumns, $aColTypes, $sSource ) _ArrayDisplay( $aArray100 ) Return EndIf Local $hTimer = TimerInit() Local $aArray = $oRand2dArrayClass.Rand2dArray( $iRows, $aColumns, $aColTypes, $sSource ) ConsoleWrite( TimerDiff( $hTimer ) & @CRLF ) #forceref $aArray EndFunc #cs 180.043279980917 387.024483304017 966.513008235719 #ce Imports System Class Rand2dArrayClass Public Function Rand2dArray( iRows As Integer, aColumns As Object(,), aColTypes As Object(,), sSource As String ) As Object(,) Dim iColumns As Integer = aColumns.GetUpperBound(1) + 1 Dim aSource As Char() = sSource.ToCharArray() Dim iSourceLen As Integer = sSource.Length Dim aObjects(iColumns-1,iRows-1) Dim oRnd As New Random() Dim sStr As String = "" Dim k, y, m, dMax As Integer For i As Integer = 0 To iRows - 1 'String columns For j As Integer = 1 To aColTypes(0,0) k = aColTypes(j,0) For l As Integer = 1 To oRnd.Next( aColumns(1,k), aColumns(2,k) ) sStr &= aSource(oRnd.Next( iSourceLen )) Next aObjects(k,i) = sStr sStr = "" Next 'Integer columns For j As Integer = 1 To aColTypes(0,1) k = aColTypes(j,1) aObjects(k,i) = oRnd.Next( aColumns(1,k), aColumns(2,k) ) Next 'Float columns For j As Integer = 1 To aColTypes(0,2) k = aColTypes(j,2) aObjects(k,i) = aColumns(1,k) + ( aColumns(2,k) - aColumns(1,k) ) * oRnd.NextDouble() Next 'Date columns For j As Integer = 1 To aColTypes(0,3) k = aColTypes(j,3) y = oRnd.Next( aColumns(1,k), aColumns(2,k) ) m = oRnd.Next( 1, 13 ) Select m Case 1, 3, 5, 7, 8, 10, 12 dMax = 31 Case 4, 6, 9, 11 dMax = 30 Case Else '2 dMax = If( y Mod 4 <> 0, 28, If( y Mod 400 = 0, 29, If( y Mod 100 = 0, 28, 29 ) ) ) End Select aObjects(k,i) = y * 10000 + m * 100 + oRnd.Next( 1, dMax + 1 ) Next 'Time columns For j As Integer = 1 To aColTypes(0,4) k = aColTypes(j,4) aObjects(k,i) = oRnd.Next( aColumns(1,k), aColumns(2,k) ) * 10000 + oRnd.Next( 0, 60 ) * 100 + oRnd.Next( 0, 60 ) Next 'Row/col columns For j As Integer = 1 To aColTypes(0,5) k = aColTypes(j,5) aObjects(k,i) = i & "/" & k Next Next Return aObjects End Function End Class Structure definitionThe structure in Example03.vb is defined this way: Public Structure Test Public iString As Integer 'String length Public sString As String Public iInteger As Integer Public dDouble As Double Public iDate As Integer Public iTime As Integer Public iRowCol As Integer 'String length Public sRowCol As String End Structure When a string is copied from the .NET structure to a corresponding AutoIt structure, only a string pointer is copied to the structure, while the string itself is stored in memory outside the structure. Therefore, AutoIt code must be used this way to read the string: $tString = DllStructCreate( "char sString[" & $tStruct.iString & "]", $tStruct.pString ) ConsoleWrite( "$tString.sString = " & $tString.sString & @CRLF ) Example03 implementation #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 "Random2dArray.au3" Example( 100, "sifdtr", "abcdefghijklmnopqrstuvwxyz" ) Example( 50000, "sifdtr", "abcdefghijklmnopqrstuvwxyz" ) Example( 100000, "sifdtr", "abcdefghijklmnopqrstuvwxyz" ) Example( 250000, "sifdtr", "abcdefghijklmnopqrstuvwxyz" ) Func Example( _ $iRows, _ ; Number of rows in the array $aColumns, _ ; Number of columns and data types in the array, see 1) in docu $sSource = "" ) ; Character source for string columns, random strings are created from these characters ; Load .NET code, create object Local $oNetCode = DotNet_LoadVBcode( FileRead( "Example03.vb" ), "System.dll" ) Local $oRand2dArrayClass = DotNet_CreateObject( $oNetCode, "Rand2dArrayClass" ) ; Check $aColumns array Local $iError = CheckColumnsArray( $aColumns ) If $iError Then Return SetError($iError,0,0) ; Define $aColTypes array Local $iColumns = UBound( $aColumns ) Local $aColTypes[6][$iColumns+1] ; Update $aColTypes and $aColumns For $i = 0 To $iColumns - 1 If CalcColTypes( $i, $aColumns, $aColTypes, $iRows, $sSource ) Then ContinueLoop $aColumns[$i][2] += 1 ; Because of .NET Random class ; Convert duplicates as a percentage to number of unique rows $aColumns[$i][3] = $iRows - Int( $iRows * $aColumns[$i][3] / 100 ) If $aColumns[$i][3] And $aColumns[$i][3] < $iRows Then $aColumns[$i][3] -= 1 Next ; Visual code verification If $iRows = 100 Then Local $pPtr100 = $oRand2dArrayClass.Rand2dArray( $iRows, $aColumns, $aColTypes, $sSource ), $tStruct, $tString, $iSize = @AutoItX64 ? 56 : 40 ConsoleWrite( "$pPtr100 = " & Ptr( $pPtr100 ) & @CRLF & @CRLF ) ; Display first structure ConsoleWrite( "First structure:" & @CRLF ) $tStruct = DllStructCreate( "int iString;ptr pString;int iInteger;double dDouble;int iDate;int iTime;int iRowCol;ptr pRowCol", $pPtr100 ) ConsoleWrite( "$tStruct.iString = " & $tStruct.iString & @CRLF ) ConsoleWrite( "$tStruct.pString = " & Ptr( $tStruct.pString ) & @CRLF ) $tString = DllStructCreate( "char sString[" & $tStruct.iString & "]", $tStruct.pString ) ConsoleWrite( "$tString.sString = " & $tString.sString & @CRLF ) ConsoleWrite( "$tStruct.iInteger = " & $tStruct.iInteger & @CRLF ) ConsoleWrite( "$tStruct.dDouble = " & $tStruct.dDouble & @CRLF ) ConsoleWrite( "$tStruct.iDate = " & $tStruct.iDate & @CRLF ) ConsoleWrite( "$tStruct.iTime = " & $tStruct.iTime & @CRLF ) ConsoleWrite( "$tStruct.iRowCol = " & $tStruct.iRowCol & @CRLF ) ConsoleWrite( "$tStruct.pRowCol = " & Ptr( $tStruct.pRowCol ) & @CRLF ) $tString = DllStructCreate( "char sString[" & $tStruct.iRowCol & "]", $tStruct.pRowCol ) ConsoleWrite( "$tString.sString = " & $tString.sString & @CRLF & @CRLF ) ; Display last structure ConsoleWrite( "Last structure:" & @CRLF ) $tStruct = DllStructCreate( "int iString;ptr pString;int iInteger;double dDouble;int iDate;int iTime;int iRowCol;ptr pRowCol", $pPtr100 + $iSize * ( $iRows - 1 ) ) ConsoleWrite( "$tStruct.iString = " & $tStruct.iString & @CRLF ) ConsoleWrite( "$tStruct.pString = " & Ptr( $tStruct.pString ) & @CRLF ) $tString = DllStructCreate( "char sString[" & $tStruct.iString & "]", $tStruct.pString ) ConsoleWrite( "$tString.sString = " & $tString.sString & @CRLF ) ConsoleWrite( "$tStruct.iInteger = " & $tStruct.iInteger & @CRLF ) ConsoleWrite( "$tStruct.dDouble = " & $tStruct.dDouble & @CRLF ) ConsoleWrite( "$tStruct.iDate = " & $tStruct.iDate & @CRLF ) ConsoleWrite( "$tStruct.iTime = " & $tStruct.iTime & @CRLF ) ConsoleWrite( "$tStruct.iRowCol = " & $tStruct.iRowCol & @CRLF ) ConsoleWrite( "$tStruct.pRowCol = " & Ptr( $tStruct.pRowCol ) & @CRLF ) $tString = DllStructCreate( "char sString[" & $tStruct.iRowCol & "]", $tStruct.pRowCol ) ConsoleWrite( "$tString.sString = " & $tString.sString & @CRLF & @CRLF ) ; Free structure memory $oRand2dArrayClass.FreeStructure() Return EndIf Local $hTimer = TimerInit() Local $pPtr = $oRand2dArrayClass.Rand2dArray( $iRows, $aColumns, $aColTypes, $sSource ) ConsoleWrite( TimerDiff( $hTimer ) & @CRLF ) ; Free structure memory $oRand2dArrayClass.FreeStructure() #forceref $pPtr EndFunc #cs 94.8014985921955 190.196704770522 465.101048033797 #ce Imports System Imports System.Runtime.InteropServices Public Structure Test Public iString As Integer 'String length Public sString As String Public iInteger As Integer Public dDouble As Double Public iDate As Integer Public iTime As Integer Public iRowCol As Integer 'String length Public sRowCol As String End Structure Class Rand2dArrayClass Dim pnt As IntPtr Public Function Rand2dArray( iRows As Integer, aColumns As Object(,), aColTypes As Object(,), sSource As String ) As String Dim iColumns As Integer = aColumns.GetUpperBound(1) + 1 Dim aSource As Char() = sSource.ToCharArray() Dim iSourceLen As Integer = sSource.Length Dim oRnd As New Random() Dim tTest As Test Dim iTotSize As IntPtr = 0 Dim iSize As Integer = Marshal.SizeOf( tTest ) pnt = Marshal.AllocHGlobal( iRows * iSize ) 'Console.WriteLine( "Marshal.SizeOf( tTest ) = {0}", iSize ) Dim sStr As String = "" Dim k, y, m, dMax As Integer For i As Integer = 0 To iRows - 1 'String columns For j As Integer = 1 To aColTypes(0,0) k = aColTypes(j,0) For l As Integer = 1 To oRnd.Next( aColumns(1,k), aColumns(2,k) ) sStr &= aSource(oRnd.Next( iSourceLen )) Next tTest.iString = sStr.Length + 1 tTest.sString = sStr sStr = "" Next 'Integer columns For j As Integer = 1 To aColTypes(0,1) k = aColTypes(j,1) tTest.iInteger = oRnd.Next( aColumns(1,k), aColumns(2,k) ) Next 'Float columns For j As Integer = 1 To aColTypes(0,2) k = aColTypes(j,2) tTest.dDouble = aColumns(1,k) + ( aColumns(2,k) - aColumns(1,k) ) * oRnd.NextDouble() Next 'Date columns For j As Integer = 1 To aColTypes(0,3) k = aColTypes(j,3) y = oRnd.Next( aColumns(1,k), aColumns(2,k) ) m = oRnd.Next( 1, 13 ) Select m Case 1, 3, 5, 7, 8, 10, 12 dMax = 31 Case 4, 6, 9, 11 dMax = 30 Case Else '2 dMax = If( y Mod 4 <> 0, 28, If( y Mod 400 = 0, 29, If( y Mod 100 = 0, 28, 29 ) ) ) End Select tTest.iDate = y * 10000 + m * 100 + oRnd.Next( 1, dMax + 1 ) Next 'Time columns For j As Integer = 1 To aColTypes(0,4) k = aColTypes(j,4) tTest.iTime = oRnd.Next( aColumns(1,k), aColumns(2,k) ) * 10000 + oRnd.Next( 0, 60 ) * 100 + oRnd.Next( 0, 60 ) Next 'Row/col columns For j As Integer = 1 To aColTypes(0,5) k = aColTypes(j,5) tTest.sRowCol = i & "/" & k tTest.iRowCol = tTest.sRowCol.Length + 1 Next 'Copy structure to unmanaged memory Marshal.StructureToPtr( tTest, pnt + iTotSize, False ) iTotSize += iSize Next Return pnt.ToString() End Function Public Sub FreeStructure() Marshal.FreeHGlobal( pnt ) End Sub End Class Performance measurementPerformance measurements for 50,000, 100,000 and 250,000 array rows and structure instances, respectively. Example02: 180.043279980917 387.024483304017 966.513008235719 Example03: 94.8014985921955 190.196704770522 465.101048033797 The passing technique in Example02 takes twice as long as the copying technique in Example03. Unicode supportThe characters to generate random strings ("abcdefghijklmnopqrstuvwxyz" in the examples) are copied directly from the au3 source files. To use Unicode characters, the text encoding of the source files must support Unicode characters. I use Notepad++ as editor and SciTE to run the code so that output can be seen in SciTE console. To use Unicode characters I set the text encoding in Notepad++ to UCS-2 Little Endian. And the char in the AutoIt DllStruct definition must of course be directed to wchar. 7z-fileNew 7z-file at bottom of first post.
    2 points
  2. Efo74, Glad I could produce something for you so quickly. M23
    1 point
  3. You'll want to set this to False if you want to instruct the UDF to skip checking for an existing instance of the webdriver.
    1 point
  4. Utter is a free ware windows API automation script.It can do most of the sapi dll functions."SAPI" stands for Windows Speech Reconition API,SAPI.dll is the file which manages the speech recognition of windows Utter utilises most of the SAPI functions making use of the best potential of SAPI.dll,You can include speech recognition to your project by using utter. Utter zipped and updated (new version with examples) Modified ......: 12/04/2017 Version .......: 3.0.0.1 Author ........: Surya I am new to autoit it sounds great and i love it while i am getting used to it so i want to write my own UDF in autoit first of all i thank all the forum members because i couldnt do it without research,So i wrote UTTER ,Its is a UDF that uses most of the SAPI dll function or in simple words it can do many functions relating to the computers speech recognition if you have any doubt in the code or have any bugs please notify me freely I will be always there to help its my first UDF so please notify me if you found any error Thank you! Utter has been recently updated ,examples included.The zip can be downloaded here at the download section of autoit : Download utter !! CAUTION !! REMEMBER TO SHUTDOWN THE INSTANCE OF CREATED RECOGNITION ENGINE BEFORE STARTING ANOTHER INSTANCE IF YOU START ANOTHER WITHOUT SHUTTING THE PREVIOUS ONE DOWN IT WILL LEAD TO AN ERROR! REMEMBER THAT "|" IS THE DEFAULT GUIDataSeparatorChar CHANGE IT ACCORDING TO YOUR NEEDS AND GRAMMAR DELIMITER IS GUIDataSeparatorChar IF NO GUIDataSeparatorChar IS FOUND IN THE INPUT STRING THEN THE ENTIRE STRING WOULD BE CONSIDERED AS ONE WORD! DO NOT CALL THE INTERNAL FUNCTIONS THEY ARE TO BE CALLED INSIDE THE FUNCTION AND DO NOT CHANGE THE VALUE OF VARIABLES USED IN THE FUNCTION! THE RECIEVING FUNCTIONS SHOULD HAVE ATLEAST ONE PARAMETER TO ACCEPT THE SPEECH COMMANDS FROM THE _Utter_Speech_GrammarRecognize() FUNCTION please report if you have any bugs/complaints
    1 point
  5. You can also use _FileWriteFromArray. To append you need to open the file using FileOpen with $FO_APPEND and use that handle with _FileWriteFromArray.
    1 point
  6. You can use _ArraytoString with @CRLF as the delimiter, then use FileWriteToLine.
    1 point
  7. Unfortunately I don't have the link you are looking for, but this script may generate something that (remotely) may look like what you are looking for p.s. the script is not mine, it is a translation of an old script for an Apple 2 recovered at the following link: https://www.calormen.com/jsbasic/ (select the script --> Snowflakes (Kevin Riordan)) #cs https://www.calormen.com/jsbasic/ SELECT --> Snowflakes (Kevin Riordan) 100 REM ***************************************************************** 110 REM * * 120 REM * SNOWFLAKE * 130 REM * A GRAPHICS NONSENSE FOR APPLE II * 140 REM * KEVIN RIORDAN 1985 * 150 REM * * 160 REM ***************************************************************** 170 : 180 REM THIS PROGRAM DRAWS SUCCESSIVE AND INCREASINGLY 190 REM INTRICATE SYMMETRICAL DESIGNS ON THE HIRES SCREEN. 210 REM IT RUNS IN AN ETERNAL LOOP 230 REM IT'S VERY RESTFUL TO STARE AT! 240 : #ce #include <ColorConstantS.au3> #include <GDIPlus.au3> #include <WindowsConstants.au3> #include <GUIConstantsEx.au3> _GDIPlus_Startup() OnAutoItExitRegister("_Terminate") Global $graphheight = @DesktopHeight / 2 Global $graphwidth = $graphheight ; @DesktopWidth / 2 Global $iCX = $graphwidth / 2, $iCY = $graphheight / 2 Global $hMain, $PenColor = 0xFFFF0000 Global $hGraphics, $hPen, $hColor, $hDC, $hHBitmap, $hDC_backbuffer, $DC_obj _GraphWindow($graphwidth, $graphheight) Global $x = 3, $S = $iCX, $T = $iCY _WinAPI_BitBlt($hDC_backbuffer, 0, 0, $graphwidth, $graphheight, $hDC_backbuffer, 0, 0, $WHITENESS) Do For $y = 0 To Int(($x - 2) / 2) fn280() Sleep(750) _WinAPI_BitBlt($hDC_backbuffer, 0, 0, $graphwidth, $graphheight, $hDC_backbuffer, 0, 0, $WHITENESS) Next $x += 1 Until GUIGetMsg() = $GUI_EVENT_CLOSE _Terminate() Func fn280() $A1 = 2 * (22 / 7) / $x $A2 = $A1 * ($y + 1) $C = 1 / Sin((22 / 7) * ($y + 1) / $x) $D = $x $E = $y + 1 Do $D = $D - Int($D / $E) * $E $ENDLOOP = True If Abs($D) > 0.5 Then $F = $E $E = $D $D = $F $ENDLOOP = False EndIf Until $ENDLOOP $E = Int($E + 0.5) $D = $x / $E If $D - Int($D / 2) * 2 > 0.5 Then $C += Cos((22 / 7) * $E / (2 * $x)) $G = $x + 0.5 $K = $D - 0.5 For $L = 1 To Int($G) $M = 0 $N = 0 $R = ($L - 1) * $A1 For $Q = 1 To Int($K) $M += Cos($R) / $C $N += Sin($R) / $C $U = $iCX + Int($iCY * $M + 0.5) $V = $iCY + Int($iCY * $N + 0.5) _GDIPlus_GraphicsDrawLine($hGraphics, $S, $T, $U, $V, $hPen) _WinAPI_BitBlt($hDC, 0, 0, $graphwidth, $graphheight, $hDC_backbuffer, 0, 0, $SRCCOPY) ;blit drawn bitmap to GUI $S = $U $T = $V $R += $A2 Next $U = $iCX $V = $iCY _GDIPlus_GraphicsDrawLine($hGraphics, $S, $T, $U, $V, $hPen) _WinAPI_BitBlt($hDC, 0, 0, $graphwidth, $graphheight, $hDC_backbuffer, 0, 0, $SRCCOPY) ;blit drawn bitmap to GUI $S = $iCX $T = $iCY If GUIGetMsg() = $GUI_EVENT_CLOSE Then _Terminate() Next EndFunc ;==>fn280 Func _GraphWindow($graphwidth, $graphheight) $hMain = GUICreate("Spirograph", $graphwidth, $graphheight) GUISetState(@SW_SHOW, $hMain) $hDC = _WinAPI_GetDC($hMain) $hHBitmap = _WinAPI_CreateCompatibleBitmap($hDC, $graphwidth, $graphheight) $hDC_backbuffer = _WinAPI_CreateCompatibleDC($hDC) $DC_obj = _WinAPI_SelectObject($hDC_backbuffer, $hHBitmap) $hGraphics = _GDIPlus_GraphicsCreateFromHDC($hDC_backbuffer) _GDIPlus_GraphicsSetSmoothingMode($hGraphics, $GDIP_SMOOTHINGMODE_HIGHQUALITY) _GDIPlus_GraphicsSetPixelOffsetMode($hGraphics, $GDIP_PIXELOFFSETMODE_HIGHQUALITY) $hPen = _GDIPlus_PenCreate($PenColor, 2) EndFunc ;==>_GraphWindow Func _Terminate() ; Clean up resources _WinAPI_SelectObject($hDC_backbuffer, $DC_obj) _WinAPI_DeleteDC($hDC_backbuffer) _WinAPI_DeleteObject($hHBitmap) _WinAPI_ReleaseDC($hMain, $hDC) _GDIPlus_GraphicsDispose($hGraphics) _GDIPlus_PenDispose($hPen) _GDIPlus_Shutdown() GUIDelete($hMain) Exit EndFunc ;==>_Terminate
    1 point
  8. Here how to proceed with an overlapped file : Func _FileBlock_Open($sFileName) Local $hFile = _WinAPI_CreateFileEx($sFileName, $OPEN_EXISTING, $GENERIC_READ, 0, $FILE_FLAG_OVERLAPPED) If Not $hFile Then Return SetError(_WinAPI_GetLastError()) $tOverlap = DllStructCreate($tagOVERLAPPED) $pOverlap = DllStructGetPtr($tOverlap) $hEvent = _WinAPI_CreateEvent(0, False, False) If $hEvent = 0 Then Exit MsgBox($MB_SYSTEMMODAL, "FileBlock Open", "CreateEvent failed") $tOverlap.hEvent = $hEvent Return $hFile EndFunc ;==>_FileBlock_Open
    1 point
  9. To get the title or handle of the active window : HotKeySet("{ESC}", "_Terminate") HotKeySet("+!1", "_ActiveWindow") ; Shift-Alt-1 Global $sTitleActive, $hHandleActive ; Title or Handle While True Sleep(100) WEnd Func _ActiveWindow() $sTitleActive = WinGetTitle("[active]") $hHandleActive = WinGetHandle("[active]") MsgBox(BitOR(4096, 64), "Minimize :", "Title : " & @CRLF & $sTitleActive & @CRLF & _ "Handle : " & @CRLF & $hHandleActive & @CRLF) EndFunc Func _Terminate() MsgBox(BitOR(4096, 64), "Message :", "Script terminated" & @CRLF) Exit EndFunc Use WinSetState (with title or handle) to minimize the active window for example.
    1 point
  10. Hello. Please next time share a runnable code. Here is an example I wrote years ago. #include <Array.au3> Global Enum $LIBUSB_SUCCESS = 0 Global $g_sLibName = @AutoItX64 ? "iLibUSB.dll" : "iLibUSB_32.dll" Global $g_hlibusb = DllOpen($g_sLibName) _Test() Func _Test() _libusb_init() Local $ahDevicesList = _libusb_get_device_list() _ArrayDisplay($ahDevicesList) _libusb_free_device_list($ahDevicesList) _libusb_exit() EndFunc ;==>_Test Func _libusb_exit($hContext = 0) DllCall($g_hlibusb, "none", "libusb_exit", "ptr", $hContext) If @error Then Return SetError(1, 0, 0) Return 1 EndFunc ;==>_libusb_exit Func _libusb_free_device_list(ByRef $ahDevicesList, $iUnref_Devices = 1) If Not IsArray($ahDevicesList) Or Not UBound($ahDevicesList) Then Return SetError(1, 0, 0) Local $hDeviceList = (UBound($ahDevicesList, 2) = 4) ? $ahDevicesList[0][0] : $ahDevicesList[0] If Not $hDeviceList Then Return SetError(1, 0, 0) Local $aCall = DllCall($g_hlibusb, "none", "libusb_free_device_list", "ptr", $hDeviceList, "int", $iUnref_Devices) If @error Then Return SetError(1, 0, 0) Return 1 EndFunc ;==>_libusb_free_device_list Func _libusb_get_device_list($hContext = 0) Local $aCall = DllCall($g_hlibusb, "int", "libusb_get_device_list", "ptr", $hContext, "ptr*", 0) If @error Or Not $aCall[0] Then Return SetError(1, 0, 0) Local $tlibusb_device_list = DllStructCreate("ptr[" & $aCall[0] & "]", $aCall[2]) Local $ahDevicesList[$aCall[0] + 1] $ahDevicesList[0] = $aCall[2] ;store libusb_device pointer For $i = 1 To $aCall[0] $ahDevicesList[$i] = DllStructGetData($tlibusb_device_list, 1, $i) Next Return $ahDevicesList EndFunc ;==>_libusb_get_device_list Func _libusb_init($bNewhContext = False) If Not $g_hlibusb Then Return SetError(1, 0, -1) Local $sParamType = ($bNewhContext) ? "ptr*" : "ptr" Local $aCall = DllCall($g_hlibusb, "int", "libusb_init", $sParamType, 0) If @error Or Not $aCall[0] = $LIBUSB_SUCCESS Then Return SetError(1, 0, 0) Return $aCall[1] EndFunc ;==>_libusb_init PD: I like your website. It's nice. Saludos
    1 point
×
×
  • Create New...