Jump to content

Gianni

MVPs
  • Posts

    2,710
  • Joined

  • Last visited

  • Days Won

    41

Gianni last won the day on September 25

Gianni had the most liked content!

About Gianni

  • Birthday 05/02/1962

Profile Information

  • Location
    Italy

Recent Profile Visitors

8,186 profile views

Gianni's Achievements

  1. Hi @Numeric1, thanks for the clarification. I believe the decision to route events through a queue is a sound and prudent design choice, aimed at ensuring maximum stability and preventing potential reentrancy issues. This approach provides a clear separation between WebView2’s internal callback mechanism and the application’s event-processing logic, resulting in a more controlled and predictable execution model. However, this level of protection also introduces a certain degree of rigidity. By preventing application code from executing directly within the callbacks, the implementation limits the flexibility that developers might sometimes require, especially when immediate event handling is necessary or preferred. A useful compromise would be to keep the queue-based mechanism as the default, security-oriented approach, while simultaneously offering an option for direct handling via callbacks. Since WebView2 callbacks are executed serially on the same Single-Threaded Apartment (STA) thread, direct handling is neither inherently unsafe nor prohibited. This would accommodate developers who, fully aware of the implications, can ensure that the execution of their callbacks does not trigger nested message loops or unsafe reentrant operations. In this way, it would be possible to combine the robustness of the current approach with the flexibility of a more direct event-handling model.
  2. Hi @Numeric1, What puzzles me about this UDF is the entire mechanism used to handle events. As I understand it, you have implemented a background system that, "under the hood," keeps track of all the events one has subscribed to; the user, in turn, queries this queue (via `_WaitForEvent()`, `_HandleEvent()`, etc.) to check whether an event has occurred. Or am I mistaken? If that is the case, doesn't this approach end up "complicating" the native concept of an event—where, typically, a specific function is associated with an event and then automatically invoked whenever that event occurs? Please correct me if I have misunderstood how events are used in this UDF.
  3. Hi @Numeric1, thanks for the clarifications. For example, I want to subscribe to the "add_IsDocumentPlayingAudioChanged" event of the "ICoreWebView2_8" interface; then, within the callback function, I update a "Label" to display either "no audio" or "audio playing," depending on the situation. Typically, I would simply subscribe to the "add_IsDocumentPlayingAudioChanged" event and not have to worry about it further—whenever the audio state in the browser changes, my callback function is invoked, allowing me to update the "Label" with the appropriate message.
  4. Hi @Numeric1, Excellent UDF: it’s lightweight and easy to get started with. Looking at it briefly, there are two aspects that aren't entirely clear to me. If I’m not mistaken, are we limited to using only the WebView2 functions already provided within the available wrappers? Also—correct me if I’m wrong—it doesn’t seem to support custom callback functions, neither for events nor for asynchronous methods. In effect—unless I’ve misunderstood something—it appears that events must be constantly "polled" to check for their outcome. Again, please correct me if I’ve misunderstood, or is this a deliberate design choice on your part? This isn't a criticism, just a request for clarification. Thanks again for sharing. Cheers
  5. I’ve uploaded a new version to the first post with a few minor improvements—mainly regarding the array draft preview display—along with other small changes. P.S. Thanks for the "likes" and the comment.
  6. A simple _MAPdisplay() function: displays the contents of a MAP variable in a TreeView handles nested MAPs if a MAP key contains an array (1D or 2D), it displays the contents in a draft form If an array element contains a sub-MAP, a sub-array or other "non printable" variables, it is indicated the VarType but not recursively expanded. I’ve uploaded a new version with some minor improvements, primarily regarding the preview display of the array draft. The layout is as follows: on the left side of the list, enclosed in square brackets, is the key name; on the right side is the key's content. The two elements are separated by a colon. If the key's content is a MAP, an Array, or a variable type that cannot be printed directly, it is indicated by a placeholder enclosed in curly braces. For MAPs or Arrays, you need to expand the corresponding TreeView item to view the content. I hope it is bug-free and proves useful. Any reports of errors or suggestions for improvements are welcome. Cheers and enjoy! P.S. The MAP used in the example is quite complex and likely unusual, but I intentionally designed it that way to stress-test the function. This is the UDF. Below there is a second script with example #include <TreeViewConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <Array.au3> ; #FUNCTION# ==================================================================================================================== ; Name ..........: _MapDisplay ; Description ...: Displays the content of a MAP variable ; Syntax ........: _MapDisplay($mMAP) ; Parameters ....: $mMAP - a variable of type MAP ; Return values .: None ; Author ........: Gianni Addiego ; Modified ......: ; Remarks .......: v 1.0 ; Related .......: ; Link ..........: ; Example .......: ; =============================================================================================================================== Func _MapDisplay(ByRef $mMain, $bPseudoParent = False) If Not IsMap($mMain) Then Return SetError(1, 0, '') ; Create and show the GUI Local $hGUI = GUICreate("Map Display", 850, 550) Local $idTreeView = GUICtrlCreateTreeView(10, 10, 830, 530, $TVS_HASBUTTONS + $TVS_HASLINES + $TVS_LINESATROOT, $WS_EX_CLIENTEDGE) GUICtrlSetFont($idTreeView, 8.5, 0, 0, "Courier New") GUISetState(@SW_SHOW) If $bPseudoParent Then ; (virtual root) Local $__mPseudoRoot[] $__mPseudoRoot['Root'] = $mMain _MapToTreeView($__mPseudoRoot, $idTreeView) Else _MapToTreeView($mMain, $idTreeView) EndIf ; Waiting loop Do Until GUIGetMsg() = $GUI_EVENT_CLOSE GUIDelete($hGUI) $idTreeView = 0 Return EndFunc ;==>_MapDisplay ; Ebhanced recursive function Func _MapToTreeView(ByRef $map, $idParent) Local $aKeys = MapKeys($map) Local $key, $value, $idNewParentNode Local $iDimensions, $idNodeArray1D, $idNodeArray2D Local $iRows, $iColumns, $sRowText, $vCheckType, $sArrayHeader, $aArrayFormatted Local $iColWidth = 10 If UBound($aKeys) = 0 Then ; Is an empty MAP $idNewParentNode = GUICtrlCreateTreeViewItem("{empty}", $idParent) Return EndIf For $i = 0 To UBound($aKeys) - 1 $key = $aKeys[$i] $value = $map[$key] ; --- Nested MAP If IsMap($value) Then $idNewParentNode = GUICtrlCreateTreeViewItem("[" & $key & "]: (MAP)", $idParent) _MapToTreeView($value, $idNewParentNode) ; --- Array (1D or 2D) ElseIf IsArray($value) Then ; Check the number of array dimensions $iDimensions = UBound($value, $UBOUND_DIMENSIONS) $idNodeArray = GUICtrlCreateTreeViewItem("[" & $key & "]: (" & $iDimensions & "D ARRAY)", $idParent) If $iDimensions < 3 Then $aArrayFormatted = _FormatArrayToColumns($value, $iColWidth) $sArrayHeader = StringFormat("%-" & StringLen(UBound($aArrayFormatted) - 1) + 4 & "s", "Row") For $c = 0 To UBound($value, $UBOUND_COLUMNS) - 1 $sArrayHeader &= StringFormat("%-" & $iColWidth + 3 & "s", "Col" & $c) Next If UBound($aArrayFormatted, 1) Then GUICtrlCreateTreeViewItem($sArrayHeader, $idNodeArray) For $ii = 0 To UBound($aArrayFormatted) - 1 GUICtrlCreateTreeViewItem("#" & StringFormat("%" & StringLen(UBound($aArrayFormatted) - 1) & "s", $ii) & " : " & $aArrayFormatted[$ii], $idNodeArray) Next Else GUICtrlCreateTreeViewItem("{empty}", $idNodeArray) EndIf Else ; --- MultiD Array ; Arrays with 3 or more dimensions (uncommon, showing a warning only) $sMsg = "Preview unsupported for " & $iDimensions & "D array. Subscripts: -> " For $s = 1 To $iDimensions $sMsg &= "[" & UBound($value, $s) & "]" Next GUICtrlCreateTreeViewItem($sMsg, $idNodeArray) ; MultiD Arrays Unsupported EndIf Else ; --- Standalone value $vCheckType = IsArray($value) ? '{Array}' _ : IsMap($value) ? '{MAP}' _ : IsObj($value) ? '{Object}' _ : IsDllStruct($value) ? '{DLLStruct}' _ : IsFunc($value) ? '{Function}' _ : ((Not IsBool($value)) And ($value = "")) ? '{empty}' _ : $value GUICtrlCreateTreeViewItem("[" & $key & "]: " & $vCheckType, $idParent) EndIf Next EndFunc ;==>_MapToTreeView ; Minimalist clone of _ArrayDisplay Func _FormatArrayToColumns(Const ByRef $aInput, $iColWidth, $bAlignLeft = True) Local $iDims, $iRows, $iCols, $sCellText, $sRowText, $sFormat ; check if is array If Not IsArray($aInput) Then Return SetError(1, 0, 0) $iDims = UBound($aInput, 0) ; array dimensions $iRows = UBound($aInput, 1) Local $aOutput[$iRows] $sFormat = "%-" & ($iDims = 1 ? '' : $iColWidth & ".") & $iColWidth & "s" ; Left align (default) If Not $bAlignLeft Then $sFormat = "%" & ($iDims = 1 ? '' : $iColWidth & ".") & $iColWidth & "s" ; Right align EndIf If Not $iRows Then Return $aOutput EndIf ; Array rows loop For $i = 0 To $iRows - 1 $sRowText = "" If $iDims = 1 Then ; Array 1D $sRowText = StringFormat($sFormat, String(IsArray($aInput[$i]) ? '{Array}' _ : IsMap($aInput[$i]) ? '{MAP}' _ : IsObj($aInput[$i]) ? '{Object}' _ : IsDllStruct($aInput[$i]) ? '{DLLStruct}' _ : IsFunc($aInput[$i]) ? '{Function}' _ : $aInput[$i])) ElseIf $iDims = 2 Then ; Array 2D $iCols = UBound($aInput, 2) For $j = 0 To $iCols - 1 $sCellText = StringFormat($sFormat, String(IsArray($aInput[$i][$j]) ? '{Array}' _ : IsMap($aInput[$i][$j]) ? '{MAP}' _ : IsObj($aInput[$i][$j]) ? '{Object}' _ : IsDllStruct($aInput[$i][$j]) ? '{DLLStruct}' _ : IsFunc($aInput[$i][$j]) ? '{Function}' _ : $aInput[$i][$j])) $sRowText &= StringLen($aInput[$i][$j]) > $iColWidth ? $sCellText & '>| ' : $sCellText & " | " Next EndIf $aOutput[$i] = $sRowText Next Return $aOutput EndFunc ;==>_FormatArrayToColumns This second script contains the UDF and an example that generates a rather complex map and displays it. #include <TreeViewConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <Array.au3> ; #FUNCTION# ==================================================================================================================== ; Name ..........: _MapDisplay ; Description ...: Displays the content of a MAP variable ; Syntax ........: _MapDisplay($mMAP) ; Parameters ....: $mMAP - a variable of type MAP ; Return values .: None ; Author ........: Gianni Addiego ; Modified ......: ; Remarks .......: v 1.0 ; Related .......: ; Link ..........: ; Example .......: ; =============================================================================================================================== Func _MapDisplay(ByRef $mMain, $bPseudoParent = False) If Not IsMap($mMain) Then Return SetError(1, 0, '') ; Create and show the GUI Local $hGUI = GUICreate("Map Display", 850, 550) Local $idTreeView = GUICtrlCreateTreeView(10, 10, 830, 530, $TVS_HASBUTTONS + $TVS_HASLINES + $TVS_LINESATROOT, $WS_EX_CLIENTEDGE) GUICtrlSetFont($idTreeView, 8.5, 0, 0, "Courier New") GUISetState(@SW_SHOW) If $bPseudoParent Then ; (virtual root) Local $__mPseudoRoot[] $__mPseudoRoot['Root'] = $mMain _MapToTreeView($__mPseudoRoot, $idTreeView) Else _MapToTreeView($mMain, $idTreeView) EndIf ; Waiting loop Do Until GUIGetMsg() = $GUI_EVENT_CLOSE GUIDelete($hGUI) $idTreeView = 0 Return EndFunc ;==>_MapDisplay ; Ebhanced recursive function Func _MapToTreeView(ByRef $map, $idParent) Local $aKeys = MapKeys($map) Local $key, $value, $idNewParentNode Local $iDimensions, $idNodeArray1D, $idNodeArray2D Local $iRows, $iColumns, $sRowText, $vCheckType, $sArrayHeader, $aArrayFormatted Local $iColWidth = 10 If UBound($aKeys) = 0 Then ; Is an empty MAP $idNewParentNode = GUICtrlCreateTreeViewItem("{empty}", $idParent) Return EndIf For $i = 0 To UBound($aKeys) - 1 $key = $aKeys[$i] $value = $map[$key] ; --- Nested MAP If IsMap($value) Then $idNewParentNode = GUICtrlCreateTreeViewItem("[" & $key & "]: (MAP)", $idParent) _MapToTreeView($value, $idNewParentNode) ; --- Array (1D or 2D) ElseIf IsArray($value) Then ; Check the number of array dimensions $iDimensions = UBound($value, $UBOUND_DIMENSIONS) $idNodeArray = GUICtrlCreateTreeViewItem("[" & $key & "]: (" & $iDimensions & "D ARRAY)", $idParent) If $iDimensions < 3 Then $aArrayFormatted = _FormatArrayToColumns($value, $iColWidth) $sArrayHeader = StringFormat("%-" & StringLen(UBound($aArrayFormatted) - 1) + 4 & "s", "Row") For $c = 0 To UBound($value, $UBOUND_COLUMNS) - 1 $sArrayHeader &= StringFormat("%-" & $iColWidth + 3 & "s", "Col" & $c) Next If UBound($aArrayFormatted, 1) Then GUICtrlCreateTreeViewItem($sArrayHeader, $idNodeArray) For $ii = 0 To UBound($aArrayFormatted) - 1 GUICtrlCreateTreeViewItem("#" & StringFormat("%" & StringLen(UBound($aArrayFormatted) - 1) & "s", $ii) & " : " & $aArrayFormatted[$ii], $idNodeArray) Next Else GUICtrlCreateTreeViewItem("{empty}", $idNodeArray) EndIf Else ; --- MultiD Array ; Arrays with 3 or more dimensions (uncommon, showing a warning only) $sMsg = "Preview unsupported for " & $iDimensions & "D array. Subscripts: -> " For $s = 1 To $iDimensions $sMsg &= "[" & UBound($value, $s) & "]" Next GUICtrlCreateTreeViewItem($sMsg, $idNodeArray) ; MultiD Arrays Unsupported EndIf Else ; --- Standalone value $vCheckType = IsArray($value) ? '{Array}' _ : IsMap($value) ? '{MAP}' _ : IsObj($value) ? '{Object}' _ : IsDllStruct($value) ? '{DLLStruct}' _ : IsFunc($value) ? '{Function}' _ : ((Not IsBool($value)) And ($value = "")) ? '{empty}' _ : $value GUICtrlCreateTreeViewItem("[" & $key & "]: " & $vCheckType, $idParent) EndIf Next EndFunc ;==>_MapToTreeView ; Minimalist clone of _ArrayDisplay Func _FormatArrayToColumns(Const ByRef $aInput, $iColWidth, $bAlignLeft = True) Local $iDims, $iRows, $iCols, $sCellText, $sRowText, $sFormat ; check if is array If Not IsArray($aInput) Then Return SetError(1, 0, 0) $iDims = UBound($aInput, 0) ; array dimensions $iRows = UBound($aInput, 1) Local $aOutput[$iRows] $sFormat = "%-" & ($iDims = 1 ? '' : $iColWidth & ".") & $iColWidth & "s" ; Left align (default) If Not $bAlignLeft Then $sFormat = "%" & ($iDims = 1 ? '' : $iColWidth & ".") & $iColWidth & "s" ; Right align EndIf If Not $iRows Then Return $aOutput EndIf ; Array rows loop For $i = 0 To $iRows - 1 $sRowText = "" If $iDims = 1 Then ; Array 1D $sRowText = StringFormat($sFormat, String(IsArray($aInput[$i]) ? '{Array}' _ : IsMap($aInput[$i]) ? '{MAP}' _ : IsObj($aInput[$i]) ? '{Object}' _ : IsDllStruct($aInput[$i]) ? '{DLLStruct}' _ : IsFunc($aInput[$i]) ? '{Function}' _ : $aInput[$i])) ElseIf $iDims = 2 Then ; Array 2D $iCols = UBound($aInput, 2) For $j = 0 To $iCols - 1 $sCellText = StringFormat($sFormat, String(IsArray($aInput[$i][$j]) ? '{Array}' _ : IsMap($aInput[$i][$j]) ? '{MAP}' _ : IsObj($aInput[$i][$j]) ? '{Object}' _ : IsDllStruct($aInput[$i][$j]) ? '{DLLStruct}' _ : IsFunc($aInput[$i][$j]) ? '{Function}' _ : $aInput[$i][$j])) $sRowText &= StringLen($aInput[$i][$j]) > $iColWidth ? $sCellText & '>| ' : $sCellText & " | " Next EndIf $aOutput[$i] = $sRowText Next Return $aOutput EndFunc ;==>_FormatArrayToColumns ; ----- Example zone ----- #include <date.au3> #include <InetConstants.au3> ; The functions Example1 and Example2 simply generate a rather complex MAP. ; Returned MAP is displayed by the _MapDisplay() function. _MapDisplay(Example2()) ; _MapDisplay(Example1()) Func Example1() ; --- Example 1 --- ; Create a MAP containing nested MAPs ; Read a file CSV containing european States, Regions, Provinces ; Read the file directly to a variable without saving it to a local file. Local $dData = InetRead("https://gisco-services.ec.europa.eu/distribution/v2/nuts/csv/NUTS_AT_2024.csv", BitAND($INET_FORCERELOAD, $INET_BINARYTRANSFER)) ; Convert the ANSI compatible binary string back into a string. Local $sData = BinaryToString($dData, $SB_UTF8) ; $SB_UTF8 (4) = binary data is UTF8 Local $a2D = _StringToArray2D($sData, ',') ; convert a CSV into a two-dimensional array ; _ArrayDisplay($a2D) Local $mContinents[] ; only Europe in this context Local $mCountries[] Local $mRegions[] ; Local $mProvinces[] Local $mMAP[] ; an empty MAP For $i = 1 To UBound($a2D) - 1 $a2D[$i][4] = StringLen($a2D[$i][1]) & $a2D[$i][2] $a2D[$i][5] = StringLeft($a2D[$i][1], 4) Next _ArraySort($a2D, 0, 1, 0, 4) ; create a nested MAP : Continents -> Countries -> Regions -> Provinces $mContinents['Europe'] = $mMAP ; first submap For $i = 1 To UBound($a2D) - 1 Switch StringLen($a2D[$i][1]) Case 2 ; State code $mContinents["Europe"][$a2D[$i][2]] = $mMAP $mCountries[$a2D[$i][1]] = $a2D[$i][2] ; <- populate the map of Countries Case 4 ; Region code $mRegions[$a2D[$i][1]] = $a2D[$i][2] ; <- populate the map of Regions ; We place the region within the map of its State $mContinents["Europe"][$mCountries[$a2D[$i][0]]][$a2D[$i][2]] = $mMAP Case 5 ; Province code ; We place the Province within the map of its Region $mContinents["Europe"][$mCountries[$a2D[$i][0]]][$mRegions[$a2D[$i][5]]][$a2D[$i][2]] = "" ; the last leaf on the branch EndSwitch Next Return $mContinents EndFunc ;==>Example1 ; --- Example 2 --- Func Example2() ; Create a MAP containing a nested MAP containing Arrays Local $mMyMAP[], $mMAP[] $mMyMAP["FirsKey"] = "Simple String" $mMyMAP["SecondKey"] = 150 ; a number $mMyMAP["Calendar"] = $mMAP ; Local $iYear = @YEAR For $iYear = @YEAR To @YEAR + 4 $mMyMAP["Calendar"][$iYear] = $mMAP ; Key "Calendar" subKey 2026 contains another empty MAP For $i = 1 To 12 ; Populate the 2026 map with 12 keys each named as a month. $mMyMAP["Calendar"][$iYear][_DateToMonth($i)] = _GenerateMonth($iYear, $i) ; <- Each 2D array contains the calendar for that month. ; _ArrayDisplay($mMyMAP["Calendar"][$iYear][_DateToMonth($i)]) ; Debug Next Next ; Add some 1D and 2D arrays to the MAP Local $aMonths[12] = [ _ "January", "February", "March", "April", _ "May", "June", "July", "August", _ "September", "October", "November", "December" _ ] $mMyMAP["Months"] = $aMonths Local $aMonthsMultiLang = [ _ ["English", "Italiano", "Español", "Français", "Deutsch", "Português", "Nederlands", "Polski"], _ ["January", "Gennaio", "Enero", "Janvier", "Januar", "Janeiro", "Januari", "Styczeń"], _ ["February", "Febbraio", "Febrero", "Février", "Februar", "Fevereiro", "Februari", "Luty"], _ ["March", "Marzo", "Marzo", "Mars", "März", "Março", "Maart", "Marzec"], _ ["April", "Aprile", "Abril", "Avril", "April", "Abril", "April", "Kwiecień"], _ ["May", "Maggio", "Mayo", "Mai", "Mai", "Maio", "Mei", "Maj"], _ ["June", "Giugno", "Junio", "Juin", "Juni", "Junho", "Juni", "Czerwiec"], _ ["July", "Luglio", "Julio", "Juillet", "Juli", "Julho", "Juli", "Lipiec"], _ ["August", "Agosto", "Agosto", "Août", "August", "Agosto", "Augustus", "Sierpień"], _ ["September", "Settembre", "Septiembre", "Septembre", "September", "Setembro", "September", "Wrzesień"], _ ["October", "Ottobre", "Octubre", "Octobre", "Oktober", "Outubro", "Oktober", "Październik"], _ ["November", "Novembre", "Noviembre", "Novembre", "November", "Novembro", "November", "Listopad"], _ ["December", "Dicembre", "Diciembre", "Décembre", "Dezember", "Dezembro", "December", "Grudzień"] _ ] $mMyMAP["MultiLangMonths"] = $aMonthsMultiLang Local $aZodiacSigns[12] = [ _ "Aries", "Taurus", "Gemini", "Cancer", _ "Leo", "Virgo", "Libra", "Scorpio", _ "Sagittarius", "Capricorn", "Aquarius", "Pisces" _ ] $mMyMAP["ZodiacSigns"] = $aZodiacSigns Local $aFamousScientists[6] = [ _ "Albert Einstein", "Isaac Newton", "Marie Curie", _ "Galileo Galilei", "Nikola Tesla", "Charles Darwin" _ ] $mMyMAP["Scientists"] = $aFamousScientists Local $aFamousPainters[6] = [ _ "Leonardo da Vinci", "Vincent van Gogh", "Pablo Picasso", _ "Claude Monet", "Michelangelo", "Rembrandt" _ ] $mMyMAP["Painters"] = $aFamousPainters Local $aFamousMusicians[6] = [ _ "Wolfgang Amadeus Mozart", "Ludwig van Beethoven", "Johann Sebastian Bach", _ "Frederic Chopin", "Pyotr Ilyich Tchaikovsky", "Jimi Hendrix" _ ] $mMyMAP["Musicians"] = $aFamousMusicians ; ------------------------------------- ; check for VarTypes output on TreeView ; ------------------------------------- ; Local $aArray[2] = [1, "Example"] Local $aArray[1][0][3][9][5] ; Exit MsgBox(0,'Debug',UBound($aArray,0) & @TAB & UBound($aArray,1) & @TAB & UBound($aArray,2)) Local $mMAP[] Local $dBinary = Binary("0x00204060A9FF003C") Local $bBoolean = False Local $pPtr = Ptr(-1) Local $hWnd = WinGetHandle(AutoItWinGetTitle()) Local $iInt = 1 Local $fFloat = 2.9 Local $oObject = ObjCreate("Scripting.Dictionary") Local $sString = "Some text" Local $tStruct = DllStructCreate("wchar[256]") Local $vKeyword = Default Local $fuFunc = ConsoleWrite Local $fuUserFunc = Example1 ; a 2D array containing also a sub array a MAP and other VarTypes ; Nested arrays, maps, and non-"printable" variables are enclosed in curly braces but not expanded. Local $aWorldCities = [["London", "New York", "Tokyo", $oObject], _ ["Rome", "Beijing", $aFamousPainters, "Moscow"], _ [MsgBox, "Munich", "Athens", "Lisbon"], _ [$mMAP, "Warsaw", "Prague", "Copenhagen"]] $mMyMAP["NestedArray"] = $aWorldCities $mMyMAP["VarTypes"] = $mMAP $mMyMAP["VarTypes"]["Array"] = $aArray $mMyMAP["VarTypes"]["Map"] = $mMAP $mMyMAP["VarTypes"]["Binary"] = $dBinary $mMyMAP["VarTypes"]["Boolean"] = $bBoolean $mMyMAP["VarTypes"]["Ptr"] = $pPtr $mMyMAP["VarTypes"]["Wnd"] = $hWnd $mMyMAP["VarTypes"]["Int"] = $iInt $mMyMAP["VarTypes"]["Float"] = $fFloat $mMyMAP["VarTypes"]["Object"] = $oObject $mMyMAP["VarTypes"]["String"] = $sString $mMyMAP["VarTypes"]["Struct"] = $tStruct $mMyMAP["VarTypes"]["Keyword"] = $vKeyword $mMyMAP["VarTypes"]["Func"] = MsgBox $mMyMAP["VarTypes"]["Func2"] = $fuFunc $mMyMAP["VarTypes"]["Func3"] = Example1 $mMyMAP["VarTypes"]["UserFunc"] = $fuUserFunc $mMyMAP["Geo"] = Example1() Return $mMyMAP EndFunc ;==>Example2 ; ======================== Func _StringToArray2D($sFile, $delim = ";") ; this function is extracted, adapted and slightly modified from the _FileReadToArray() function in file.au3 Local $aArray ; remove last line separator if any at the end of the file If StringRight($sFile, 1) = @LF Then $sFile = StringTrimRight($sFile, 1) If StringRight($sFile, 1) = @CR Then $sFile = StringTrimRight($sFile, 1) If StringInStr($sFile, @LF) Then $aArray = StringSplit(StringStripCR($sFile), @LF) ElseIf StringInStr($sFile, @CR) Then ;; @LF does not exist so split on the @CR $aArray = StringSplit($sFile, @CR) Else ;; unable to split the file If StringLen($sFile) Then Dim $aArray[2] = [1, $sFile] ; returns the whole file in one element Else Return SetError(2, 0, 0) ; File is empty EndIf EndIf ; now split 1D $aArray to 2D $aColumns according to delimiter Local $aColumns[$aArray[0]][1] ; create a new [2D] array with same nr. of lines of $aArray For $i = 1 To $aArray[0] ; scan all lines of the array $TempRow = StringSplit($aArray[$i], $delim, 2) ; split the line If UBound($TempRow) > UBound($aColumns, 2) Then ReDim $aColumns[$aArray[0]][UBound($TempRow)] For $ii = 0 To UBound($TempRow) - 1 $aColumns[$i - 1][$ii] = $TempRow[$ii] Next Next Return $aColumns EndFunc ;==>_StringToArray2D ;============================================== Func _GenerateMonth($iYear = @YEAR, $iMonth = @MON, $ISO = True) ; this function creates a month calendar into an 7x7 array Local $aMonth[7][7], $iDOW Local $iFirstDOW = $ISO ? _DateToDayOfWeekISO($iYear, $iMonth, 1) : _DateToDayOfWeek($iYear, $iMonth, 1) For $iDay = 1 To 7 $aMonth[0][$iDay - 1] = $ISO ? _DateDayOfWeek(Mod($iDay, 7) + $ISO, $DMW_LOCALE_SHORTNAME) : _DateDayOfWeek($iDay, $DMW_LOCALE_SHORTNAME) Next For $iDay = 1 To _DateDaysInMonth($iYear, $iMonth) $iDOW = $ISO ? _DateToDayOfWeekISO($iYear, $iMonth, $iDay) : _DateToDayOfWeek($iYear, $iMonth, $iDay) $aMonth[Int(($iFirstDOW + $iDay - 2) / 7) + 1][$iDOW - 1] = $iDay Next Return $aMonth EndFunc ;==>_GenerateMonth
  7. In SciTE select UTF-8 encoding to save the script, while to save the .ini file with Notepad, select UTF-16 LE encoding
  8. At the following link the "download" button seems to work: https://web.archive.org/web/20210724011512/http://www.thefoolonthehill.net/drupal/AutoIt Debugger
  9. Okay, thanks for the clarification, @MattyD. I'll keep your suggestion in mind. ... I also read some of your interesting topics while searching for a solution on the site. 👍 Bye and thanks again. 👋
  10. Wow! ... so the additional interfaces after the first aren't independent, but must all be chained together to form a larger interface that inherits all the methods of the previous interfaces... Enlightening! Thanks so much, DanyFirex, as always, you're a great help. You're fantastic! 👍
  11. Hello friends In this topic, @LarsJ explained how to implement COM callback interfaces, pointers, and objects. But I'm facing a problem I can't solve right now. The WebView2 component, used as the base product on which @LarsJ's examples are based, is constantly evolving, with new features added with new versions. These additions are made by adding new interfaces. For example, the ICoreWebView2 base interface, which was present when this post was written, has been joined by the ICoreWebView2_2, ICoreWebView2_3, and so on, currently up to ICoreWebView2_28. Well, the problem I'm having is: how can I use the methods of the new interfaces in addition to those in the base interface? For example, the ICoreWebView2_8 interface contains, among others, the get_IsMuted(), put_IsMuted(), get_IsDocumentPlayingAudio() methods, which I'd like to try using as a generic example. I've prepared and simplified one of the scripts from LarsJ's examples to create a lightweight script that hopefully someone brilliant can implement into a working example. To run the script without complications, you must first download the zip file available in first post and unzip it to a folder of your choice, as long as you have write permissions to that folder. Then save the script from this post to the Examples folder present in the unzipped folder and run it. There are two AutoIt buttons overlaying the WebView2 embedded in the page: the one on the left, as an example, uses the basic version of an ICoreWebView2Environment interface to check the installed WebView2 version, while the one on the right contains a snippet that currently doesn't work (lines 87-105) The basic objects: Environment, Controller, and WebView are already instantiated and implemented in the variables $oCoreWebView2Environment, $oCoreWebView2Controller, and $oCoreWebView2. The ICoreWebView2_8 interface declarations have also been inserted at the beginning of the script. The goal now is to make this interface usable. Searching the forum, I found a post by @Danyfirex (Get CLSID from IID - Developer General Discussion - AutoIt Forums) for a similar problem. It seems that the .QueryInterface method on $oCoreWebView2 needs to be used, but my attempts have been unsuccessful. I think the problem may be both in the way I'm trying to make the ICoreWebView2_8 interface operational, and in the type declarations in $dtag_ICoreWebView2_8 on line 19. Any help is welcome, and I thank in advance anyone who knows how to proceed. #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 ; Project includes #include "..\Includes\WV2Interfaces.au3" Global $dtag_ICoreWebView2Environment_mod = StringReplace($dtag_ICoreWebView2Environment, "get_BrowserVersionString hresult();", "get_BrowserVersionString hresult(wstr*);") ; == ICoreWebView2_8 Interface ==================================================== Global Const $sIID_ICoreWebView2_8 = "{E9632730-6E1E-43AB-B7B8-7B2C9E62E094}" Global Const $dtag_ICoreWebView2_8 = _ "add_IsMutedChanged hresult(ptr*;struct*);" & _ ; ICoreWebView2IsMutedChangedEventHandler *eventHandler, EventRegistrationToken *token "remove_IsMutedChanged hresult(struct);" & _ ; EventRegistrationToken token "get_IsMuted hresult(BOOL*);" & _ ; BOOL *value "put_IsMuted hresult(BOOL);" & _ ; BOOL value "add_IsDocumentPlayingAudioChanged hresult(ptr*;struct*);" & _ ; ICoreWebView2IsDocumentPlayingAudioChangedEventHandler *eventHandler, EventRegistrationToken *token "remove_IsDocumentPlayingAudioChanged hresult(struct);" & _ ; EventRegistrationToken token "get_IsDocumentPlayingAudio hresult(bool);" ; BOOL *value ?? (BOOL* or BOOL) Global $pICoreWebView2_8, $oCoreWebView2_8, $tICoreWebView2_8 Global $tRIID_ICoreWebView2_8 = _WinAPI_GUIDFromString($sIID_ICoreWebView2_8) #cs Global Const $ICoreWebView2_8_Prefix = "CoreWebView2_8_" $pICoreWebView2_8 = ObjectFromTag($ICoreWebView2_8_Prefix, $dtag_ICoreWebView2_8, $tICoreWebView2_8) #ce ; ================================================================================= WebView2() Func WebView2() ; Create WebView2 GUI $hGui = GUICreate("WebView2 Sample", 950, 600, -1, -1, $WS_OVERLAPPEDWINDOW) ; Create AutoIt controls Local $idButton1 = GUICtrlCreateButton("WebView2 version", 10, 150, 170, 40) Local $idButton2 = GUICtrlCreateButton("Test2", 190, 150, 170, 40) Local $idLabelResult = GUICtrlCreateLabel("", 370, 150, 170, 40) ; --- Initialize and embed WebView2 ---------- _WinAPI_CoInitialize($COINIT_APARTMENTTHREADED) CoreWebView2CreateCoreWebView2EnvironmentCompletedHandlerCreate(True) CoreWebView2CreateCoreWebView2ControllerCompletedHandlerCreate(True) Local $hWebView2Loader = DllOpen(@AutoItX64 ? "WebView2Loader-x64.dll" : "WebView2Loader-x86.dll") Local $aRet = DllCall($hWebView2Loader, "long", "CreateCoreWebView2EnvironmentWithOptions", "wstr", "", "wstr", @ScriptDir, _ "ptr", Null, "ptr", $pCoreWebView2CreateCoreWebView2EnvironmentCompletedHandler) If @error Or $aRet[0] Then Return ConsoleWrite("CreateCoreWebView2EnvironmentWithOptions ERR" & @CRLF) ; -------------------------------------------- ; after above initialization we have 3 main objects: ; $oCoreWebView2Environment ; $oCoreWebView2Controller ; $oCoreWebView2 ; Show WebView2 GUI GUISetState(@SW_SHOW) Local $vReturnedValue ; 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 $idButton1 ; I use a simple method from the basic "Environment" interface. GUICtrlSetData($idLabelResult, "") $oCoreWebView2Environment.get_BrowserVersionString($vReturnedValue) ; get a simple synchronous property MsgBox(0, '', "WebView2 Version is " & $vReturnedValue) GUICtrlSetData($idLabelResult, "current WebView2 Version is" & @CRLF & $vReturnedValue) Case $idButton2 ; attempting to use methods of a later version interface (ICoreWebView2_8) #cs From interface ICoreWebView2_8 I would like to test this 2 synchronous methods get_IsMuted() - audio status put_IsMuted() — toggle audio get_IsDocumentPlayingAudio() - Is Audio Playing? #ce ;#cs --- This attempt to use QueryInterface fails --- Local $peek Local $HRESULT $HRESULT = $oCoreWebView2.QueryInterface($tRIID_ICoreWebView2_8, $pICoreWebView2_8) ConsoleWrite('Debug: line ' & @ScriptLineNumber & ' @error: ' & @error & @TAB & _ '$HRESULT -> ' & VarGetType($HRESULT) & ' ' & $HRESULT & @TAB & _ '$pICoreWebView2_8 -> ' & VarGetType($pICoreWebView2_8) & ' ' & $pICoreWebView2_8 & @CRLF) $oCoreWebView2_8 = ObjCreateInterface($pICoreWebView2_8, $sIID_ICoreWebView2_8, $dtag_ICoreWebView2_8) ConsoleWrite('Debug: line ' & @ScriptLineNumber & ' @error: ' & @error & @TAB & _ '$oCoreWebView2_8 -> ' & VarGetType($oCoreWebView2_8) & ' ' & $oCoreWebView2_8 & @CRLF) $HRESULT = $oCoreWebView2_8.get_IsDocumentPlayingAudio($peek) ConsoleWrite('Debug: line ' & @ScriptLineNumber & ' @error: ' & @error & @TAB & _ '$HRESULT -> ' & VarGetType($HRESULT) & ' ' & $HRESULT & @TAB & _ '$Peek -> ' & VarGetType($peek) & ' ' & $peek & @CRLF) ;#ce MsgBox(32, '', "?? How do I use methods from the ICoreWebView2_8 interface " & _ "in relation to the WebView2 control referenced by the $oCoreWebView2 variable ??" & @CRLF & @CRLF & _ "Thanks") ; $oCoreWebView2.Navigate("https://learn.microsoft.com/en-us/microsoft-edge/webview2/reference/win32/icorewebview2_8") Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd ; Cleanup CoreWebView2CreateCoreWebView2ControllerCompletedHandlerDelete() CoreWebView2CreateCoreWebView2EnvironmentCompletedHandlerDelete() DllClose($hWebView2Loader) EndFunc ;==>WebView2 ; 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_mod) ConsoleWrite("IsObj( $oCoreWebView2Environment ) = " & IsObj($oCoreWebView2Environment) & @CRLF & @CRLF) $oCoreWebView2Environment.AddRef() ; 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 ;==>CoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_Invoke ; 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) ; Navigate to web page $oCoreWebView2.Navigate("https://www.youtube.com/watch?v=oSexfR0Ubzw") Return 0 ; S_OK = 0x00000000 #forceref $pSelf, $long EndFunc ;==>CoreWebView2CreateCoreWebView2ControllerCompletedHandler_Invoke ; -- Callback functions ----- Func CoreWebView2_8_QueryInterface($pSelf, $pRIID, $pObj) ; Ret: long Par: ptr;ptr* Return 0 ; S_OK = 0x00000000 #forceref $pSelf, $pRIID, $pObj EndFunc ;==>CoreWebView2_8_QueryInterface Func CoreWebView2_8_AddRef($pSelf) ; Ret: dword Return 1 ; For AddRef/Release #forceref $pSelf EndFunc ;==>CoreWebView2_8_AddRef Func CoreWebView2_8_Release($pSelf) ; Ret: dword Return 1 ; For AddRef/Release #forceref $pSelf EndFunc ;==>CoreWebView2_8_Release
  12. I recorded for about a minute just by pressing the Start button and without changing any settings, but when I open the file, the media player displays this message: "Cannot open Capture_..._... It's using unsupported encoding settings." (win11 x64) Am I doing something wrong?
  13. Animation file size: 57182968 bytes Dimension: 1920 x 1080 Frame count: 115 Duration: 10000 ms Estimated FPS: 11.5 GPU about 40% Intel(R) HD Graphics 530 Intel(R) Core(TM) i5-6500 CPU @ 3.20GHz (3.19 GHz)
  14. ... or also with two counters ... one of which is a little more "visual" #include <WindowsStylesConstants.au3> Func ViewCustomCmdsList() Local $hwnd = GUICreate("", 200, 30, -1, -1, $WS_POPUP) Local $hwPrg = GUICtrlCreateProgress(0, 0, 200, 30) GUISetState(@SW_SHOWNOACTIVATE, $hwnd) WinActivate($hSAWSTUDIO_MAIN) ; ----------------------------------------------- ; Select Custom Cmds button Sleep($iTimeOut) MouseClick($MOUSE_CLICK_LEFT, 250, 378, 1, 0) Sleep(1000) ; --------------------- ; Select each Cmd in turn Sleep($iTimeOut) Send("{DOWN +3}") For $i = 2 To 27 Sleep($iTimeOut) ToolTip($i & " of 27", 450, 440) GUICtrlSetData($hwPrg, $i * (100 / 27)) Sleep($iDelayTime) Send("{DOWN}") Next ; --------------------- ToolTip("") GUIDelete($hwnd) Sleep(1000) Send("{ESC}") EndFunc ;==>ViewCustomCmdsList ; -----------------------------------------------
×
×
  • Create New...