Leaderboard
Popular Content
Showing content with the highest reputation on 02/20/2021 in all areas
-
UDF versionThe definitions at top of WebView2-1-6.au3 are starting to fill up a lot. It's time to support the examples with a UDF: WV2Interfaces.au3. WV2Interfaces.au3 contains all the interface definitions as well as the callback functions generated by ObjectFromTag(). These callback functions always seem to consist of 4 functions: $sFunctionPrefix_QueryInterface() $sFunctionPrefix_AddRef() $sFunctionPrefix_Release() $sFunctionPrefix_Invoke() For the first 3 functions, the code appears to be constant. These functions can be moved directly into the UDF. For the last function, Invoke(), the code varies depending on the functionality we want in the WebView window. Therefore, Invoke() is placed in the UDF as a function skeleton commented out. When we need to use the Invoke() function in our own code, we can start by copying the function skeleton, and add code as needed. WebView2-1-7.au3 is similar to WebView2-1-a.au3 (WebView2-1-a.au3 is a copy of the WebView2-1.au3 example here) but is slightly updated: #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" WebView2() Func WebView2() ; Create WebView2 GUI $hGui = GUICreate( "WebView2 Sample", 1200, 900, -1, -1, $WS_OVERLAPPEDWINDOW ) ; Initialize COM _WinAPI_CoInitialize( $COINIT_APARTMENTTHREADED ) ; Create callback interfaces and functions CoreWebView2CreateCoreWebView2EnvironmentCompletedHandlerCreate( True ) CoreWebView2CreateCoreWebView2ControllerCompletedHandlerCreate( True ) ; DllCall CreateCoreWebView2EnvironmentWithOptions Local $hWebView2Loader = DllOpen( @AutoItX64 ? "WebView2Loader-x64.dll" : "WebView2Loader-x86.dll" ) Local $aRet = DllCall( $hWebView2Loader, "long", "CreateCoreWebView2EnvironmentWithOptions", "wstr", "", "wstr", @ScriptDir, _ "ptr", NULL, "ptr", $pCoreWebView2CreateCoreWebView2EnvironmentCompletedHandler ) ; Forces CoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_Invoke() below to be executed 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 CoreWebView2CreateCoreWebView2EnvironmentCompletedHandlerDelete() CoreWebView2CreateCoreWebView2ControllerCompletedHandlerDelete() DllClose( $hWebView2Loader ) EndFunc ; Copied from WV2Interfaces.au3 ; Executed as a consequence of the CreateCoreWebView2EnvironmentWithOptions DllCall() above 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 ) ; Navigate to web page $oCoreWebView2.Navigate( "https://www.bing.com/" ) Return 0 ; S_OK = 0x00000000 #forceref $pSelf, $long EndFunc Two WebView windowsWebView2-1-8.au3 implements two WebView windows: #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_1, $hGui_2 Global $pCoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_1, $tCoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_1 Global $pCoreWebView2CreateCoreWebView2ControllerCompletedHandler_1, $tCoreWebView2CreateCoreWebView2ControllerCompletedHandler_1 Global $pCoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_2, $tCoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_2 Global $pCoreWebView2CreateCoreWebView2ControllerCompletedHandler_2, $tCoreWebView2CreateCoreWebView2ControllerCompletedHandler_2 Global $oCoreWebView2Environment_1, $oCoreWebView2Controller_1, $oCoreWebView2_1 Global $oCoreWebView2Environment_2, $oCoreWebView2Controller_2, $oCoreWebView2_2 ; Project includes #include "..\Includes\WV2Interfaces.au3" WebView2() Func WebView2() ; Create WebView2 GUIs $hGui_1 = GUICreate( "WebView2 Sample 1", 1200, 900, 50, 50, $WS_OVERLAPPEDWINDOW ) $hGui_2 = GUICreate( "WebView2 Sample 2", 1200, 900, 100, 100, $WS_OVERLAPPEDWINDOW ) ; Initialize COM _WinAPI_CoInitialize( $COINIT_APARTMENTTHREADED ) ; Create callback interfaces and functions $pCoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_1 = _ ObjectFromTag( "CoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_", _ $dtag_ICoreWebView2CreateCoreWebView2EnvironmentCompletedHandler, _ $tCoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_1, False ) $pCoreWebView2CreateCoreWebView2ControllerCompletedHandler_1 = _ ObjectFromTag( "CoreWebView2CreateCoreWebView2ControllerCompletedHandler_", _ $dtag_ICoreWebView2CreateCoreWebView2ControllerCompletedHandler, _ $tCoreWebView2CreateCoreWebView2ControllerCompletedHandler_1, False ) $pCoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_2 = _ ObjectFromTag( "CoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_", _ $dtag_ICoreWebView2CreateCoreWebView2EnvironmentCompletedHandler, _ $tCoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_2, False ) $pCoreWebView2CreateCoreWebView2ControllerCompletedHandler_2 = _ ObjectFromTag( "CoreWebView2CreateCoreWebView2ControllerCompletedHandler_", _ $dtag_ICoreWebView2CreateCoreWebView2ControllerCompletedHandler, _ $tCoreWebView2CreateCoreWebView2ControllerCompletedHandler_2, False ) ; DllCall CreateCoreWebView2EnvironmentWithOptions Local $hWebView2Loader = DllOpen( @AutoItX64 ? "WebView2Loader-x64.dll" : "WebView2Loader-x86.dll" ) Local $aRet = DllCall( $hWebView2Loader, "long", "CreateCoreWebView2EnvironmentWithOptions", "wstr", "", "wstr", @ScriptDir, _ "ptr", NULL, "ptr", $pCoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_1 ) ; Forces CoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_Invoke() below to be executed If @error Or $aRet[0] Then Return ConsoleWrite( "CreateCoreWebView2EnvironmentWithOptions ERR" & @CRLF ) ConsoleWrite( "CreateCoreWebView2EnvironmentWithOptions OK" & @CRLF & @CRLF ) ; DllCall CreateCoreWebView2EnvironmentWithOptions $aRet = DllCall( $hWebView2Loader, "long", "CreateCoreWebView2EnvironmentWithOptions", "wstr", "", "wstr", @ScriptDir, _ "ptr", NULL, "ptr", $pCoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_2 ) ; Forces CoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_Invoke() below to be executed If @error Or $aRet[0] Then Return ConsoleWrite( "CreateCoreWebView2EnvironmentWithOptions ERR" & @CRLF ) ConsoleWrite( "CreateCoreWebView2EnvironmentWithOptions OK" & @CRLF & @CRLF ) ; Show WebView2 GUIs GUISetState( @SW_SHOW, $hGui_1 ) GUISetState( @SW_SHOW, $hGui_2 ) Local $aMsg, $tRect ; Loop While 1 $aMsg = GUIGetMsg(1) Switch $aMsg[1] Case $hGui_1 Switch $aMsg[0] Case $GUI_EVENT_MAXIMIZE, $GUI_EVENT_RESIZED, $GUI_EVENT_RESTORE $tRect = _WinAPI_GetClientRect( $hGui_1 ) $oCoreWebView2Controller_1.put_Bounds( $tRect ) Case $GUI_EVENT_CLOSE GUIDelete( $hGui_1 ) If Not $hGui_2 Then ExitLoop $hGui_1 = 0 EndSwitch Case $hGui_2 Switch $aMsg[0] Case $GUI_EVENT_MAXIMIZE, $GUI_EVENT_RESIZED, $GUI_EVENT_RESTORE $tRect = _WinAPI_GetClientRect( $hGui_2 ) $oCoreWebView2Controller_2.put_Bounds( $tRect ) Case $GUI_EVENT_CLOSE GUIDelete( $hGui_2 ) If Not $hGui_1 Then ExitLoop $hGui_2 = 0 EndSwitch EndSwitch WEnd ; Cleanup DllClose( $hWebView2Loader ) EndFunc ; Copied from WV2Interfaces.au3 ; Executed as a consequence of the CreateCoreWebView2EnvironmentWithOptions DllCall() above Func CoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_Invoke( $pSelf, $long, $ptr ) ; Ret: long Par: long;ptr* ConsoleWrite( "CoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_Invoke()" & @CRLF ) Switch $pSelf Case $pCoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_1 ; $hGui_1 ; Create CoreWebView2Environment object $oCoreWebView2Environment_1 = ObjCreateInterface( $ptr, $sIID_ICoreWebView2Environment, $dtag_ICoreWebView2Environment ) ConsoleWrite( "IsObj( $oCoreWebView2Environment_1 ) = " & IsObj( $oCoreWebView2Environment_1 ) & @CRLF & @CRLF ) ; Set $pCoreWebView2CreateCoreWebView2ControllerCompletedHandler callback pointer for the WebView2 GUI $oCoreWebView2Environment_1.CreateCoreWebView2Controller( $hGui_1, $pCoreWebView2CreateCoreWebView2ControllerCompletedHandler_1 ) ; Forces CoreWebView2CreateCoreWebView2ControllerCompletedHandler_Invoke() below to be executed Case $pCoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_2 ; $hGui_2 ; Create CoreWebView2Environment object $oCoreWebView2Environment_2 = ObjCreateInterface( $ptr, $sIID_ICoreWebView2Environment, $dtag_ICoreWebView2Environment ) ConsoleWrite( "IsObj( $oCoreWebView2Environment_2 ) = " & IsObj( $oCoreWebView2Environment_2 ) & @CRLF & @CRLF ) ; Set $pCoreWebView2CreateCoreWebView2ControllerCompletedHandler callback pointer for the WebView2 GUI $oCoreWebView2Environment_2.CreateCoreWebView2Controller( $hGui_2, $pCoreWebView2CreateCoreWebView2ControllerCompletedHandler_2 ) ; Forces CoreWebView2CreateCoreWebView2ControllerCompletedHandler_Invoke() below to be executed EndSwitch Return 0 ; S_OK = 0x00000000 #forceref $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 ) Local $tRect, $pCoreWebView2 Switch $pSelf Case $pCoreWebView2CreateCoreWebView2ControllerCompletedHandler_1 ; $hGui_1 ; Create CoreWebView2Controller object $oCoreWebView2Controller_1 = ObjCreateInterface( $ptr, $sIID_ICoreWebView2Controller, $dtag_ICoreWebView2Controller ) ConsoleWrite( "IsObj( $oCoreWebView2Controller_1 ) = " & IsObj( $oCoreWebView2Controller_1 ) & @CRLF ) $oCoreWebView2Controller_1.AddRef() ; Prevent the object from being deleted when the function ends ; Set bounds for the CoreWebView2 object $tRect = _WinAPI_GetClientRect( $hGui_1 ) $oCoreWebView2Controller_1.put_Bounds( $tRect ) ; Create CoreWebView2 object $oCoreWebView2Controller_1.get_CoreWebView2( $pCoreWebView2 ) $oCoreWebView2_1 = ObjCreateInterface( $pCoreWebView2, $sIID_ICoreWebView2, $dtag_ICoreWebView2 ) ConsoleWrite( "IsObj( $oCoreWebView2_1 ) = " & IsObj( $oCoreWebView2_1 ) & @CRLF & @CRLF ) ; Navigate to web page $oCoreWebView2_1.Navigate( "https://www.bing.com/" ) Case $pCoreWebView2CreateCoreWebView2ControllerCompletedHandler_2 ; $hGui_2 ; Create CoreWebView2Controller object $oCoreWebView2Controller_2 = ObjCreateInterface( $ptr, $sIID_ICoreWebView2Controller, $dtag_ICoreWebView2Controller ) ConsoleWrite( "IsObj( $oCoreWebView2Controller_2 ) = " & IsObj( $oCoreWebView2Controller_2 ) & @CRLF ) $oCoreWebView2Controller_2.AddRef() ; Prevent the object from being deleted when the function ends ; Set bounds for the CoreWebView2 object $tRect = _WinAPI_GetClientRect( $hGui_2 ) $oCoreWebView2Controller_2.put_Bounds( $tRect ) ; Create CoreWebView2 object $oCoreWebView2Controller_2.get_CoreWebView2( $pCoreWebView2 ) $oCoreWebView2_2 = ObjCreateInterface( $pCoreWebView2, $sIID_ICoreWebView2, $dtag_ICoreWebView2 ) ConsoleWrite( "IsObj( $oCoreWebView2_2 ) = " & IsObj( $oCoreWebView2_2 ) & @CRLF & @CRLF ) ; Navigate to web page $oCoreWebView2_2.Navigate( "file:///" & @ScriptDir & "/index.html" ) EndSwitch Return 0 ; S_OK = 0x00000000 #forceref $long EndFunc For the two callback interfaces, the same $sFunctionPrefix values are used, so that the same set of four callback functions can be used in both windows: ; Create WebView2 GUIs $hGui_1 = GUICreate( "WebView2 Sample 1", 1200, 900, 50, 50, $WS_OVERLAPPEDWINDOW ) $hGui_2 = GUICreate( "WebView2 Sample 2", 1200, 900, 100, 100, $WS_OVERLAPPEDWINDOW ) ; Initialize COM _WinAPI_CoInitialize( $COINIT_APARTMENTTHREADED ) ; Create callback interfaces and functions $pCoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_1 = _ ObjectFromTag( "CoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_", _ $dtag_ICoreWebView2CreateCoreWebView2EnvironmentCompletedHandler, _ $tCoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_1, False ) $pCoreWebView2CreateCoreWebView2ControllerCompletedHandler_1 = _ ObjectFromTag( "CoreWebView2CreateCoreWebView2ControllerCompletedHandler_", _ $dtag_ICoreWebView2CreateCoreWebView2ControllerCompletedHandler, _ $tCoreWebView2CreateCoreWebView2ControllerCompletedHandler_1, False ) $pCoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_2 = _ ObjectFromTag( "CoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_", _ $dtag_ICoreWebView2CreateCoreWebView2EnvironmentCompletedHandler, _ $tCoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_2, False ) $pCoreWebView2CreateCoreWebView2ControllerCompletedHandler_2 = _ ObjectFromTag( "CoreWebView2CreateCoreWebView2ControllerCompletedHandler_", _ $dtag_ICoreWebView2CreateCoreWebView2ControllerCompletedHandler, _ $tCoreWebView2CreateCoreWebView2ControllerCompletedHandler_2, False ) In the Invoke() functions you can distinguish between the two WebView windows through the object pointers (corresponding to the value of $pSelf) in this way: ; Copied from WV2Interfaces.au3 ; Executed as a consequence of the CreateCoreWebView2EnvironmentWithOptions DllCall() above Func CoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_Invoke( $pSelf, $long, $ptr ) ; Ret: long Par: long;ptr* ConsoleWrite( "CoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_Invoke()" & @CRLF ) Switch $pSelf Case $pCoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_1 ; $hGui_1 ; Create CoreWebView2Environment object $oCoreWebView2Environment_1 = ObjCreateInterface( $ptr, $sIID_ICoreWebView2Environment, $dtag_ICoreWebView2Environment ) ConsoleWrite( "IsObj( $oCoreWebView2Environment_1 ) = " & IsObj( $oCoreWebView2Environment_1 ) & @CRLF & @CRLF ) ; Set $pCoreWebView2CreateCoreWebView2ControllerCompletedHandler callback pointer for the WebView2 GUI $oCoreWebView2Environment_1.CreateCoreWebView2Controller( $hGui_1, $pCoreWebView2CreateCoreWebView2ControllerCompletedHandler_1 ) ; Forces CoreWebView2CreateCoreWebView2ControllerCompletedHandler_Invoke() below to be executed Case $pCoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_2 ; $hGui_2 ; Create CoreWebView2Environment object $oCoreWebView2Environment_2 = ObjCreateInterface( $ptr, $sIID_ICoreWebView2Environment, $dtag_ICoreWebView2Environment ) ConsoleWrite( "IsObj( $oCoreWebView2Environment_2 ) = " & IsObj( $oCoreWebView2Environment_2 ) & @CRLF & @CRLF ) ; Set $pCoreWebView2CreateCoreWebView2ControllerCompletedHandler callback pointer for the WebView2 GUI $oCoreWebView2Environment_2.CreateCoreWebView2Controller( $hGui_2, $pCoreWebView2CreateCoreWebView2ControllerCompletedHandler_2 ) ; Forces CoreWebView2CreateCoreWebView2ControllerCompletedHandler_Invoke() below to be executed EndSwitch Return 0 ; S_OK = 0x00000000 #forceref $long EndFunc DllCall()In the two examples in this post, @ScriptDir is added as a parameter in the DllCall() function to avoid this error: CreateCoreWebView2EnvironmentWithOptions ERR. You can add the @ScriptDir parameter in the DllCall() function in the previous examples if you wish. The 7z-file at bottom of first post has been updated.3 points
-
Suppose we want to put a text of variable lengths in the vertical center of two horizontal lines. The text is mostly one liner, but some are so long that they have to be wrapped to 2 lines. Unfortunately, GUICtrlCreateLabel() doesn't have a style option for vertical centering of the text. $SS_CENTERIMAGE works, but it does not allow wrapping. I thought I could adjust the vertical position of the label control if I know the text is wrapped. But I could not find a function to determine if the text is wrapped or not. StringSize UDF is too good and too cumbersome for this small purpose. Creating a temporary, hidden label control was the solution. It takes 4 to 6 milliseconds, which is about the same as, or a little faster than, StringSize UDF. HotKeySet("{ESC}", "Quit") local $hGUI = GUICreate("Vertical Center", 290, 200, -1, -1) GUISetFont(12, 400) Local $sLine = "-----------------------------------" Local $sShort = "A short string of characters" Local $sLong_1 = "A long string of characters in ORIGINAL label position" Local $sLong_2 = "A long string of characters in ADJUSTED label position" Local $iLabelWidth = 250 Local $idLabel_1 = GUICtrlCreateLabel($sLine, 20, 20, $iLabelWidth, 20) Local $idLabel_2 = GUICtrlCreateLabel($sShort, 20, 48, $iLabelWidth, 35) Local $idLabel_3 = GUICtrlCreateLabel($sLine, 20, 80, $iLabelWidth, 20) GUISetState() Local $sString = $sShort, $tmpGUI, $tmpLabel, $aPos While 1 ; The next 4 lines of code calculate the pixel width of a string. $tmpGUI = GUICreate("") GUISetFont(12, 400) ; keep font the same as main GUI $tmpLabel = GUICtrlCreateLabel($sString, 0, 0) $aPos = ControlGetPos($tmpGUI, "", $tmpLabel) GUIDelete($tmpGUI) If $aPos[2] <= $iLabelWidth Then ; text is one liner $sString = $sShort GUICtrlSetData($idLabel_2, $sString) GUICtrlSetPos($idLabel_2, 20, 48) $sString = $sLong_1 Else ; text is wrapped GUICtrlSetData($idLabel_2, $sString) Sleep(5000) $sString = $sLong_2 GUICtrlSetData($idLabel_2, $sString) GUICtrlSetPos($idLabel_2, 20, 40) $sString = $sShort EndIf Sleep(5000) WEnd Func Quit() GUIDelete($hGUI) Exit EndFunc2 points
-
Vertical Centering of Label Text
pixelsearch and one other reacted to Musashi for a topic
@pixelsearch and @CYCho : Both scripts even work on my stone age testing computer (Win7 SP1 64 Bit, AutoIt 3.3.14.0)2 points -
CYCho, Using a temporary GUI was exactly how I started with StringSize before switching to the current GetTextExtentPoint32W method - great minds think alike! M232 points
-
Vertical Centering of Label Text
Zmy and one other reacted to pixelsearch for a topic
Hi Cycho Nice idea to test the pixel width of a string in a temporary GUI. In a final script, it won't probably be tested over and over within a while Wend loop, but as we're in an example script... Just for fun, I tried another way, keeping the same position of the label. It works on my computer, not sure it will work accurately everywhere. #include <StaticConstants.au3> HotKeySet("{ESC}", "Quit") local $hGUI = GUICreate("Vertical Center", 290, 200, -1, -1) GUISetFont(12, 400) Local $sShort = "A short string of characters" Local $sLong = "A long string of characters in ORIGINAL label position" Local $iLabelWidth = 250 Local $idLabel = GUICtrlCreateLabel($sShort, 20, 48, $iLabelWidth, 40, $SS_SUNKEN) GUISetState() Local $sString = $sShort, $tmpGUI, $tmpLabel, $aPos While 1 ; The next 4 lines of code calculate the pixel width of a string. $tmpGUI = GUICreate("") GUISetFont(12, 400) ; keep font the same as main GUI $tmpLabel = GUICtrlCreateLabel($sString, 0, 0) $aPos = ControlGetPos($tmpGUI, "", $tmpLabel) GUIDelete($tmpGUI) If $aPos[2] <= $iLabelWidth Then ; text is one liner $sString = $sShort GUICtrlSetStyle($idLabel, $SS_CENTERIMAGE) GUICtrlSetData($idLabel, $sString) $sString = $sLong Else ; text is wrapped $sString = $sLong GUICtrlSetStyle($idLabel, 0) GUICtrlSetData($idLabel, $sString) $sString = $sShort EndIf Sleep(3000) WEnd Func Quit() GUIDelete($hGUI) Exit EndFunc2 points -
AutoItObject Pure AutoIt
argumentum and one other reacted to genius257 for a topic
version: 3.0.0 changes Most notable change: ROT¹ support! 🎊 ¹ Running Object Table2 points -
No it doesn't speak, I lied. That is impossible. It's about setting animated GIF (and every other type of images) to a GUI control. How is this done for animated GIF? Few simple steps: - created ImageList of GIF Bitmaps retrieved from gif file/resource - created Pic control - every now and then another image is displayed. This is determined by frame delay time - see gif specification somewhere. That's it. All that takes time and could potentially block our gui/script. That's why flying assembly is used. Animation is done in another thread different from one AutoIt's code is executed in. Nothing stops animation but you. Animation works both for x64 and x86. Also it works for all kind of images not only GIFs. That means you can use it to display PNGs, BMPs, JPGs, etc... All of them from resources too. Example: #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include "GIFAnimation.au3" Opt("MustDeclareVars", 1) ; Start by choosing GIF to display Global $sFile = FileOpenDialog("Choose Image", "", "(*.gif;*.png;*.jpg;*.tiff;*.bmp;*.jpeg)", -1, "") If @error Then Exit ; Make GUI Global $hGui = GUICreate("GIF Animation", 500, 500, -1, -1, $WS_OVERLAPPEDWINDOW) ; Add some buttons Global $hButton = GUICtrlCreateButton("&Pause animation", 50, 450, 100, 25) Global $hButton1 = GUICtrlCreateButton("&Delete Control", 200, 450, 100, 25) Global $hButton2 = GUICtrlCreateButton("&Open Image", 350, 450, 100, 25) ; Make GIF Control Global $hGIF = _GUICtrlCreateGIF($sFile, "", 10, 10) If @extended Then GUICtrlSetState($hButton, $GUI_DISABLE) GUICtrlSetTip($hGIF, "Image") ; Additional processing of some windows messages (for example) GUIRegisterMsg(133, "_Refresh") ; WM_NCPAINT GUIRegisterMsg(15, "_ValidateGIFs") ; WM_PAINT Global $iPlay = 1 ; Show it GUISetState() ; Loop till end While 1 Switch GUIGetMsg() Case -3 Exit Case $hButton If $iPlay Then If _GIF_PauseAnimation($hGIF) Then $iPlay = 0 GUICtrlSetData($hButton, "Resume animation") EndIf Else If _GIF_ResumeAnimation($hGIF) Then $iPlay = 1 GUICtrlSetData($hButton, "Pause animation") EndIf EndIf Case $hButton1 _GIF_DeleteGIF($hGIF) Case $hButton2 $sFile = FileOpenDialog("Choose gif", "", "(*.gif;*.png;*.jpg;*.tiff;*.bmp;*.jpeg)", -1, "", $hGui) If Not @error Then _GIF_DeleteGIF($hGIF); delete previous $hGIF = _GUICtrlCreateGIF($sFile, "", 10, 10) If @extended Then GUICtrlSetState($hButton, $GUI_DISABLE) Else GUICtrlSetState($hButton, $GUI_ENABLE) EndIf GUICtrlSetTip($hGIF, "Image") $iPlay = 1 GUICtrlSetData($hButton, "Pause animation") EndIf EndSwitch WEnd Func _Refresh($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg, $wParam, $lParam _GIF_RefreshGIF($hGIF) EndFunc ;==>_Refresh Func _ValidateGIFs($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg, $wParam, $lParam _GIF_ValidateGIF($hGIF) EndFunc ;==>_ValidateGIFs It should be 0% cpu. Download from here if you want to impress chicks: http://code.google.com/p/gif-animation/downloads/list There are 8 examples in there. GIF files are downloaded automatically if some example script needs it. Mostly from photobucket.com. Some examples work without classic download. Required data is get with InetRead(). That's mighty cool. So, download, open ZIP, grab folder inside and place it where you want. Run examples and that's it. Word or two about main function, _GUICtrlCreateGIF(). It can handle all sorts of input. Will display Images that are passed as binary, resource identifiers, strings, file names, ... everything. If it's valid image all works. For example, all this is valid: ; Pass GIF File path/name _GUICtrlCreateGIF("Some.gif", "", 10, 10) ; Binary data _GUICtrlCreateGIF($bGIF, "", 10, 10,) ; PE Resource (file GIF.dll, Type: GIF, Name: 4) _GUICtrlCreateGIF("GIF.dll", "GIF;4", 10, 10, 100, 120) ; PE Resource (file @AutoItExe, Type: RES, Name: BLAH, Language: 1033) _GUICtrlCreateGIF(@AutoItExe, "RES;BLAH;1033", 10, 10) ; PE Resource (file "explorer.exe", Type: 2, Name: 6801) _GUICtrlCreateGIF("explorer.exe", "2;6801", 10, 10) ;<- BITMAP ; PE Resource (file @AutoItExe, Type: RC_DATA, Name: PNG) _GUICtrlCreateGIF(@AutoItExe, "10;PNG", 10, 10) ; GIF string _GUICtrlCreateGIF(FileRead("Some.gif"), "", 10, 10) ____________________________________________1 point
-
mesale0077 asked me whether I could code some CSS loading animations from different web sites. These are the results using GDI+ (AutoIt v3.3.12.0+ required!): _GDIPlus_MonochromaticBlinker.au3 / _GDIPlus_RotatingBokeh.au3 _GDIPlus_SpinningCandy.au3 / _GDIPlus_SteamPunkLoading.au3 _GDIPlus_IncreasingBalls.au3 / _GDIPlus_PacmanProgressbar.au3 _GDIPlus_StripProgressbar.au3 / _GDIPlus_RingProgressbar.au3 _GDIPlus_LineProgressbar.au3 / _GDIPlus_SimpleLoadingAnim.au3 _GDIPlus_TextFillingWithWater.au3 / _GDIPlus_MultiColorLoader.au3 _GDIPlus_LoadingSpinner.au3 / _GDIPlus_SpinningAndPulsing.au3 _GDIPlus_TogglingSphere.au3 / _GDIPlus_CloudySpiral.au3 _GDIPlus_GlowingText.au3 (thanks to Eukalyptus) / _GDIPlus_HypnoticLoader.au3 _GDIPlus_RotatingRectangles.au3 / _GDIPlus_TRONSpinner.au3 _GDIPlus_RotatingBars.au3 / _GDIPlus_AnotherText.au3 (thanks to Eukalyptus) _GDIPlus_CogWheels.au3 (thanks to Eukalyptus) / _GDIPlus_DrawingText.au3 (thanks to Eukalyptus) _GDIPlus_GearsAnim.au3 / _GDIPlus_LEDAnim.au3 _GDIPlus_LoadingTextAnim.au3 / _GDIPlus_MovingRectangles.au3 _GDIPlus_SpinningAndGlowing.au3 (thanks to Eukalyptus) / _GDIPlus_YetAnotherLoadingAnim.au3 _GDIPlus_AnimatedTypeLoader.au3 / _GDIPlus_Carousel.au3 Each animation function has a built-in example how it can be used. AiO download: GDI+ Animated Wait Loading Screens.7z (previous downloads: 1757) Big thanks to Eukalyptus for providing several examples. Maybe useful for some of you Br, UEZ PS: I don't understand CSS - everything is made out of my mind, so it might be different from original CSS examples1 point
-
Every now and then I come back to my two big monitors and I can't find the mouse cursor. I'm moving the mouse around but don't seem to be looking in the right place or the right screen. In a few seconds I feel like and idiot and it is very irritating. So finally I wrote a program that waits for 5 minutes of idletime (no keyboard or mouse movement) and draws a nice red circle around the mouse cursor. That I can spot easily, even from across the room as I walk up to the computer. It works nicely coming back from sleep mode if I press a key. If I moved the mouse to come out of sleep I can press the middle mouse button to show the red ring. As soon as I move the mouse it disappears. It has a tray menu so you can change the amount of idletime before it turns on and there is another menu choice to Exit. You can compile the script and set a link in your start menu to come on every day if you like it. I'm attaching a circle icon for the taskbar icon and the exe icon in case want to use it. Thanks to Bam and martin for the circle code using window regions ;circle around mouse cursor #AutoIt3Wrapper_Icon=circle2.ico #NoTrayIcon #include <GUIConstants.au3> #include <WindowsConstants.au3> #include <timers.au3> #include <misc.au3> ;Thanks to Bam and martin for the circle code using window regions https://www.autoitscript.com/forum/topic/85970-draw-a-circle-around-the-mouse/ Global $IdleTime = 5 * 60000 ;change the 5 to the number of minutes before circle appears Opt("TrayMenuMode", 3) ;The default tray menu items will not be shown and items are not checked when selected. These are options 1 and 2 for TrayMenuMode. Opt("TrayOnEventMode", 1) ; Use event trapping for tray menu TraySetToolTip("ms-circle") TrayCreateItem("SetTime") TrayItemSetOnEvent(-1, "__SetTime") TrayCreateItem("Exit") TrayItemSetOnEvent(-1, "_bye") TraySetIcon("circle2.ico") TraySetState() $iCircleR = 20 ; <=== Edit this for different circle radius (in pixels) $iCircleD = $iCircleR * 2 $pt = MouseGetPos() $GUI = GUICreate("test", $iCircleD, $iCircleD, $pt[0] - $iCircleR, $pt[1] - $iCircleR, $WS_POPUP, $WS_EX_TOPMOST) GUISetBkColor(0xFF0000) $a = _CreateRoundRectRgn(0, 0, $iCircleD, $iCircleD, $iCircleD, $iCircleD) $b = _CreateRoundRectRgn(4, 4, ($iCircleD - 8), ($iCircleD - 8), ($iCircleD - 4), ($iCircleD - 4)) _CombineRgn($a, $b) _SetWindowRgn($GUI, $a) GUISetState(@SW_HIDE) While 1 Sleep(250) _chk_Idle() WEnd ;*** Functions *** Func _CreateRoundRectRgn($l, $t, $w, $h, $e1, $e2) $ret = DllCall("gdi32.dll", "long", "CreateRoundRectRgn", "long", $l, "long", $t, "long", $l + $w, "long", $t + $h, "long", $e1, "long", $e2) Return $ret[0] EndFunc ;==>_CreateRoundRectRgn Func _CombineRgn(ByRef $rgn1, ByRef $rgn2) DllCall("gdi32.dll", "long", "CombineRgn", "long", $rgn1, "long", $rgn1, "long", $rgn2, "int", 3) EndFunc ;==>_CombineRgn Func _SetWindowRgn($h_win, $rgn) DllCall("user32.dll", "long", "SetWindowRgn", "hwnd", $h_win, "long", $rgn, "int", 1) EndFunc ;==>_SetWindowRgn Func __SetTime() Local $sd, $min $sd = "Number of minutes" $min = InputBox("Now " & $IdleTime / 60000 & " minutes", $sd, "", "", -1, 122 + (13.2 * UBound(StringRegExp($sd, '\R', 3)))) if $min > 0 then $IdleTime = $min * 60000 EndFunc ;==>__SetTime Func _bye() ToolTip("Exiting") Sleep(1000) ToolTip("", 500, 300) Exit EndFunc ;==>_bye Func _chk_Idle() If _Timer_GetIdleTime() > $IdleTime Or _IsPressed(04) Then ;1 minutes idle Local $wh = WinGetHandle("[active]") $pt = MouseGetPos() GUISetState() GUISetState(@SW_DISABLE) If Not @error Then WinMove($GUI, "", $pt[0] - $iCircleR, $pt[1] - $iCircleR) WinActivate($wh) While 1 $ap = MouseGetPos() If $ap[0] <> $pt[0] Then ExitLoop EndIf Sleep(1000) WEnd GUISetState(@SW_HIDE) EndIf EndFunc ;==>_chk_Idle circle2.ico1 point
-
EasyCodeIt - cross-platform AutoIt implementation
TheSaint reacted to JockoDundee for a topic
Fledgling Startup EasyCodeIt Faces Division Over Direction (Feb 20, 2021 - Wire Services) Citing concerns about a perceived dearth of example code, a small but vocal faction of the burgeoning ECI community shared their belief that greater resources invested towards example scripts would, in the end lead to greater “views”, and ultimately “more click on [the] project”. With a shout-out to the iconic, if aging Id title, poster E1M1, speaking for the faction argued: This latest provocation threatens to widen the bifurcation started previously when E1M1 noted simply that such a directory might be “cool”, and was decidedly vague about implementation details. The response from the reclusive and enigmatic “TheDcoder” was swift and unambiguous, countering “cool” with “tedious” and ending with a classic punctuating emoji. What TheDcoder’s response to this latest more aggressive salvo is anyone’s guess, known for being wildly unpredictable, there’s just no telling what his next move may be as the fate of ECI hangs in the balance Stay tuned - this is breaking news...1 point -
Another good example of what not to use : Send and MouseClick. Try this instead : Run("notepad.exe") $hWnd = WinWait("[CLASS:Notepad]") ControlSetText($hWnd, "", "Edit1", "OK") Sleep(2000) ; time for you to see the text ControlSetText($hWnd, "", "Edit1", "New Text")1 point
-
Exit, In Win 10 Settings open the <Devices> - <Mouse> - <Additional mouse options> - you find that option at the bottom of the <Pointer Options> tab. M23 Edit: Just as water shows.1 point
-
I use this setting too and never had to search my mouse pointer since. https://www.isunshare.com/windows-10/show-pointer-location-with-ctrl-key-in-windows-10.html1 point
-
That would allow others to see how far have you get with this project. I mean not eveyone who is interested in project is interested enough to try it out for themselves. It's kinda like with YouTube - It allows me to quickly check out new interesting and fun Doom mods without having to install and play these myself. And so is with examples - it helps you to get more "views". Which means better chance that someone would actually try to do something with your language and upload their script to their github which in return ends up in more click on your project. I understand how busy you are - I would probably also feel that way. But you also dont want to end up having 100% implementation of Autoit and only then star to figure out how to get user base. And These example scripts could also serve as some sort of unit tests - you refactor something and then see which example scripts start to print something else than they used to.1 point
-
Made it worked with this line : Local $iRet = TCPSend($Socket, 'login {"protocol":1,"client":"test","clientver":"0.1"}' & chr(4))1 point
-
please help me
FrancescoDiMuro reacted to Jos for a topic
English please as I already requested! I live in the Netherlands, but still communicate in English, so I would say give it a proper try or else you are in the wrong forum.1 point -
It worked! Thank you very much! In "Prices" tab it had 2 "toolStrip" toolbars, don't know why. The only thing it changes between the 2 of them is the native handle property. My question is, can I identify the handle of the "right" toolStrip? Or the handle never changes?1 point
-
Microsoft Edge - WebView2, embed web code in your native application
argumentum reacted to Gianni for a topic
Sorry, but I disagree. Personally I am convinced that this tool is very useful and considering that this topic has had almost 3000 views in almost 3 months it is a sign that there is a good interest (and expectation) around this udf by AutoIt programmers. I was already convinced when I drafted this other post (even if for another 'engine'). @LarsJ, please don't go away.... it's not exactly correct to consider this stuff as a replacement for the IE.udf. IE.udf can be better replaced by @Danp2's WebDriver udf. Maybe The only function of ie.udf that better compares to this WebView2 is _IECreateEmbedded() This is true for the IE browser, but as far as BrowserControl is concerned I think it will survive IE for example the BrowserControl is part of the .NET "System.Windows.Controls" WebBrowser class. It is also used in the windows help. If you use the 'AutoIt Window Info' tool you can see that the BrowserControl (class: Internet Explorer_Server) is used as the help viewer...1 point -
@frank10 $sOption is optional as far as the function is concerned. However, it is required for some of the $sCommand actions, like "New". If you look at the code for WD_NewTab, you'll find that it calls _WD_Window like this to create a new tab -- $sTabHandle = _WD_Window($sSession, 'new', '{"type":"tab"}') Now check out the New Window W3C specs to see that you can also pass a type of "window". Thus you should be able to get the desired result with this -- $sTabHandle = _WD_Window($sSession, 'new', '{"type":"window"}')1 point
-
Responding eventsIn the first post, the ICoreWebView2CreateCoreWebView2EnvironmentCompletedHandler callback interface was implemented. According to the Microsoft documentation, this callback interface is implemented to be able get an object pointer to the the ICoreWebView2Environment through a DllCall() to either the CreateCoreWebView2Environment() or CreateCoreWebView2EnvironmentWithOptions() functions implemented in WebView2Loader.dll. ICoreWebView2Environment represents the WebView2 environment on the PC. You pass the $pCoreWebView2CreateCoreWebView2EnvironmentCompletedHandler pointer to one of the dll-functions. As a consequence of the function call, the dll-function generates a CoreWebView2CreateCoreWebView2EnvironmentCompletedHandler event. You respond to this event by adding code in the callback function CoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_Invoke() (WebView2-1-4.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 Global $pCoreWebView2CreateCoreWebView2EnvironmentCompletedHandler, _ $tCoreWebView2CreateCoreWebView2EnvironmentCompletedHandler Global Const $dtag_ICoreWebView2CreateCoreWebView2EnvironmentCompletedHandler = _ "Invoke hresult(hresult;ptr*);" ; ICoreWebView2Environment interface Global $oCoreWebView2Environment Global Const $sIID_ICoreWebView2Environment = "{B96D755E-0319-4E92-A296-23436F46A1FC}" Global Const $dtag_ICoreWebView2Environment = _ "CreateCoreWebView2Controller hresult(hwnd;ptr);" & _ "CreateWebResourceResponse hresult();" & _ "get_BrowserVersionString hresult();" & _ "add_NewBrowserVersionAvailable hresult();" & _ "remove_NewBrowserVersionAvailable hresult();" ; Project includes ;#include "..\Includes\WV2Interfaces.au3" #include "..\Includes\ObjectFromTag.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 interfaces and functions $pCoreWebView2CreateCoreWebView2EnvironmentCompletedHandler = _ ObjectFromTag( "CoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_", _ $dtag_ICoreWebView2CreateCoreWebView2EnvironmentCompletedHandler, _ $tCoreWebView2CreateCoreWebView2EnvironmentCompletedHandler, False, True ) ; $bPrint = 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 ) ; Forces CoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_Invoke() below to be executed 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_CLOSE ExitLoop EndSwitch WEnd ; Cleanup DllClose( $hWebView2Loader ) EndFunc Func CoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_QueryInterface( $pSelf, $pRIID, $pObj ) ; Ret: long Par: ptr;ptr* ConsoleWrite( "CoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_QueryInterface()" & @CRLF & @CRLF ) Return 0 ; S_OK = 0x00000000 #forceref $pSelf, $pRIID, $pObj EndFunc Func CoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_AddRef( $pSelf ) ; Ret: dword ConsoleWrite( "CoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_AddRef()" & @CRLF & @CRLF ) Return 1 ; For AddRef/Release #forceref $pSelf EndFunc Func CoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_Release( $pSelf ) ; Ret: dword ConsoleWrite( "CoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_Release()" & @CRLF & @CRLF ) Return 1 ; For AddRef/Release #forceref $pSelf EndFunc ; Executed as a consequence of the CreateCoreWebView2EnvironmentWithOptions DllCall() 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 SciTE console output: Func CoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_QueryInterface( $pSelf, $pRIID, $pObj ) ; Ret: long Par: ptr;ptr* ConsoleWrite( "CoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_QueryInterface()" & @CRLF & @CRLF ) Return 0 ; S_OK = 0x00000000 #forceref $pSelf, $pRIID, $pObj EndFunc @error = 0 Func CoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_AddRef( $pSelf ) ; Ret: dword ConsoleWrite( "CoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_AddRef()" & @CRLF & @CRLF ) Return 1 ; For AddRef/Release #forceref $pSelf EndFunc @error = 0 Func CoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_Release( $pSelf ) ; Ret: dword ConsoleWrite( "CoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_Release()" & @CRLF & @CRLF ) Return 1 ; For AddRef/Release #forceref $pSelf EndFunc @error = 0 Func CoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_Invoke( $pSelf, $long, $ptr ) ; Ret: long Par: long;ptr* ConsoleWrite( "CoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_Invoke()" & @CRLF & @CRLF ) Return 0 ; S_OK = 0x00000000 #forceref $pSelf, $long, $ptr EndFunc @error = 0 CoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_AddRef() CoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_Invoke() IsObj( $oCoreWebView2Environment ) = 1 CoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_Release() CreateCoreWebView2EnvironmentWithOptions OK According to the documentation for ICoreWebView2CreateCoreWebView2EnvironmentCompletedHandler interface the Invoke() method returns a pointer to the ICoreWebView2Environment interface as the last parameter. From this pointer the CoreWebView2Environment object can be created: ; 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 Data for the ICoreWebView2Environment interface is included at the top of WebView2-1-4.au3. The most interesting method of the CoreWebView2Environment object is CreateCoreWebView2Controller(). The method takes our AutoIt GUI and a pointer to an ICoreWebView2CreateCoreWebView2ControllerCompletedHandler callback interface as input parameters and creates a WebView2 window embedded in the AutoIt GUI. Create callback interfaceBefore we can execute the CreateCoreWebView2Controller() method, we need to create the ICoreWebView2CreateCoreWebView2ControllerCompletedHandler callback interface and its functions so that we can pass the object pointer to the method. We create the callback interface and its functions by performing the 5 steps described in first post. Step 1The $dtag for the ICoreWebView2CreateCoreWebView2ControllerCompletedHandler callback interface can be created based on the information in WebView2.h (search the interface) and the Microsoft documentation (google the interface): Global Const $dtag_ICoreWebView2CreateCoreWebView2ControllerCompletedHandler = _ "Invoke hresult(hresult;ptr*);" Continue with steps 2 - 4 as described in first post. Step 5To test whether the interface functions are called as expected, we need to execute the CreateCoreWebView2Controller() method in the code above. The CoreWebView2CreateCoreWebView2ControllerCompletedHandler_Invoke() function is called as a consequence of executing this method. Check if the interface functions are called as expected (WebView2-1-5.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 Global $pCoreWebView2CreateCoreWebView2EnvironmentCompletedHandler, _ $tCoreWebView2CreateCoreWebView2EnvironmentCompletedHandler Global Const $dtag_ICoreWebView2CreateCoreWebView2EnvironmentCompletedHandler = _ "Invoke hresult(hresult;ptr*);" Global $pCoreWebView2CreateCoreWebView2ControllerCompletedHandler, _ $tCoreWebView2CreateCoreWebView2ControllerCompletedHandler Global Const $dtag_ICoreWebView2CreateCoreWebView2ControllerCompletedHandler = _ "Invoke hresult(hresult;ptr*);" ; ICoreWebView2Environment interface Global $oCoreWebView2Environment Global Const $sIID_ICoreWebView2Environment = "{B96D755E-0319-4E92-A296-23436F46A1FC}" Global Const $dtag_ICoreWebView2Environment = _ "CreateCoreWebView2Controller hresult(hwnd;ptr);" & _ "CreateWebResourceResponse hresult();" & _ "get_BrowserVersionString hresult();" & _ "add_NewBrowserVersionAvailable hresult();" & _ "remove_NewBrowserVersionAvailable hresult();" ; Project includes ;#include "..\Includes\WV2Interfaces.au3" #include "..\Includes\ObjectFromTag.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 interfaces and functions $pCoreWebView2CreateCoreWebView2EnvironmentCompletedHandler = _ ObjectFromTag( "CoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_", _ $dtag_ICoreWebView2CreateCoreWebView2EnvironmentCompletedHandler, _ $tCoreWebView2CreateCoreWebView2EnvironmentCompletedHandler, False, True ) ; $bPrint = True $pCoreWebView2CreateCoreWebView2ControllerCompletedHandler = _ ObjectFromTag( "CoreWebView2CreateCoreWebView2ControllerCompletedHandler_", _ $dtag_ICoreWebView2CreateCoreWebView2ControllerCompletedHandler, _ $tCoreWebView2CreateCoreWebView2ControllerCompletedHandler, False, True ) ; $bPrint = 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 ) ; Forces CoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_Invoke() below to be executed 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_CLOSE ExitLoop EndSwitch WEnd ; Cleanup DllClose( $hWebView2Loader ) EndFunc Func CoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_QueryInterface( $pSelf, $pRIID, $pObj ) ; Ret: long Par: ptr;ptr* ConsoleWrite( "CoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_QueryInterface()" & @CRLF & @CRLF ) Return 0 ; S_OK = 0x00000000 #forceref $pSelf, $pRIID, $pObj EndFunc Func CoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_AddRef( $pSelf ) ; Ret: dword ConsoleWrite( "CoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_AddRef()" & @CRLF & @CRLF ) Return 1 ; For AddRef/Release #forceref $pSelf EndFunc Func CoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_Release( $pSelf ) ; Ret: dword ConsoleWrite( "CoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_Release()" & @CRLF & @CRLF ) Return 1 ; For AddRef/Release #forceref $pSelf EndFunc ; Executed as a consequence of the CreateCoreWebView2EnvironmentWithOptions DllCall() 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 Func CoreWebView2CreateCoreWebView2ControllerCompletedHandler_QueryInterface( $pSelf, $pRIID, $pObj ) ; Ret: long Par: ptr;ptr* ConsoleWrite( "CoreWebView2CreateCoreWebView2ControllerCompletedHandler_QueryInterface()" & @CRLF & @CRLF ) Return 0 ; S_OK = 0x00000000 #forceref $pSelf, $pRIID, $pObj EndFunc Func CoreWebView2CreateCoreWebView2ControllerCompletedHandler_AddRef( $pSelf ) ; Ret: dword ConsoleWrite( "CoreWebView2CreateCoreWebView2ControllerCompletedHandler_AddRef()" & @CRLF & @CRLF ) Return 1 ; For AddRef/Release #forceref $pSelf EndFunc Func CoreWebView2CreateCoreWebView2ControllerCompletedHandler_Release( $pSelf ) ; Ret: dword ConsoleWrite( "CoreWebView2CreateCoreWebView2ControllerCompletedHandler_Release()" & @CRLF & @CRLF ) Return 1 ; For AddRef/Release #forceref $pSelf EndFunc ; Executed as a consequence of $oCoreWebView2Environment.CreateCoreWebView2Controller() above Func CoreWebView2CreateCoreWebView2ControllerCompletedHandler_Invoke( $pSelf, $long, $ptr ) ; Ret: long Par: long;ptr* ConsoleWrite( "CoreWebView2CreateCoreWebView2ControllerCompletedHandler_Invoke()" & @CRLF & @CRLF ) Return 0 ; S_OK = 0x00000000 #forceref $pSelf, $long, $ptr EndFunc SciTE console output: Func CoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_QueryInterface( $pSelf, $pRIID, $pObj ) ; Ret: long Par: ptr;ptr* ConsoleWrite( "CoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_QueryInterface()" & @CRLF & @CRLF ) Return 0 ; S_OK = 0x00000000 #forceref $pSelf, $pRIID, $pObj EndFunc @error = 0 Func CoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_AddRef( $pSelf ) ; Ret: dword ConsoleWrite( "CoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_AddRef()" & @CRLF & @CRLF ) Return 1 ; For AddRef/Release #forceref $pSelf EndFunc @error = 0 Func CoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_Release( $pSelf ) ; Ret: dword ConsoleWrite( "CoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_Release()" & @CRLF & @CRLF ) Return 1 ; For AddRef/Release #forceref $pSelf EndFunc @error = 0 Func CoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_Invoke( $pSelf, $long, $ptr ) ; Ret: long Par: long;ptr* ConsoleWrite( "CoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_Invoke()" & @CRLF & @CRLF ) Return 0 ; S_OK = 0x00000000 #forceref $pSelf, $long, $ptr EndFunc @error = 0 Func CoreWebView2CreateCoreWebView2ControllerCompletedHandler_QueryInterface( $pSelf, $pRIID, $pObj ) ; Ret: long Par: ptr;ptr* ConsoleWrite( "CoreWebView2CreateCoreWebView2ControllerCompletedHandler_QueryInterface()" & @CRLF & @CRLF ) Return 0 ; S_OK = 0x00000000 #forceref $pSelf, $pRIID, $pObj EndFunc @error = 0 Func CoreWebView2CreateCoreWebView2ControllerCompletedHandler_AddRef( $pSelf ) ; Ret: dword ConsoleWrite( "CoreWebView2CreateCoreWebView2ControllerCompletedHandler_AddRef()" & @CRLF & @CRLF ) Return 1 ; For AddRef/Release #forceref $pSelf EndFunc @error = 0 Func CoreWebView2CreateCoreWebView2ControllerCompletedHandler_Release( $pSelf ) ; Ret: dword ConsoleWrite( "CoreWebView2CreateCoreWebView2ControllerCompletedHandler_Release()" & @CRLF & @CRLF ) Return 1 ; For AddRef/Release #forceref $pSelf EndFunc @error = 0 Func CoreWebView2CreateCoreWebView2ControllerCompletedHandler_Invoke( $pSelf, $long, $ptr ) ; Ret: long Par: long;ptr* ConsoleWrite( "CoreWebView2CreateCoreWebView2ControllerCompletedHandler_Invoke()" & @CRLF & @CRLF ) Return 0 ; S_OK = 0x00000000 #forceref $pSelf, $long, $ptr EndFunc @error = 0 CoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_AddRef() CoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_Invoke() IsObj( $oCoreWebView2Environment ) = 1 CoreWebView2CreateCoreWebView2ControllerCompletedHandler_AddRef() CoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_Release() CreateCoreWebView2EnvironmentWithOptions OK CoreWebView2CreateCoreWebView2ControllerCompletedHandler_AddRef() CoreWebView2CreateCoreWebView2ControllerCompletedHandler_Invoke() CoreWebView2CreateCoreWebView2ControllerCompletedHandler_Release() CoreWebView2CreateCoreWebView2ControllerCompletedHandler_Release() Output looks as expected. So far, there is no web page to view because we haven't opened one. Responding events 2As a consequence of executing $oCoreWebView2Environment.CreateCoreWebView2Controller() above, a CoreWebView2CreateCoreWebView2EnvironmentCompletedHandler event is generated. You respond to this event by adding code in the callback function CoreWebView2CreateCoreWebView2ControllerCompletedHandler_Invoke(). Here we'll add code to open a web page (WebView2-1-6.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 Global $pCoreWebView2CreateCoreWebView2EnvironmentCompletedHandler, _ $tCoreWebView2CreateCoreWebView2EnvironmentCompletedHandler Global Const $dtag_ICoreWebView2CreateCoreWebView2EnvironmentCompletedHandler = _ "Invoke hresult(hresult;ptr*);" Global $pCoreWebView2CreateCoreWebView2ControllerCompletedHandler, _ $tCoreWebView2CreateCoreWebView2ControllerCompletedHandler Global Const $dtag_ICoreWebView2CreateCoreWebView2ControllerCompletedHandler = _ "Invoke hresult(hresult;ptr*);" ; ICoreWebView2Environment interface Global $oCoreWebView2Environment Global Const $sIID_ICoreWebView2Environment = "{B96D755E-0319-4E92-A296-23436F46A1FC}" Global Const $dtag_ICoreWebView2Environment = _ "CreateCoreWebView2Controller hresult(hwnd;ptr);" & _ "CreateWebResourceResponse hresult();" & _ "get_BrowserVersionString hresult();" & _ "add_NewBrowserVersionAvailable hresult();" & _ "remove_NewBrowserVersionAvailable hresult();" Global $oCoreWebView2Controller Global Const $sIID_ICoreWebView2Controller = "{4D00C0D1-9434-4EB6-8078-8697A560334F}" Global Const $dtag_ICoreWebView2Controller = _ "get_IsVisible hresult();" & _ "put_IsVisible hresult();" & _ "get_Bounds hresult();" & _ ( @AutoItX64 ? "put_Bounds hresult(struct*);" : "put_Bounds hresult(struct);" ) & _ "get_ZoomFactor hresult();" & _ "put_ZoomFactor hresult();" & _ "add_ZoomFactorChanged hresult();" & _ "remove_ZoomFactorChanged hresult();" & _ "SetBoundsAndZoomFactor hresult();" & _ "MoveFocus hresult();" & _ "add_MoveFocusRequested hresult();" & _ "remove_MoveFocusRequested hresult();" & _ "add_GotFocus hresult();" & _ "remove_GotFocus hresult();" & _ "add_LostFocus hresult();" & _ "remove_LostFocus hresult();" & _ "add_AcceleratorKeyPressed hresult();" & _ "remove_AcceleratorKeyPressed hresult();" & _ "get_ParentWindow hresult();" & _ "put_ParentWindow hresult();" & _ "NotifyParentWindowPositionChanged hresult();" & _ "Close hresult();" & _ "get_CoreWebView2 hresult(ptr*);" Global $oCoreWebView2, $pCoreWebView2 Global Const $sIID_ICoreWebView2 = "{76ECEACB-0462-4D94-AC83-423A6793775E}" Global Const $dtag_ICoreWebView2 = _ "get_Settings hresult(ptr*);" & _ "get_Source hresult();" & _ "Navigate hresult(wstr);" & _ "NavigateToString hresult(wstr);" & _ "add_NavigationStarting hresult(ptr;struct*);" & _ "remove_NavigationStarting hresult();" & _ "add_ContentLoading hresult();" & _ "remove_ContentLoading hresult();" & _ "add_SourceChanged hresult();" & _ "remove_SourceChanged hresult();" & _ "add_HistoryChanged hresult();" & _ "remove_HistoryChanged hresult();" & _ "add_NavigationCompleted hresult();" & _ "remove_NavigationCompleted hresult();" & _ "add_FrameNavigationStarting hresult();" & _ "remove_FrameNavigationStarting hresult();" & _ "add_FrameNavigationCompleted hresult();" & _ "remove_FrameNavigationCompleted hresult();" & _ "add_ScriptDialogOpening hresult();" & _ "remove_ScriptDialogOpening hresult();" & _ "add_PermissionRequested hresult();" & _ "remove_PermissionRequested hresult();" & _ "add_ProcessFailed hresult();" & _ "remove_ProcessFailed hresult();" & _ "AddScriptToExecuteOnDocumentCreated hresult(wstr;ptr);" & _ "RemoveScriptToExecuteOnDocumentCreated hresult();" & _ "ExecuteScript hresult(wstr;ptr);" & _ "CapturePreview hresult();" & _ "Reload hresult();" & _ "PostWebMessageAsJson hresult();" & _ "PostWebMessageAsString hresult();" & _ "add_WebMessageReceived hresult(ptr;struct*);" & _ "remove_WebMessageReceived hresult();" & _ "CallDevToolsProtocolMethod hresult();" & _ "get_BrowserProcessId hresult();" & _ "get_CanGoBack hresult();" & _ "get_CanGoForward hresult();" & _ "GoBack hresult();" & _ "GoForward hresult();" & _ "GetDevToolsProtocolEventReceiver hresult();" & _ "Stop hresult();" & _ "add_NewWindowRequested hresult();" & _ "remove_NewWindowRequested hresult();" & _ "add_DocumentTitleChanged hresult();" & _ "remove_DocumentTitleChanged hresult();" & _ "get_DocumentTitle hresult();" & _ "AddHostObjectToScript hresult();" & _ "RemoveHostObjectFromScript hresult();" & _ "OpenDevToolsWindow hresult();" & _ "add_ContainsFullScreenElementChanged hresult();" & _ "remove_ContainsFullScreenElementChanged hresult();" & _ "get_ContainsFullScreenElement hresult();" & _ "add_WebResourceRequested hresult();" & _ "remove_WebResourceRequested hresult();" & _ "AddWebResourceRequestedFilter hresult();" & _ "RemoveWebResourceRequestedFilter hresult();" & _ "add_WindowCloseRequested hresult();" & _ "remove_WindowCloseRequested hresult();" ; Project includes ;#include "..\Includes\WV2Interfaces.au3" #include "..\Includes\ObjectFromTag.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 interfaces and functions $pCoreWebView2CreateCoreWebView2EnvironmentCompletedHandler = _ ObjectFromTag( "CoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_", _ $dtag_ICoreWebView2CreateCoreWebView2EnvironmentCompletedHandler, _ $tCoreWebView2CreateCoreWebView2EnvironmentCompletedHandler, False, True ) ; $bPrint = True $pCoreWebView2CreateCoreWebView2ControllerCompletedHandler = _ ObjectFromTag( "CoreWebView2CreateCoreWebView2ControllerCompletedHandler_", _ $dtag_ICoreWebView2CreateCoreWebView2ControllerCompletedHandler, _ $tCoreWebView2CreateCoreWebView2ControllerCompletedHandler, False, True ) ; $bPrint = 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 ) ; Forces CoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_Invoke() below to be executed 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_CLOSE ExitLoop EndSwitch WEnd ; Cleanup DllClose( $hWebView2Loader ) EndFunc Func CoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_QueryInterface( $pSelf, $pRIID, $pObj ) ; Ret: long Par: ptr;ptr* ConsoleWrite( "CoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_QueryInterface()" & @CRLF & @CRLF ) Return 0 ; S_OK = 0x00000000 #forceref $pSelf, $pRIID, $pObj EndFunc Func CoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_AddRef( $pSelf ) ; Ret: dword ConsoleWrite( "CoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_AddRef()" & @CRLF & @CRLF ) Return 1 ; For AddRef/Release #forceref $pSelf EndFunc Func CoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_Release( $pSelf ) ; Ret: dword ConsoleWrite( "CoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_Release()" & @CRLF & @CRLF ) Return 1 ; For AddRef/Release #forceref $pSelf EndFunc ; Executed as a consequence of the CreateCoreWebView2EnvironmentWithOptions DllCall() 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 Func CoreWebView2CreateCoreWebView2ControllerCompletedHandler_QueryInterface( $pSelf, $pRIID, $pObj ) ; Ret: long Par: ptr;ptr* ConsoleWrite( "CoreWebView2CreateCoreWebView2ControllerCompletedHandler_QueryInterface()" & @CRLF & @CRLF ) Return 0 ; S_OK = 0x00000000 #forceref $pSelf, $pRIID, $pObj EndFunc Func CoreWebView2CreateCoreWebView2ControllerCompletedHandler_AddRef( $pSelf ) ; Ret: dword ConsoleWrite( "CoreWebView2CreateCoreWebView2ControllerCompletedHandler_AddRef()" & @CRLF & @CRLF ) Return 1 ; For AddRef/Release #forceref $pSelf EndFunc Func CoreWebView2CreateCoreWebView2ControllerCompletedHandler_Release( $pSelf ) ; Ret: dword ConsoleWrite( "CoreWebView2CreateCoreWebView2ControllerCompletedHandler_Release()" & @CRLF & @CRLF ) Return 1 ; For AddRef/Release #forceref $pSelf EndFunc ; 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.bing.com/" ) Return 0 ; S_OK = 0x00000000 #forceref $pSelf, $long EndFunc SciTE console output: Func CoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_QueryInterface( $pSelf, $pRIID, $pObj ) ; Ret: long Par: ptr;ptr* ConsoleWrite( "CoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_QueryInterface()" & @CRLF & @CRLF ) Return 0 ; S_OK = 0x00000000 #forceref $pSelf, $pRIID, $pObj EndFunc @error = 0 Func CoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_AddRef( $pSelf ) ; Ret: dword ConsoleWrite( "CoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_AddRef()" & @CRLF & @CRLF ) Return 1 ; For AddRef/Release #forceref $pSelf EndFunc @error = 0 Func CoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_Release( $pSelf ) ; Ret: dword ConsoleWrite( "CoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_Release()" & @CRLF & @CRLF ) Return 1 ; For AddRef/Release #forceref $pSelf EndFunc @error = 0 Func CoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_Invoke( $pSelf, $long, $ptr ) ; Ret: long Par: long;ptr* ConsoleWrite( "CoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_Invoke()" & @CRLF & @CRLF ) Return 0 ; S_OK = 0x00000000 #forceref $pSelf, $long, $ptr EndFunc @error = 0 Func CoreWebView2CreateCoreWebView2ControllerCompletedHandler_QueryInterface( $pSelf, $pRIID, $pObj ) ; Ret: long Par: ptr;ptr* ConsoleWrite( "CoreWebView2CreateCoreWebView2ControllerCompletedHandler_QueryInterface()" & @CRLF & @CRLF ) Return 0 ; S_OK = 0x00000000 #forceref $pSelf, $pRIID, $pObj EndFunc @error = 0 Func CoreWebView2CreateCoreWebView2ControllerCompletedHandler_AddRef( $pSelf ) ; Ret: dword ConsoleWrite( "CoreWebView2CreateCoreWebView2ControllerCompletedHandler_AddRef()" & @CRLF & @CRLF ) Return 1 ; For AddRef/Release #forceref $pSelf EndFunc @error = 0 Func CoreWebView2CreateCoreWebView2ControllerCompletedHandler_Release( $pSelf ) ; Ret: dword ConsoleWrite( "CoreWebView2CreateCoreWebView2ControllerCompletedHandler_Release()" & @CRLF & @CRLF ) Return 1 ; For AddRef/Release #forceref $pSelf EndFunc @error = 0 Func CoreWebView2CreateCoreWebView2ControllerCompletedHandler_Invoke( $pSelf, $long, $ptr ) ; Ret: long Par: long;ptr* ConsoleWrite( "CoreWebView2CreateCoreWebView2ControllerCompletedHandler_Invoke()" & @CRLF & @CRLF ) Return 0 ; S_OK = 0x00000000 #forceref $pSelf, $long, $ptr EndFunc @error = 0 CoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_AddRef() CoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_Invoke() IsObj( $oCoreWebView2Environment ) = 1 CoreWebView2CreateCoreWebView2ControllerCompletedHandler_AddRef() CoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_Release() CreateCoreWebView2EnvironmentWithOptions OK CoreWebView2CreateCoreWebView2ControllerCompletedHandler_AddRef() CoreWebView2CreateCoreWebView2ControllerCompletedHandler_Invoke IsObj( $oCoreWebView2Controller ) = 1 IsObj( $oCoreWebView2 ) = 1 CoreWebView2CreateCoreWebView2ControllerCompletedHandler_Release() CoreWebView2CreateCoreWebView2ControllerCompletedHandler_Release() According to the documentation for ICoreWebView2CreateCoreWebView2ControllerCompletedHandler interface the Invoke() method returns a pointer to the ICoreWebView2Controller interface as the last parameter. From this pointer the CoreWebView2Controller object can be created: ; 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.bing.com/" ) Return 0 ; S_OK = 0x00000000 #forceref $pSelf, $long EndFunc With the CoreWebView2Controller object, we can set the position and size of the embedded WebView window to match the client rectangle of the AutoIt GUI, and we can create the CoreWebView2 object. With this object we can open a web page. The 7z-file at bottom of first post has been updated.1 point
-
only 2 cents: Reading this web page I have copied/pasted some information from there, to here in this larsj's snippet trying to understand something more. ; To initialize the web view we must call the CreateCoreWebView2EnvironmentWithOptions() method with the following arguments: ; (1) The path to the installation folder of Edge. ; If this is null, the component should automatically locate the installation of Edge and use that. ; In practice, providing null does not work well, and the component is not able to detect the browser. ; ; (2) The path to the user data folder. ; If this is null, a subfolder in the current folder will be created. ; Beware that if your application is installed in Program Files, it will not be able to create it. ; Invoking this method will result in an access denied error (0x80070005 which is a HRESULT value for ERROR_ACCESS_DENIED). ; Therefore, make sure you provide a user folder to a writable location. ; ; (3) Optional environment options (as ICoreWebView2EnvironmentOptions*) to change the behavior of the web view. ; ; (4) A handler for the result of the asynchronous operation, that will be invoked if the environment was successfully created. ; Local $aRet = DllCall($hWebView2Loader, "long", "CreateCoreWebView2EnvironmentWithOptions", _ "wstr", "", _ ; (1) "wstr", @ScriptDir, _ ; (2) "ptr", Null, _ ; (3) "ptr", $pCoreWebView2CreateCoreWebView2EnvironmentCompletedHandler) ; (4) Well, if we set the parameter (2) with a path that is convenient for us, for example @ScriptDir, we don't have to worry about enabling read/write on the WebView2 user data folder within the AutoIt path.1 point
-
"One gui to rule all these pixels, one gui to find them, one gui to bring them all and in an array bind them"1 point