Leaderboard
Popular Content
Showing content with the highest reputation on 02/22/2021 in all areas
-
EasyCodeIt - cross-platform AutoIt implementation
argumentum and one other reacted to TheDcoder for a topic
I have posted a progress update about the current state of things in code at the new forum: https://forum.dtw.tools/d/5-easycodeit-progress-parsing-statements For those who missed the last interim update (not surprising for those who did, because the post was unfortunately the last post before the page break), I basically made a new forum where I am planning to post more shorter and frequent updates: Here is the same progress update for archival purposes: As I have mentioned in my post, please feel free to post any queries and suggestions in the forum. I plan to use the forum to share an increasing number of posts about many things, having a dedicated forum has it's advantages. For starters, I don't have to spam the AutoIt forum with all of those things and I can keep this thread short for more important updates. Not to mention that all of the discussion would be more organized with multiple threads. I'll be looking forward to see you there2 points -
This is based on this topic. With this UDF, you can define all the HotKeySet you want on any of the keyboards. The keys registered as HotKeySet are not sent to the active window. I also created a "Event-driven" mode for lengthy procedure. There is still the immediate action mode for short procedure. Note that in Event-driven mode, you will need to create an close loop to intercept the HotKey events. Events are asynchronous. In Event-driven mode only one procedure can be running at a given time. But immediate action procedure can interrupt a Event-driven procedure. All procedures are declared as actual function (without quotes). It is important that lengthy procedure should be declared as Event-driven, otherwise the system may become unstable. Version 2024-01-04 * Added support to {LEFT} and {RIGHT} keys * Added more information about keyboards in list * Added new parameter to _MKHKS_Initialize to exclude a specific keyboard from the list. To do so, you simply provide partial part (as a string) of the device name. Version 2024-01-03 * Added support to Send command, Hotkey must be set for the first keyboard. Version 2022-12-22 * Added support to register the same Hotkey on multiple keyboards (same or different functions) * Added possibility to unregister a Hotkey for a particular keyboard * Added validation on registering the same Hotkey twice It may happen that the list would provide more keyboards than they are actually connected. To exclude one particular keyboard, you could run the following example and test the hotkeys (0, 1, 2, ...) on each keyboard to see which ones are responding. Then you can provide partial string of the device to be excluded with the _MKHKS_Initialize function. #include "MKHKS-UDF.au3" Example() Func Example() HotKeySet("{END}", _Exit) Local $iNumKB = _MKHKS_Initialize() For $i = 0 To $iNumKB - 1 _MKHKS_Register_HotKey(String($i), _Test, $i, False) ; set hotkey to keyboard number (0, 1, 2,...) Next While Sleep(50) WEnd EndFunc ;==>Example Func _Exit() Exit EndFunc ;==>_Exit Func _Test() ConsoleWrite("Test succeeded - " & @HotKeyPressed & " was Key Pressed" & @CRLF) EndFunc ;==>_Test As usual if you have any suggestion, I would be very interested to hear them. MKHKS-UDF.zip1 point
-
$oObject.AddRef()In WebView2-2-0.au3 in the post above, a $oCoreWebView2NavigationStartingEventArgs.AddRef() code line is added after the object is created. This code line is required to prevent 0xC0000005 errors (STATUS_ACCESS_VIOLATION). It can be a little difficult to figure out when this line of code is needed. The easiest way is usually to run the code and see if the 0xC0000005 error occurs. In that case, try adding the code line and see if the error disappears. Global variablesThe Invoke() functions are defined and created based on description tags for callback interfaces and they are executed due to events. Therefore, the easiest way to pass data between these functions and the rest of the code is to use global variables. If there are many Invoke() functions, it can result in a fairly large number of global variables. There's not much to do about it. At least not in the program development phase. Once the program is complete, you may be able to group the variables into a single or a few global arrays. WebView2 projectThe WebView2 project has been used as a starting point for the examples above. If you are interested in a complete translation of the WebView2 API into AutoIt, keep an eye on the original project.1 point
-
Creating a WebView window through pseudo eventsThe CreateCoreWebView2EnvironmentWithOptions() function (DllCall) takes a pointer to an ICoreWebView2CreateCoreWebView2EnvironmentCompletedHandler callback interface as an input parameter. See e.g. WebView2-1-7.au3. As a consequence of the DllCall, the callback function CoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_Invoke() is executed. In the documentation for the Invoke() method you can read: Called to provide the implementer with the completion status and result of the corresponding asynchronous method call. The Invoke() method returns an ICoreWebView2Environment interface. The $oCoreWebView2Environment.CreateCoreWebView2Controller() method takes a pointer to an ICoreWebView2CreateCoreWebView2ControllerCompletedHandler callback interface as an input parameter. As a consequence of the method call, the callback function CoreWebView2CreateCoreWebView2ControllerCompletedHandler_Invoke() is executed. In the documentation for the Invoke() method you can read: Called to provide the implementer with the completion status and result of the corresponding asynchronous method call. The Invoke() method returns an ICoreWebView2Controller interface. The creation of the ICoreWebView2Environment and ICoreWebView2Controller interfaces required to create a WebView window appears to be implemented as a kind of pseudo-events to handle code running asynchronously. Creating a WebView window is about creating two callback interfaces and executing code in a DllCall function and a method function to call the corresponding Invoke() methods. Real events in a WebView windowAn example of real events (due to user actions that may occur multiple times) in a WebView window is NavigationStarting events as coded in WebView2-2-0.au3 (similar to WebView2-2-a.au3 but slightly updated (WebView2-2-a.au3 is a copy of the WebView2-2.au3 example here)) #AutoIt3Wrapper_Au3Check_Parameters=-d -w- 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 #AutoIt3Wrapper_UseX64=y Opt( "MustDeclareVars", 1 ) #include <MsgBoxConstants.au3> #include <WindowsConstants.au3> #include <GUIConstantsEx.au3> #include <WinAPICom.au3> #include <WinAPI.au3> Global $hGui ; Project includes #include "..\Includes\WV2Interfaces.au3" WebView2() Func WebView2() ; Create WebView2 GUI $hGui = GUICreate( "WebView2 Sample", 1200, 900, -1, -1, $WS_OVERLAPPEDWINDOW ) ; Initialize COM _WinAPI_CoInitialize( $COINIT_APARTMENTTHREADED ) ; Create callback interfaces and functions CoreWebView2CreateCoreWebView2EnvironmentCompletedHandlerCreate( True ) ; Create WebView window CoreWebView2CreateCoreWebView2ControllerCompletedHandlerCreate( True ) ; Create WebView window CoreWebView2NavigationStartingEventHandlerCreate( True ) ; Create event handler ; 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 ) ; Add NavigationStarting event handler Local $tEventRegistrationToken = DllStructCreate( "uint64" ) $oCoreWebView2.add_NavigationStarting( $pCoreWebView2NavigationStartingEventHandler, $tEventRegistrationToken ) ConsoleWrite( "DllStructGetData( $tEventRegistrationToken, 1 ) = " & DllStructGetData( $tEventRegistrationToken, 1 ) & @CRLF & @CRLF ) ; Forces CoreWebView2NavigationStartingEventHandler_Invoke() below to be executed ; Navigate to web page $oCoreWebView2.Navigate( "https://www.bing.com/" ) Return 0 ; S_OK = 0x00000000 #forceref $pSelf, $long EndFunc ; Copied from WV2Interfaces.au3 ; Executed as a consequence of $oCoreWebView2.add_NavigationStarting() above Func CoreWebView2NavigationStartingEventHandler_Invoke( $pSelf, $ptr1, $ptr2 ) ; Ret: long Par: ptr*;ptr* ConsoleWrite( "CoreWebView2NavigationStartingEventHandler_Invoke()" & @CRLF ) ; Create CoreWebView2NavigationStartingEventArgs object $oCoreWebView2NavigationStartingEventArgs = ObjCreateInterface( $ptr2, $sIID_ICoreWebView2NavigationStartingEventArgs, $dtag_ICoreWebView2NavigationStartingEventArgs ) ConsoleWrite( "IsObj( $oCoreWebView2NavigationStartingEventArgs ) = " & IsObj( $oCoreWebView2NavigationStartingEventArgs ) & @CRLF & @CRLF ) $oCoreWebView2NavigationStartingEventArgs.AddRef() ; Prevent the object from being deleted when the function ends ; Get navigation information Local $bIsUserInitiated, $bIsRedirected $oCoreWebView2NavigationStartingEventArgs.get_IsUserInitiated( $bIsUserInitiated ) $oCoreWebView2NavigationStartingEventArgs.get_IsRedirected( $bIsRedirected ) ; Confirm navigation If $bIsUserInitiated And Not $bIsRedirected Then Local $sUri $oCoreWebView2NavigationStartingEventArgs.get_Uri( $sUri ) If MsgBox( $MB_YESNO+$MB_ICONWARNING, "Navigation warning", "You are about to navigate to: " & $sUri & @CRLF & @CRLF & "Do you want to continue?" ) = $IDNO Then $oCoreWebView2NavigationStartingEventArgs.put_Cancel( True ) $oCoreWebView2.NavigateToString( "<h1>Navigation Canceled</h1><p>You chose to cancel navigation to the following URL: " & $sUri & "</p>" ) EndIf EndIf Return 0 ; S_OK = 0x00000000 #forceref $pSelf, $ptr1 EndFunc EventRegistrationTokenAt top of the code, three callback interfaces are now created: ; Create callback interfaces and functions CoreWebView2CreateCoreWebView2EnvironmentCompletedHandlerCreate( True ) ; Create WebView window CoreWebView2CreateCoreWebView2ControllerCompletedHandlerCreate( True ) ; Create WebView window CoreWebView2NavigationStartingEventHandlerCreate( True ) ; Create event handler The NavigationStarting event handler is added in CoreWebView2CreateCoreWebView2ControllerCompletedHandler_Invoke() ; Add NavigationStarting event handler Local $tEventRegistrationToken = DllStructCreate( "uint64" ) $oCoreWebView2.add_NavigationStarting( $pCoreWebView2NavigationStartingEventHandler, $tEventRegistrationToken ) ConsoleWrite( "DllStructGetData( $tEventRegistrationToken, 1 ) = " & DllStructGetData( $tEventRegistrationToken, 1 ) & @CRLF & @CRLF ) ; Forces CoreWebView2NavigationStartingEventHandler_Invoke() below to be executed Note the EventRegistrationToken used to add the event handler to the code. Such a token seems to be used in conjunction with most real event handlers. EventHandler_Invoke()An EventArgs object supports many real event handlers in obtaining information about the event: ; Copied from WV2Interfaces.au3 ; Executed as a consequence of $oCoreWebView2.add_NavigationStarting() above Func CoreWebView2NavigationStartingEventHandler_Invoke( $pSelf, $ptr1, $ptr2 ) ; Ret: long Par: ptr*;ptr* ConsoleWrite( "CoreWebView2NavigationStartingEventHandler_Invoke()" & @CRLF ) ; Create CoreWebView2NavigationStartingEventArgs object $oCoreWebView2NavigationStartingEventArgs = ObjCreateInterface( $ptr2, $sIID_ICoreWebView2NavigationStartingEventArgs, $dtag_ICoreWebView2NavigationStartingEventArgs ) ConsoleWrite( "IsObj( $oCoreWebView2NavigationStartingEventArgs ) = " & IsObj( $oCoreWebView2NavigationStartingEventArgs ) & @CRLF & @CRLF ) $oCoreWebView2NavigationStartingEventArgs.AddRef() ; Prevent the object from being deleted when the function ends ; Get navigation information Local $bIsUserInitiated, $bIsRedirected $oCoreWebView2NavigationStartingEventArgs.get_IsUserInitiated( $bIsUserInitiated ) $oCoreWebView2NavigationStartingEventArgs.get_IsRedirected( $bIsRedirected ) ; Confirm navigation If $bIsUserInitiated And Not $bIsRedirected Then Local $sUri $oCoreWebView2NavigationStartingEventArgs.get_Uri( $sUri ) If MsgBox( $MB_YESNO+$MB_ICONWARNING, "Navigation warning", "You are about to navigate to: " & $sUri & @CRLF & @CRLF & "Do you want to continue?" ) = $IDNO Then $oCoreWebView2NavigationStartingEventArgs.put_Cancel( True ) $oCoreWebView2.NavigateToString( "<h1>Navigation Canceled</h1><p>You chose to cancel navigation to the following URL: " & $sUri & "</p>" ) EndIf EndIf Return 0 ; S_OK = 0x00000000 #forceref $pSelf, $ptr1 EndFunc The 7z-file at bottom of first post has been updated.1 point
-
Thank you for the constructive reply first of all. I was not aware of the ctrl F5 with the line added to the script would show in verbose errors. It helps alot in the long run. I am new to scripting in general and right now just barely limping along. Purchased a book online but no courses on Autoit are out there and almost no education book wise. I figured it would be obvious I am not a scripting expert let alone an AutoIT expert. I included my whole script in the posting because that is what normally is requested by those that help out on the forums. In the past I have gotten some nice and informative help on these forums so I hope that in the future that continues. I am grateful for your look at the script and will go through it again with this new error information. Thank you for taking the time to look at it TheXMan!1 point
-
WinMerge / Github / StackOverFlow / Track - AutoIt Syntax Highlighting
FrancescoDiMuro reacted to mLipok for a topic
Thanks @FrancescoDiMuro fixed.1 point -
WinMerge / Github / StackOverFlow / Track - AutoIt Syntax Highlighting
mLipok reacted to FrancescoDiMuro for a topic
@mLipok Using ranges [] with just \w in it is not useful is this case. You can just use \w+ without any square brackets, so the final pattern should look like: '(?i)\$\w+' But, in this case, you may find substitution in a StringRegExpReplace() function (and many others wrong results), like the following example: Test() Func Test() Local $str = "This is a string with $dollar sign!" ConsoleWrite("Before: " & $str & @CRLF & _ "After : " & StringRegExpReplace($str, "\$(\w+)", "no more $1") & @CRLF) EndFunc With the result: https://regex101.com/r/sh4osq/1/1 point -
StringRegExp - Verbatim sequence
HurleyShanabarger reacted to AspirinJunkie for a topic
If you want to keep your \Q...\E construct, you can also solve it like this: Dim $sText_1 = "C:\Test (example)\\\Everything" Dim $sUserPattern_1 = "Test (example)\\\Every" ConsoleWrite(StringRegExp($sText_1, "^.+?\Q" & StringRegExpReplace($sUserPattern_1, '\\E', '\\E\\\\E\\Q') & "\E.+?$") & @TAB & "This fails nothing more" & @CRLF) Dim $sText_2 = "C:\Test (example)\Eallout" Dim $sUserPattern_2 = "Test (example)\Eall" ConsoleWrite(StringRegExp($sText_2, "^.+?" & _RegExEscape($sUserPattern_2) & ".+?$") & @TAB & "No problem here" & @CRLF) ; same wrapped in a function Func _RegExEscape($sString) Return "\Q" & StringRegExpReplace($sString, '\\E', '\\E\\\\E\\Q') & "\E" EndFunc Also a escape function is a lot more easier with this approach.1 point -
I'll try to find time to look at the code over the coming week.1 point
-
StringRegExp - Verbatim sequence
HurleyShanabarger reacted to MrCreatoR for a topic
The best solution is to escape specials chars: Dim $sText_1 = "C:\Test (example)\Everything" Dim $sUserPattern_1 = "Test (example)\Every" ConsoleWrite(StringRegExp($sText_1, "^.+?" & _StringRegExpEscapeChars($sUserPattern_1) & ".+?$") & @TAB & "No problem here" & @CRLF) Dim $sText_2 = "C:\Test (example)\Fallout" Dim $sUserPattern_2 = "Test (example)\Fall" ConsoleWrite(StringRegExp($sText_2, "^.+?" & _StringRegExpEscapeChars($sUserPattern_2) & ".+?$") & @TAB & "No problem here" & @CRLF) Func _StringRegExpEscapeChars($sString, $sChars = '') If StringStripWS($sChars, 8) = '' Then $sChars = '\]\[<>\^\\.+*?$(){}=!|:' EndIf Return StringRegExpReplace($sString, '([' & $sChars & '])', '\\\1') EndFunc1 point -
GIF Animation (cached)
dmob reacted to pixelsearch for a topic
The "problem" with my precedent pic is that it will always be placed at 0,0 in the GUI, which is maybe not what the user wants. If you want the pic to be placed at your exact coords (10,10 to 330,172) then you can create a child window having these exact coords, it's easy to script and the result looks fine : #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include "Cached GIF Animation.au3" Example() Func Example() $hGUI = GUICreate("GUI", 350, 250, -1, -1, $WS_SIZEBOX + $WS_SYSMENU + $WS_EX_COMPOSITED) GUISetBkColor(0xE0FFFF) $hGUI2 = GUICreate("", 330, 172, 10, 10, $WS_CHILD, -1, $hGUI) Local $IMG_Ctrl = _GUICtrlCreateAnimGIF("letrain.gif", -35, -90, 330 + 35, 172 + 90) GUISwitch($hGUI) Local $idButton_Close = GUICtrlCreateButton("close", 255, 190, 85, 25) GUISetState(@SW_SHOW, $hGUI) GUISetState(@SW_SHOW, $hGUI2) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE,$idButton_Close ExitLoop EndSwitch WEnd GUIDelete() EndFunc ;==>Example Nine's way (cropping it online) is sure the quickest way to do it, but it's interesting to know that we can find a solution in pure AutoIt language... while using the original animated gif1 point -
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.1 point
-
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 EndFunc1 point
-
Vertical Centering of Label Text
Zmy 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 EndFunc1 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
-
GOTO
Skysnake reacted to JockoDundee for a topic
Actually, the problem with GOTO is not where it goes to; it’s that it doesn’t come BACK FROM1 point -
I hope soon I find time to provide new features and examples based on the knowledge which I gather thanks to this above mentioned book. btw. Today I also buy this one: I hope it will be delivered to me sometime in a month, so it is possible that after the summer vacation, sometime in about half a year, I will have the opportunity to present new curiosities.1 point
-
You do it this way: #include <GuiMenu.au3> ; Create GUI. $hGui = GUICreate("Autoit GUI", 200, 100) $hMenu = _GUICtrlMenu_CreateMenu() _GUICtrlMenu_InsertMenuItem( $hMenu, 0, "none" ) $hMain = _GUICtrlMenu_CreateMenu( $MNS_MODELESS ) _GUICtrlMenu_InsertMenuItem( $hMain, 0, "none", 0, $hMenu ) _GUICtrlMenu_SetMenu( $hGui, $hMain ) ; Crate label to control progress. $label = GUICtrlCreateLabel("Working: " , 60, 30, 160) ; Set start time point script. $startPoint = 0 ; Show GUI. GUISetState(@SW_SHOW) ; Loop until the user exits. While 1 ; Set new time to label. GUICtrlSetData($label, "Working: " & $startPoint & "%") ; add point $startPoint += 1 ; When point is above 100 reset If $startPoint >= 100 Then $startPoint = 0 ; Listen signal from GUI. Switch GUIGetMsg() Case -3 Exit EndSwitch WEnd1 point
-
Help File/Documentation Issues. (Discussion Only)
Skysnake reacted to seadoggie01 for a topic
There isn't output listed anywhere, you have to run the programs (I get it though, I looked for it too)1 point -
I have a pair of DOS batch scripts (one on each machine) which in turn launch a VB script, that are triggered twice daily, 11:00 and 23:00, by windows scheduler. The triggers are offset such that the emails arrive simultaneously in my gmail account, one says NB3 should be rebooting and the other says NB3 has just rebooted. I have been running these scripts for several years now and never get tired of deleting them as soon as they arrive in my inbox. On several occasions they have alerted me that NB3 has gone down. I did it this way as I had no need or desire to delve into the complexities of Outlook. This is not an AutoIt solution but I thought I would throw it in the ring. It demonstrates how to send emails from your gmail account. I keep my little tools in C:\WinBin My android devices all ping an audio alert whenever an email arrives and it gives me great satisfaction to hear them all go off at once around the house, much to the consternation of visitors. :: With no args this will send an email "%COMPUTERNAME% reboot ok %date% %time%" :: With -pre it will send a prealert email saying arg1 sb rebooting @echo off cd C:\WinBin set To=YOUREMAIL@gmail.com set Subj=%COMPUTERNAME% reboot ok %date% %time% if .%1==.-pre set Subj=%2 sb rebooting %date% %time% set Body=%Subj% set From=YOUREMAIL@gmail.com set Serv=smtp.gmail.com set Auth=YOUREMAIL@gmail.com set Pass=YOURPASSWORD set fileattach= call :createVBS email-bat.vbs call :send %From% %To% "%Subj%" "%Body%" %Serv% %Auth% %Pass% echo email has been sent (if parameters were correct) if exist email-bat.vbs del email-bat.vbs >nul goto :EOF exit :send echo (echo) cscript.exe /nologo "%vbsfile%" %1 %2 %3 %4 %5 %6 %7 %8 cscript.exe /nologo "%vbsfile%" %1 %2 %3 %4 %5 %6 %7 %8 goto :EOF :createVBS set "vbsfile=%~1" if exist "%vbsfile%" del "%vbsfile%" >nul set cdoSchema=http://schemas.microsoft.com/cdo/configuration echo > "%vbsfile%" Set objArgs = WScript.Arguments echo >>"%vbsfile%" Set objEmail = CreateObject("CDO.Message") echo >>"%vbsfile%" objEmail.From = objArgs(0) echo >>"%vbsfile%" objEmail.To = objArgs(1) echo >>"%vbsfile%" objEmail.Subject = objArgs(2) echo >>"%vbsfile%" objEmail.Textbody = objArgs(3) if defined fileattach echo >>"%vbsfile%" objEmail.AddAttachment "%fileattach%" echo >>"%vbsfile%" with objEmail.Configuration.Fields echo >>"%vbsfile%" .Item ("%cdoSchema%/sendusing") = 2 ' not local, smtp echo >>"%vbsfile%" .Item ("%cdoSchema%/smtpserver") = objArgs(4) :: 465 for Gmail. Other values for other servers. echo >>"%vbsfile%" .Item ("%cdoSchema%/smtpserverport") = 465 echo >>"%vbsfile%" .Item ("%cdoSchema%/smtpauthenticate") = 1 ' cdobasic echo >>"%vbsfile%" .Item ("%cdoSchema%/sendusername") = objArgs(5) echo >>"%vbsfile%" .Item ("%cdoSchema%/sendpassword") = objArgs(6) :: True for Gmail, False for "other" ::echo >>"%vbsfile%" .Item ("%cdoSchema%/smtpusessl") = False echo >>"%vbsfile%" .Item ("%cdoSchema%/smtpusessl") = True echo >>"%vbsfile%" .Item ("%cdoSchema%/smtpconnectiontimeout") = 25 echo >>"%vbsfile%" .Update echo >>"%vbsfile%" end with echo >>"%vbsfile%" objEmail.Send goto :EOF exit1 point
-
I think this was fixed by @jpm https://www.autoitscript.com/trac/autoit/ticket/3682 We should wait for @Jon approval, and releasing new version .1 point
-
Script becomes way slower after a msgbox - (Moved)
Professor_Bernd reacted to Jon for a topic
Public beta uploaded.1 point -
Fixed it today.1 point
-
Resize control
pixelsearch reacted to LarsJ for a topic
On my PC it's dots but that probably depends on the theme. #include <GUIConstants.au3> #include <WinAPI.au3> Opt( "MustDeclareVars", 1 ) Global Const $SBS_SIZEBOX = 0x08 Global Const $SBS_SIZEGRIP = 0x10 Global $hGui, $hSizebox Example() Func Example() $hGui = GUICreate( "Resize corner", 300, 200, -1, 300, $WS_OVERLAPPEDWINDOW ) $hSizebox = _WinAPI_CreateWindowEx( 0, "Scrollbar", "", $WS_CHILD+$WS_VISIBLE+$SBS_SIZEBOX, 300-20, 200-20, 20, 20, $hGui ) ; $SBS_SIZEBOX or $SBS_SIZEGRIP GUIRegisterMsg( $WM_SIZE, "WM_SIZE" ) GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd GUIDelete( $hGui ) Exit EndFunc Func WM_SIZE( $hWnd, $iMsg, $wParam, $lParam ) Local $aSize = WinGetClientSize( $hGui ) WinMove( $hSizebox, "", $aSize[0] - 20, $aSize[1] - 20 ) EndFunc1 point