Quantcast
Channel: VBForums - CodeBank - Visual Basic 6 and earlier
Viewing all articles
Browse latest Browse all 1448

excel vba Webview2 Demo(edge Chromium)

$
0
0
Code:

'need rc6.dll

Option Explicit
Private Declare Function WindowFromAccessibleObject Lib "oleacc" (ByVal pacc As Object, phwnd As Long) As Long
Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
Private Declare Function FindWindowEx Lib "user32.dll" Alias "FindWindowExA" (ByVal hWndParent As Long, ByVal hWndChildAfter As Long, ByVal lpszClass As String, ByVal lpszWindow As String) As Long
Dim WebHwnd As Long, hform As Long
Dim WithEvents Web1  As cWebView2
Private Const SW_SHOWMAXIMIZED = 3
Private Sub CommandButton1_Click()
    Call WindowFromAccessibleObject(Me, hform)
    Set Web1 = New cWebView2
    Dim OK As Boolean
    OK = Web1.BindTo(hform, , GetEdgeWebViewPath)
    If Not OK Then MsgBox "err:": Exit Sub
    WebHwnd = FindWindowEx(hform, 0, "Chrome_WidgetWin_0", vbNullString)
    ShowWindow WebHwnd, SW_SHOWMAXIMIZED
    Web1.Navigate "https://www.baidu.com"
    Web1.ExecuteScript "alert(33+44)"
End Sub

 
Function GetEdgeWebViewPath() As String
  On Error Resume Next
  Dim WshShell As Object, WebView2_Version As String
  Dim RegPath As String, location As String
  Set WshShell = CreateObject("Wscript.Shell")
  RegPath = "HKEY_CURRENT_USER\SOFTWARE\WOW6432Node\Microsoft\EdgeUpdate\Clients\{F3017226-FE2A-4295-8BDF-00C3A9A7E4C5}\"
  location = WshShell.RegRead(RegPath & "location")
  If location = "" Then
        RegPath = Replace(RegPath, "\WOW6432Node", "")
        location = WshShell.RegRead(RegPath & "location")
  End If
  If location <> "" Then GetEdgeWebViewPath = location & "\" & WshShell.RegRead(RegPath & "PV")
End Function


Viewing all articles
Browse latest Browse all 1448

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>