Leaderboard
Popular Content
Showing content with the highest reputation on 01/30/2022 in all areas
-
Anybody could help with using QueryInterface in AutoIt to embed Microsoft Edge using WebView2 Interface ? Here are links to information/documentation: Image comes from: https://docs.microsoft.com/en-us/microsoft-edge/webview2/media/webview2/whatwebview.png Introduction to Microsoft Edge WebView2 https://docs.microsoft.com/en-us/microsoft-edge/webview2/ Understand WebView2 SDK versions https://docs.microsoft.com/en-us/microsoft-edge/webview2/concepts/versioning Download: https://developer.microsoft.com/en-US/microsoft-edge/webview2/ https://developer.microsoft.com/en-US/microsoft-edge/webview2/#download-section https://docs.microsoft.com/en-us/microsoft-edge/webview2/concepts/distribution API Reference: https://docs.microsoft.com/en-us/microsoft-edge/webview2/reference/win32/?view=webview2-1.0.622.22 HowTo/Concepts: https://docs.microsoft.com/en-us/microsoft-edge/webview2/concepts/versioning https://docs.microsoft.com/en-us/microsoft-edge/webview2/gettingstarted/win32 https://docs.microsoft.com/en-us/microsoft-edge/webview2/howto/debug?tabs=devtools https://docs.microsoft.com/en-us/microsoft-edge/webview2/concepts/security https://docs.microsoft.com/en-us/microsoft-edge/webview2/concepts/userdatafolder https://mybuild.microsoft.com/sessions/9198aeac-0c8e-4d32-96d1-cbb99a390aa6 Example: https://github.com/MicrosoftEdge/WebView2Samples Related: https://www.essentialobjects.com/Products/WebBrowser/Default.aspx?gclid=CjwKCAiA17P9BRB2EiwAMvwNyMe6UI9VHej-JYDBUoyGDFz40KaaJ_RidY-75Fhr-PHz65sSVC0XlxoC5loQAvD_BwE https://docs.microsoft.com/en-us/microsoft-edge/webview2/howto/webdriver btw. I'm not WindowsApi expert (QueryInterface, C++, DllCall). What I trying to say is: It means that I do not done anything in this regards .... as so far. TIMELINE/ChangeLog: 2020-11-12 - Project propsed by @mLipok 2021-02-03 - First version provided by @LarsJ1 point
-
Honestly I can't remember this thing In such cases I personally use a small func to first remove empty lines and lines containing the unwanted string - or several unwanted strings, in this case write them in the $filter param with a separator (here I used a semicolon) #include <Array.au3> $sPattern = '(?ims)^\h*(?|(?:local|Global)\h+(\N+)|((?|\$|GUI[cs])\N+))(?=.*GUISetState)' _Read("GUICtrlCreateDummy.au3") _Read("_WinAPI_CallWindowProc.au3") _Read("GUICtrlCreateContextMenu[2].au3") Func _Read($file) Local $sPath = @ProgramFilesDir & "\AutoIt3\Examples\Helpfile\" $txt = _clean(FileRead($sPath & $file), "GUICtrlCreateDummy()") _ArrayDisplay(StringRegExp($txt, $sPattern, 3)) EndFunc Func _clean($txt, $filter, $separator = ";") $filter = "\Q" & StringReplace($filter, $separator, "\E|\Q") & "\E" Return StringRegExpReplace($txt, '(?m)^(\s*|.*(?:' & $filter & ').*)$\R?', "") EndFunc1 point
-
Sort question in C++
UEZ reacted to pixelsearch for a topic
Hi everybody, After reading a bit about Vectors in C++, I could quickly sort a string column in a 2D array (example made with an AutoIt 2D array of 100.000 rows and 6 cols, also tried 500.000 rows). Here are the corresponding codes : AutoIt code : #include <Array.au3> ; #include <WinAPIDiag.au3> #include "RandomArray.au3" ; LarsJ $hDLL = DllOpen(@ScriptDir & "\rrr_03.dll") If $hDLL = -1 Then Exit Msgbox(0, "DllOpen", "error occured") Global $g_iRows = 100000, $g_iCols = 6, $g_iSort_Col = 0, $g_aArray ; only col 0 is string _Generate_All($g_aArray) Local $aBackup = $g_aArray ; extremely fast ! _ArrayDisplay($g_aArray, "UNsorted", Default, Default, Default, _ "Strings|Integers*|Floats*|Dates*|Times*|R/C*") ;==================== $hTimer = TimerInit() Local $sDelim = Chr(1), $sData = "" For $i = 0 To $g_iRows - 1 $sData &= $g_aArray[$i][$g_iSort_Col] & $sDelim Next ConsoleWrite("Preparing concatenated string = " & Int(TimerDiff($htimer)) & " ms" & @crlf) ;==================== $hTimer = TimerInit() $iBufferSize = StringLen($sData) $tStruct = DllStructCreate("char[" & $iBufferSize & "]") If @error Then Exit Msgbox(0, "DllStructCreate", "error " & @error) DllStructSetData($tStruct, 1, $sData) If @error Then Exit Msgbox(0, "DllStructSetData", "error " & @error) ConsoleWrite("Writing structure = " & Int(TimerDiff($htimer)) & " ms" & @crlf) MsgBox(0, "Pointer of struct", DllStructGetPtr($tStruct) & " Buffer size = " & $iBufferSize) $tStruct2 = DllStructCreate("int[" & $g_iRows & "]") ; will be filled by dll If @error Then Exit Msgbox(0, "DllStructCreate 2", "error " & @error) ;==================== $hTimer = TimerInit() $aRet = DllCall($hDLL, "int:cdecl", "StringSort2D", "ptr", DllStructGetPtr($tStruct), _ "ptr", DllStructGetPtr($tStruct2), "str", $sDelim, "int", $g_iRows) If @error Then Exit Msgbox(0, "DllCall StringSort2D", "error " & @error) ConsoleWrite("DllCall = " & Int(TimerDiff($htimer)) & " ms" & @crlf) _ArrayDisplay($aRet, "$aRet") ; _WinAPI_DisplayStruct($tStruct2, "int[" & $g_iRows & "]", "$tStruct2") ;==================== $hTimer = TimerInit() For $i = 0 To $g_iRows - 1 $iIndex = DllStructGetData($tStruct2, 1, $i + 1) ; row index before sorting If $i <> $iIndex Then For $j = 0 To $g_iCols - 1 $g_aArray[$i][$j] = $aBackup[$iIndex][$j] Next EndIf Next ConsoleWrite("Generating sorted 2D array = " & Int(TimerDiff($htimer)) & " ms" & @crlf) _ArrayDisplay($g_aArray, "sorted (col " & $g_iSort_Col & ")", Default, Default, Default, _ "Strings|Integers*|Floats*|Dates*|Times*|R/C*") _StringSplitFree($tStruct) _StringSplitFree($tStruct2) DllClose($hDLL) ;============================================= Func _Generate_All(ByRef $g_aArray) ; LarsJ ConsoleWrite("$g_iRows = " & $g_iRows & " $g_iCols = " & $g_iCols & @CRLF) $g_aArray = FAS_Random2DArrayAu3($g_iRows, "sifdtr", "abcdefghijklmnopqrstuvwxyz") EndFunc ;==>_Generate_All ;============================================= Func _StringSplitFree(ByRef $tStruct) ; Funkey DllCall("msvcrt.dll", "none:cdecl", "free", "ptr", DllStructGetPtr($tStruct)) If @error Then Exit Msgbox(0, "DllCall Free", "error " & @error & " occured") $tStruct = 0 EndFunc ;==>_StringSplitFree C++ code // build options OF THE PROJECT : check line C++1z (C++17) or these errors appear : // error: 'to_string' was not declared in this scope // error: 'stoi' was not declared in this scope #include <algorithm> // sort #include <string.h> // strtok #include <string> // string #include <vector> // vector using namespace std; bool sortcol(const vector<string>& v1, const vector<string>& v2) { return v1[0] < v2[0]; // [0] sort on col 0, [1] on col 1 etc... (not in this dll) // To sort descending : // return v1[0] > v2[0]; } extern "C" __declspec(dllexport) int StringSort2D(char* structure, int* structure2, char* sdelim, int irows) { vector<vector<string> > vect(irows, vector<string>(2)); // irows and 2 cols int i = 0; char* p; p = strtok(structure, sdelim); // split string into tokens (returns a pointer). // End of the token (delimiter) is automatically replaced by a null-character // https://www.cplusplus.com/reference/cstring/strtok/ while ((p != NULL) && (i < irows)) { vect[i][0] = p; // string (col 0 will be sorted) vect[i][1] = to_string(i); // row (to remember initial index before sorting) p = strtok(NULL, sdelim); i++; } sort(vect.begin(), vect.end(), sortcol); // sort on column 0 (string) in this dll for(i = 0; i < irows; ++i) { *(structure2 + i) = stoi(vect[i][1]); // index of sorted string [i][0] ... before sorting } // this should release memory used by the vector (to be confirmed) : // https://en.wikibooks.org/wiki/More_C%2B%2B_Idioms/Clear-and-minimize // http://www.cplusplus.com/reference/vector/vector/clear/ <= recommeneds swap() // http://www.cplusplus.com/reference/vector/vector/swap-free/ vector<vector<string>>().swap(vect); return 0; } I kept a part of the flowchart used for 1D array (see precedent post) but had to adapt it for 2D, by adding this : * Create a 2nd structure (int) in AutoIt to be filled by the Dll during DllCall(). This structure will contain the index (row) of each sorted string ... before it was sorted. Here is an example based on 10 strings : As you can see in the structure pic (the 2nd pic with its 1st line in green) the value of the 1st line in the structure is 2. It means that the 1st string sorted ("axso..." in the sorted pic) HAD an index of 2 in the unsorted pic. This goes for all the other sorted strings. Same explanation for another string : the last string sorted ("trll..." in the sorted pic) HAD an index of 0 in the unsorted pic. This index in the structure will be used to grab the correct values of all the other columns in a backup of the initial array ($aBackup), pointing to the correct row. So in the C++ code, the 2D vector has only 2 columns : - a column for the unsorted strings - a column for the index (row) of the string in the Autoit array (which is 0, 1, 2, 3... before the sort) After the sort is done on the string column (in the Dll), the strings will be sorted in the 1st column and their "index before sorting" will be found unaltered in the other column, which will fill the index structure. There are certainly other ways to achieve this but this is what I found. The next step should be to create a udf to take care of all cases (1D, 2D, col to be sorted, numeric or alphabetic sort, asc or desc) and to separate functions in the dll (all sorting functions should be based on vectors in the Dll, even if it's a 1D array in AutoIt) If something is ready one day, I'll post it here. Meanwhile, I hope the code will be helpful for some users. The hardest part I faced ? Find the C++ code to declare a 2D vector of strings as "easily" as we declare a 2D array in AutoIt vector<vector<string> > vect(irows, vector<string>(2)); // irows and 2 cols Edit 10 february 2022 : Though the preceding script works fine, it will soon be replaced with C++ code based on a Vector of structs (in a future post of this thread)1 point -
Here an example based on IE examples : Local $bFound = False, $sSelect Local $oObj = _IEGetObjById($oIE, "selectExampleID") If Not IsObj($oObj) Then Return MsgBox($MB_SYSTEMMODAL, "", "Not an object") Local $colOpt = _IETagNameGetCollection($oObj, "option") MsgBox($MB_SYSTEMMODAL, "Number of", $colOpt.length) For $oOpt in $colOpt ConsoleWrite($oOpt.innerText & @CRLF) If StringInStr($oOpt.innerText, "Midi") Then $sSelect = StringStripWS($oOpt.innerText, $STR_STRIPTRAILING) _IEAction($oObj, "focus") _IEFormElementOptionSelect ($oObj, $sSelect, 1, "byText") $bFound = True ExitLoop EndIf Next If Not $bFound Then Exit MsgBox($MB_SYSTEMMODAL, "Error", "No find")1 point
-
Getting started example step 4: Navigation eventsWebView2-2.au3: #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 <MsgBoxConstants.au3> #include <WindowsConstants.au3> #include <GUIConstantsEx.au3> #include <WinAPICom.au3> #include <WinAPI.au3> Global $hGui ; Project includes #include "..\Includes\WV2Interfaces.au3" WebView2() Func WebView2() ; Create WebView2 GUI $hGui = GUICreate( "WebView2 Sample", 1200, 900, -1, -1, $WS_OVERLAPPEDWINDOW ) ; Initialize COM _WinAPI_CoInitialize( $COINIT_APARTMENTTHREADED ) ; Create callback interface and functions CoreWebView2CreateCoreWebView2EnvironmentCompletedHandlerCreate( True ) ; Forces CoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_Invoke() below to be executed ; Create callback interface and functions CoreWebView2CreateCoreWebView2ControllerCompletedHandlerCreate( True ) ; Create callback interface and functions CoreWebView2NavigationStartingEventHandlerCreate( True ) ; DllCall CreateCoreWebView2EnvironmentWithOptions Local $hWebView2Loader = DllOpen( @AutoItX64 ? "WebView2Loader-x64.dll" : "WebView2Loader-x86.dll" ) Local $aRet = DllCall( $hWebView2Loader, "long", "CreateCoreWebView2EnvironmentWithOptions", "wstr", "", "wstr", "", _ "ptr", NULL, "ptr", $pCoreWebView2CreateCoreWebView2EnvironmentCompletedHandler ) If @error Or $aRet[0] Then Return ConsoleWrite( "CreateCoreWebView2EnvironmentWithOptions ERR" & @CRLF ) ConsoleWrite( "CreateCoreWebView2EnvironmentWithOptions OK" & @CRLF & @CRLF ) ; Show WebView2 GUI GUISetState( @SW_SHOW ) ; Loop While 1 Switch GUIGetMsg() Case $GUI_EVENT_MAXIMIZE, $GUI_EVENT_RESIZED, $GUI_EVENT_RESTORE Local $tRect = _WinAPI_GetClientRect( $hGui ) $oCoreWebView2Controller.put_Bounds( $tRect ) Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd ; Cleanup CoreWebView2CreateCoreWebView2ControllerCompletedHandlerDelete() CoreWebView2CreateCoreWebView2EnvironmentCompletedHandlerDelete() DllClose( $hWebView2Loader ) EndFunc ; Copied from WV2Interfaces.au3 ; Executed automatically when the callback interface is created Func CoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_Invoke( $pSelf, $long, $ptr ) ; Ret: long Par: long;ptr* ConsoleWrite( "CoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_Invoke" & @CRLF ) ; Create CoreWebView2Environment object $oCoreWebView2Environment = ObjCreateInterface( $ptr, $sIID_ICoreWebView2Environment, $dtag_ICoreWebView2Environment ) ConsoleWrite( "IsObj( $oCoreWebView2Environment ) = " & IsObj( $oCoreWebView2Environment ) & @CRLF & @CRLF ) ; Set $pCoreWebView2CreateCoreWebView2ControllerCompletedHandler callback pointer for the WebView2 GUI $oCoreWebView2Environment.CreateCoreWebView2Controller( $hGui, $pCoreWebView2CreateCoreWebView2ControllerCompletedHandler ) ; Forces CoreWebView2CreateCoreWebView2ControllerCompletedHandler_Invoke() below to be executed Return 0 ; S_OK = 0x00000000 #forceref $pSelf, $long EndFunc ; Copied from WV2Interfaces.au3 ; Executed as a consequence of $oCoreWebView2Environment.CreateCoreWebView2Controller() above Func CoreWebView2CreateCoreWebView2ControllerCompletedHandler_Invoke( $pSelf, $long, $ptr ) ; Ret: long Par: long;ptr* ConsoleWrite( "CoreWebView2CreateCoreWebView2ControllerCompletedHandler_Invoke" & @CRLF ) ; Create CoreWebView2Controller object $oCoreWebView2Controller = ObjCreateInterface( $ptr, $sIID_ICoreWebView2Controller, $dtag_ICoreWebView2Controller ) ConsoleWrite( "IsObj( $oCoreWebView2Controller ) = " & IsObj( $oCoreWebView2Controller ) & @CRLF ) $oCoreWebView2Controller.AddRef() ; Prevent the object from being deleted when the function ends ; Set bounds for the CoreWebView2 object Local $tRect = _WinAPI_GetClientRect( $hGui ) $oCoreWebView2Controller.put_Bounds( $tRect ) ; Create CoreWebView2 object $oCoreWebView2Controller.get_CoreWebView2( $pCoreWebView2 ) $oCoreWebView2 = ObjCreateInterface( $pCoreWebView2, $sIID_ICoreWebView2, $dtag_ICoreWebView2 ) ConsoleWrite( "IsObj( $oCoreWebView2 ) = " & IsObj( $oCoreWebView2 ) & @CRLF & @CRLF ) ; Add NavigationStarting event handler Local $tEventRegistrationToken = DllStructCreate( "uint64" ) $oCoreWebView2.add_NavigationStarting( $pCoreWebView2NavigationStartingEventHandler, $tEventRegistrationToken ) ConsoleWrite( "DllStructGetData( $tEventRegistrationToken, 1 ) = " & DllStructGetData( $tEventRegistrationToken, 1 ) & @CRLF & @CRLF ) ; Forces CoreWebView2NavigationStartingEventHandler_Invoke() below to be executed ; Navigate to web page $oCoreWebView2.Navigate( "https://www.bing.com/" ) Return 0 ; S_OK = 0x00000000 #forceref $pSelf, $long EndFunc ; Copied from WV2Interfaces.au3 ; Executed as a consequence of $oCoreWebView2.add_NavigationStarting() above Func CoreWebView2NavigationStartingEventHandler_Invoke( $pSelf, $ptr1, $ptr2 ) ; Ret: long Par: ptr*;ptr* ConsoleWrite( "CoreWebView2NavigationStartingEventHandler_Invoke()" & @CRLF ) ; Create CoreWebView2NavigationStartingEventArgs object $oCoreWebView2NavigationStartingEventArgs = ObjCreateInterface( $ptr2, $sIID_ICoreWebView2NavigationStartingEventArgs, $dtag_ICoreWebView2NavigationStartingEventArgs ) ConsoleWrite( "IsObj( $oCoreWebView2NavigationStartingEventArgs ) = " & IsObj( $oCoreWebView2NavigationStartingEventArgs ) & @CRLF & @CRLF ) $oCoreWebView2NavigationStartingEventArgs.AddRef() ; Prevent the object from being deleted when the function ends ; Get navigation information Local $bIsUserInitiated, $bIsRedirected $oCoreWebView2NavigationStartingEventArgs.get_IsUserInitiated( $bIsUserInitiated ) $oCoreWebView2NavigationStartingEventArgs.get_IsRedirected( $bIsRedirected ) ; Confirm navigation If $bIsUserInitiated And Not $bIsRedirected Then Local $sUri $oCoreWebView2NavigationStartingEventArgs.get_Uri( $sUri ) If MsgBox( $MB_YESNO+$MB_ICONWARNING, "Navigation warning", "You are about to navigate to: " & $sUri & @CRLF & @CRLF & "Do you want to continue?" ) = $IDNO Then $oCoreWebView2NavigationStartingEventArgs.put_Cancel( True ) $oCoreWebView2.NavigateToString( "<h1>Navigation Canceled</h1><p>You chose to cancel navigation to the following URL: " & $sUri & "</p>" ) EndIf EndIf Return 0 ; S_OK = 0x00000000 #forceref $pSelf, $ptr1, $ptr2 EndFunc The code is translated to AutoIt from the C++ code in the Getting started example step 4, from the C++ code in ICoreWebView2.add_NavigationStarting() and from the AutoHotkey code in WebView2.ahk. In case of a CreateCoreWebView2EnvironmentWithOptions ERR in the SciTE console then the cause of the problem and the solution is described by Chimp in this post above. WebView2.h, HelloWebView.cpp and the three dll-files contained in the 7z-file are copied from the NuGet package needed to compile the C++ Getting started example. Examples: WebView2-1.au3: Getting started example step 3: WebView window WebView2-2.au3: Getting started example step 4: Navigation events (this example) WebView2-3.au3: AutoIt implementation of the AutoHotkey example WebView2-4.au3: Scripting example based on code by Chimp WebView2-5.au3: Getting started example step 5: Scripting WebView2-6.au3: Getting started example step 6: Communication (doesn't work) WebView2.7z1 point
-
Thank you @LarsJ for your suggestion I copied the dlls into the autoit path, but again without success, however I think I have found the reason for the problem: 1) after copying the 2 dll to the autoit path, the error kept occurring 2) I tried to set #RequireAdmin on the script and, at this point, the following new error window appeared: "Microsoft Edge cannot read and write to the data directory: C:\ Program Files (x86) \ AutoIt3 \ autoit3_x64.exe.WebView2 \ EBWebView" so the problem is that the AutoIt3 directory doesn't have write permission for local users. That's all. it is not necessary to copy the DLLs to a location other than the script path. my solution has been to set write/modify permissions to the AutoIt3 folder so to allow the script to create its own subfolder (on first run). Once the subfolder was created, I restored the previous permission to the AutoIt3 folder and allowed the write/modify permission only to the newly created autoit3_x64.exe.WebView2 folder This way everything works fine (... so far ...) Thanks again for your tips P.S. @LarsJ This WebView2 script you wrote is elite. I tried to study it and I see that you have for example also used portions of code (Func ObjectFromTag) that I had already seen (with awe) created by the queen of developers @trancexx in this other post. But, now as then I must give up trying to understand. This type of code intimidates me, too complex for my poor understanding of the inner workings of Windows. However I like to see powerful code like this appear on the forum thanks to programmers, like you and many others, who master these intricacies with great ease. Thanks again1 point
-
Getting started example step 3: WebView window First AutoIt implementation. Tested on Windows 10/7, 32/64 bit. Execute WebView2.au3: #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 <WindowsConstants.au3> #include <GUIConstantsEx.au3> #include <WinAPICom.au3> #include <WinAPI.au3> Global $hGui, $oCoreWebView2Environment, $oCoreWebView2Controller #include "..\Includes\WV2Interfaces.au3" WebView2() Func WebView2() $hGui = GUICreate( "WebView2 Sample", 1200, 900, -1, -1, $WS_OVERLAPPEDWINDOW ) _WinAPI_CoInitialize( $COINIT_APARTMENTTHREADED ) CoreWebView2CreateCoreWebView2EnvironmentCompletedHandlerCreate() ConsoleWrite( "$pCoreWebView2CreateCoreWebView2EnvironmentCompletedHandler = " & $pCoreWebView2CreateCoreWebView2EnvironmentCompletedHandler & @CRLF & @CRLF ) CoreWebView2CreateCoreWebView2ControllerCompletedHandlerCreate() ConsoleWrite( "$pCoreWebView2CreateCoreWebView2ControllerCompletedHandler = " & $pCoreWebView2CreateCoreWebView2ControllerCompletedHandler & @CRLF & @CRLF ) Local $hWebView2Loader = DllOpen( @AutoItX64 ? "WebView2Loader-x64.dll" : "WebView2Loader-x86.dll" ) Local $aRet = DllCall( $hWebView2Loader, "long", "CreateCoreWebView2EnvironmentWithOptions", "wstr", "", "wstr", "", _ "ptr", NULL, "ptr", $pCoreWebView2CreateCoreWebView2EnvironmentCompletedHandler ) If @error Or $aRet[0] Then Return ConsoleWrite( "CreateCoreWebView2EnvironmentWithOptions ERR" & @CRLF ) ConsoleWrite( "CreateCoreWebView2EnvironmentWithOptions OK" & @CRLF & @CRLF ) GUISetState( @SW_SHOW ) While 1 Switch GUIGetMsg() Case $GUI_EVENT_MAXIMIZE, $GUI_EVENT_RESIZED Local $tRect = _WinAPI_GetClientRect( $hGui ) $oCoreWebView2Controller.put_Bounds( $tRect ) Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd CoreWebView2CreateCoreWebView2ControllerCompletedHandlerDelete() CoreWebView2CreateCoreWebView2EnvironmentCompletedHandlerDelete() DllClose( $hWebView2Loader ) EndFunc Func CoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_Invoke( $pSelf, $long, $ptr ) ; Ret: long Par: long;ptr* ConsoleWrite( "CoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_Invoke" & @CRLF ) $oCoreWebView2Environment = ObjCreateInterface( $ptr, $sIID_ICoreWebView2Environment, $dtag_ICoreWebView2Environment ) ConsoleWrite( "IsObj( $oCoreWebView2Environment ) = " & IsObj( $oCoreWebView2Environment ) & @CRLF & @CRLF ) $oCoreWebView2Environment.CreateCoreWebView2Controller( $hGui, $pCoreWebView2CreateCoreWebView2ControllerCompletedHandler ) Return 0 #forceref $pSelf, $long EndFunc Func CoreWebView2CreateCoreWebView2ControllerCompletedHandler_Invoke( $pSelf, $long, $ptr ) ; Ret: long Par: long;ptr* ConsoleWrite( "CoreWebView2CreateCoreWebView2ControllerCompletedHandler_Invoke" & @CRLF ) $oCoreWebView2Controller = ObjCreateInterface( $ptr, $sIID_ICoreWebView2Controller, $dtag_ICoreWebView2Controller ) ConsoleWrite( "IsObj( $oCoreWebView2Controller ) = " & IsObj( $oCoreWebView2Controller ) & @CRLF ) $oCoreWebView2Controller.AddRef() $oCoreWebView2Controller.get_CoreWebView2( $pCoreWebView2 ) $oCoreWebView2 = ObjCreateInterface( $pCoreWebView2, $sIID_ICoreWebView2, $dtag_ICoreWebView2 ) ConsoleWrite( "IsObj( $oCoreWebView2 ) = " & IsObj( $oCoreWebView2 ) & @CRLF & @CRLF ) Local $tRect = _WinAPI_GetClientRect( $hGui ) $oCoreWebView2Controller.put_Bounds( $tRect ) $oCoreWebView2.Navigate( "https://www.bing.com/" ) Return 0 #forceref $pSelf, $long EndFunc The code is translated to AutoIt from the C++ code in the Getting started example step 3 and from the AutoHotkey code in WebView2.ahk. A slightly updated example is included in WebView2-1.au3 in the 7z-file at bottom of this post.1 point
-
A Non-Strict JSON UDF (JSMN)
Gianni reacted to argumentum for a topic
Thanks much for your code. I touch up your code to work with the new UDF. #include "JSON.au3" #include <file.au3> Local $filelist = _FileListToArray(@ScriptDir, "*.json") Local $i, $json, $obj For $i = 1 To $filelist[0] ConsoleWrite("-----------" & $filelist[$i] & "----------------" & @CRLF) $json = FileRead($filelist[$i]) $obj = Json_Decode($json) Json_Iterate($obj, '', $filelist[$i]) Next Func Json_Iterate($obj, $string, $pre = "") Local $temp, $i, $b If ($pre <> "") Then ConsoleWrite($pre & ": ") $a = Json_Get_ShowResult($obj, $string) If IsArray($a) Then For $i = 0 To UBound($a) - 1 Json_Iterate($obj, $string & '[' & $i & ']', $pre) Next ElseIf IsObj($a) Then $b = Json_ObjGetKeys($a) For $temp In $b Json_Iterate($obj, $string & '["' & $temp & '"]', $pre) Next EndIf Return EndFunc ;==>Json_Iterate Func Json_Get_ShowResult($Var, $Key) Local $Ret = Json_Getr($Var, $Key) If @error Then Switch @error Case 1 ConsoleWrite("Error 1: key not exists" & @LF) Case 2 ConsoleWrite("Error 2: syntax error" & @LF) EndSwitch Else ConsoleWrite($Key & " => " & VarGetType($Ret) & ": " & $Ret & @LF) EndIf Return $Ret EndFunc ;==>Json_Get_ShowResult Func Json_Getr($Var, $Key) If Not $Key Then Return $Var Local $Match = StringRegExp($Key, "(^\[([^\]]+)\])", 3) If IsArray($Match) Then Local $Index = Json_Decode($Match[1]) $Key = StringTrimLeft($Key, StringLen($Match[0])) If IsString($Index) And Json_IsObject($Var) And Json_ObjExists($Var, $Index) Then Local $Ret = Json_Getr(Json_ObjGet($Var, $Index), $Key) Return SetError(@error, 0, $Ret) ElseIf IsNumber($Index) And IsArray($Var) And $Index >= 0 And $Index < UBound($Var) Then Local $Ret = Json_Getr($Var[$Index], $Key) Return SetError(@error, 0, $Ret) Else Return SetError(1, 0, "") EndIf EndIf Return SetError(2, 0, "") EndFunc ;==>Json_Getr So my problem is solved.1 point -
Try this: #include <GDIPlus.au3> _GDIPlus_Startup() ConsoleWrite(_GDIPlus_ConvertImage("C:\Temp\Test.jpg", "C:\Temp\Converted.jpg", 10) & " / " & @error & @LF) ConsoleWrite(_GDIPlus_ConvertImage("C:\Temp\Test.jpg", "C:\Temp\Converted.png") & " / " & @error & @LF) ConsoleWrite(_GDIPlus_ConvertImage("C:\Temp\Test.jpg", "C:\Temp\Converted.bmp") & " / " & @error & @LF) ConsoleWrite(_GDIPlus_ConvertImage("C:\Temp\Test.jpg", "C:\Temp\Converted.gif") & " / " & @error & @LF) _GDIPlus_Shutdown() Exit ; #FUNCTION# ==================================================================================================================== ; Name ..........: _GDIPlus_ConvertImage ; Version .......: v0.90 build 2013-02-14 ; Description ...: Converts an image from one of these format to another (JPG, PNG, BMP, GIF, TIF) ; Syntax ........: _GDIPlus_ConvertImage($sIn, $sOut[, $iQuality = 90[, $iBGColor = 0x000000]]) ; Parameters ....: $sIn - image file to load ; $sOut - output file name, extension must be given (JPG, PNG, BMP, GIF, TIF) ; $iQuality - [optional] JPG quality settings. Default is 90. ; $iBGColor - [optional] background color. Default is 0x000000. Needed for transparent images when background color shouldn't be black ; Return values .: 1 ; on error: ; 1 image file to load not found ; 2 GDI+ not initialized -> _GDIPlus_Startup() ; 3 unable to create bitmap from file ; 4 output image format not given ; 5 unable to save output JPG image ; 6 unable to save output image (BMP, PNG, GIF, TIF) ; Author ........: UEZ ; Modified ......: ; Remarks .......: GDIPlus.au3 needs to be included ; Related .......: GDI+ ; Link ..........: ; Example .......: No ; =============================================================================================================================== Func _GDIPlus_ConvertImage($sIn, $sOut, $iQuality = 90, $iBGColor = 0x000000) If Not FileExists($sIn) Then Return SetError(1, 0, 0) If Not $giGDIPToken Then Return SetError(2, 0, 0) Local $hBitmap = _GDIPlus_BitmapCreateFromFile($sIn) If @error Then Return SetError(3, 0, 0) If Int($iQuality) < 0 Or Int($iQuality) > 100 Then $iQuality = 90 If $iBGColor Then Local $iW = _GDIPlus_ImageGetWidth($hBitmap), $iH = _GDIPlus_ImageGetHeight($hBitmap) Local $aResult = DllCall($ghGDIPDll, "uint", "GdipCreateBitmapFromScan0", "int", $iW, "int", $iH, "int", 0, "int", $GDIP_PXF32ARGB, "ptr", 0, "int*", 0) Local $hCtxt = _GDIPlus_ImageGetGraphicsContext($aResult[6]) _GDIPlus_GraphicsClear($hCtxt, 0xFF000000 + $iBGColor) _GDIPlus_GraphicsDrawImageRect($hCtxt, $hBitmap, 0, 0, $iW, $iH) _GDIPlus_GraphicsDispose($hCtxt) _GDIPlus_BitmapDispose($hBitmap) $hBitmap = $aResult[6] EndIf Local $iResult, $sSuffix = StringRight($sOut, 4), $iErr = 0 Switch $sSuffix Case ".jpg" Local $sCLSID = _GDIPlus_EncodersGetCLSID("JPG") Local $tParams = _GDIPlus_ParamInit(1) Local $tData = DllStructCreate("int Quality") DllStructSetData($tData, "Quality", $iQuality) _GDIPlus_ParamAdd($tParams, $GDIP_EPGQUALITY, 1, $GDIP_EPTLONG, DllStructGetPtr($tData)) _GDIPlus_ImageSaveToFileEx($hBitmap, $sOut, $sCLSID, DllStructGetPtr($tParams)) If @error Then $iErr = 5 Case ".bmp", ".gif", ".png", ".tif" _GDIPlus_ImageSaveToFile($hBitmap, $sOut) If @error Then $iErr = 6 Case Else $iErr = 4 EndSwitch _GDIPlus_BitmapDispose($hBitmap) $tParams = 0 $tData = 0 If $iErr Then Return SetError($iErr, 0, 0) Return 1 EndFunc Br, UEZ1 point