Help Center

CWebView2.CWebView2CreateCoreWebView2ControllerCompletedHandlermethod

Implementation of the ICoreWebView2CreateCoreWebView2ControllerCompletedHandler callback interface.

WebViewmethoddoc-orphan
No implementation located. This member is documented, but the source scan found no matching declaration. It is likely declared in a header this scan does not resolve, or provided by a macro.

Syntax

FUNCTION Invoke (BYVAL errorCode AS HRESULT, BYVAL createdController AS Afx_ICoreWebView2Controller PTR) AS HRESULT

Parameters

NameDescription
[Invoke](#invoke)Provides the result of the corresponding asynchronous method.
errorCode[in] An HRESULT code to check for errors.
createdController[in] A pointer to the ICoreWebView2Controller interface.

Description

Implementation of the ICoreWebView2CreateCoreWebView2ControllerCompletedHandler callback interface.

The controller is created during the processing of the Invoke method of the CWebView2CreateCoreWebView2EnvironmentCompletedHandlerInternal class by calloing the CreateCoreWebView2Controller of the ICoreWebView2Environment interface. A pointer to the ICoreWebView2Controller interface is provided by WebViewin the Invoke method of the CWebView2CreateCoreWebView2ControllerCompletedHandlerInternal class.

Examples

FUNCTION CWebView2CreateCoreWebView2EnvironmentCompletedHandlerInternal.Invoke (BYVAL errorCode AS HRESULT, BYVAL createdEnvironment AS Afx_ICoreWebView2Environment PTR) AS HRESULT CWV2_DP("") IF errorCode = S_OK AND m_pWebView2 <> NULL THEN

m_pWebView2->m_pEnv = createdEnvironment
  m_pWebView2->m_pEnv->AddRef
  ' // Create controller
  DIM pController AS CWebView2CreateCoreWebView2ControllerCompletedHandlerInternal PTR
  pController = NEW CWebView2CreateCoreWebView2ControllerCompletedHandlerInternal(m_pWebView2)
  m_pWebView2->m_pEnv->CreateCoreWebView2Controller(m_pWebView2->m_hWnd, cast(ANY PTR, pController))
  ' // Get the runtime versión
  DIM wszVersion AS LPWSTR
  IF m_pWebView2->m_pEnv->get_BrowserVersionString(@wszVersion) = S_OK THEN
     m_pWebView2->m_BrowserVersion = *wszVersion
     CoTaskMemFree(wszVersion)
  END IF

END IF RETURN S_OK END FUNCTION

' ######################################################################################## ' CWebView2CreateCoreWebView2ControllerCompletedHandler class ' Implementation of the ICoreWebView2CreateCoreWebView2ControllerCompletedHandler callback interface. ' ######################################################################################## TYPE CWebView2CreateCoreWebView2ControllerCompletedHandler EXTENDS OBJECT

DECLARE VIRTUAL FUNCTION QueryInterface (BYVAL riid AS REFIID, BYVAL ppvObject AS LPVOID PTR) AS HRESULT DECLARE VIRTUAL FUNCTION AddRef () AS ULONG DECLARE VIRTUAL FUNCTION Release () AS ULONG DECLARE VIRTUAL FUNCTION Invoke (BYVAL errorCode AS HRESULT, BYVAL createdController AS Afx_ICoreWebView2Controller PTR) AS HRESULT

DECLARE CONSTRUCTOR DECLARE DESTRUCTOR

' Reference count for COM refCount AS ULONG = 0

END TYPE ' ########################################################################################

' ===================================================================================== ' Constructor ' ===================================================================================== PRIVATE CONSTRUCTOR CWebView2CreateCoreWebView2ControllerCompletedHandler CWV2_DP("") END CONSTRUCTOR ' ===================================================================================== ' ===================================================================================== ' Destructor ' ===================================================================================== PRIVATE DESTRUCTOR CWebView2CreateCoreWebView2ControllerCompletedHandler CWV2_DP("") END DESTRUCTOR ' =====================================================================================

' ======================================================================================== ' Returns pointers to the implemented classes and supported interfaces. ' It is never called by WebView, so we simply return S_OK. ' ======================================================================================== PRIVATE FUNCTION CWebView2CreateCoreWebView2ControllerCompletedHandler.QueryInterface (BYVAL riid AS REFIID, BYVAL ppvObj AS LPVOID PTR) AS HRESULT CWV2_DP("") RETURN S_OK END FUNCTION ' =====================================================================================

' ======================================================================================== ' Increments the reference count for an interface on an object. This method should be called ' for every new copy of a pointer to an interface on an object. ' ======================================================================================== PRIVATE FUNCTION CWebView2CreateCoreWebView2ControllerCompletedHandler.AddRef () AS ULONG refCount += 1 CWV2_DP(WSTR(refCount)) RETURN refCount END FUNCTION ' ========================================================================================

' ======================================================================================== ' Decrements the reference count for an interface on an object. ' If the count reaches 0, it deletes itself. ' ======================================================================================== PRIVATE FUNCTION CWebView2CreateCoreWebView2ControllerCompletedHandler.Release () AS ULONG refCount -= 1 CWV2_DP(WSTR(refCount)) IF refCount = 0 THEN

CWV2_DP("Delete class")
  Delete @this

END IF RETURN refCount END FUNCTION ' =====================================================================================

' ===================================================================================== PRIVATE FUNCTION CWebView2CreateCoreWebView2ControllerCompletedHandler.Invoke (BYVAL errorCode AS HRESULT, BYVAL createdController AS Afx_ICoreWebView2Controller PTR) AS HRESULT CWV2_DP("") RETURN S_OK END FUNCTION ' =====================================================================================

' ######################################################################################## ' CWebView2CreateCoreWebView2ControllerCompletedHandlerInternal class ' Implementation of the ICoreWebView2CreateCoreWebView2ControllerCompletedHandler callback interface. ' ########################################################################################

' ===================================================================================== ' Constructor ' ===================================================================================== CONSTRUCTOR CWebView2CreateCoreWebView2ControllerCompletedHandlerInternal (BYVAL pWebView2 AS CWebView2 PTR) CWV2_DP("pWebView2: " & WSTR(pWebView2) & " - this: " & WSTR(@this)) m_pWebView2 = pWebView2 END CONSTRUCTOR ' ===================================================================================== ' ===================================================================================== ' Destructor ' ===================================================================================== DESTRUCTOR CWebView2CreateCoreWebView2ControllerCompletedHandlerInternal CWV2_DP(WSTR(@this)) END DESTRUCTOR ' =====================================================================================

' ======================================================================================== ' Returns pointers to the implemented classes and supported interfaces. ' It is never called by WebView, so we simply return S_OK. ' ======================================================================================== FUNCTION CWebView2CreateCoreWebView2ControllerCompletedHandlerInternal.QueryInterface (BYVAL riid AS REFIID, BYVAL ppvObj AS LPVOID PTR) AS HRESULT CWV2_DP("") RETURN S_OK END FUNCTION ' =====================================================================================

' ======================================================================================== ' Increments the reference count for an interface on an object. This method should be called ' for every new copy of a pointer to an interface on an object. ' ======================================================================================== FUNCTION CWebView2CreateCoreWebView2ControllerCompletedHandlerInternal.AddRef () AS ULONG refCount += 1 CWV2_DP(WSTR(refCount)) RETURN refCount END FUNCTION ' ========================================================================================

' ======================================================================================== ' Decrements the reference count for an interface on an object. ' If the count reaches 0, it deletes itself. ' ======================================================================================== FUNCTION CWebView2CreateCoreWebView2ControllerCompletedHandlerInternal.Release () AS ULONG refCount -= 1 CWV2_DP(WSTR(refCount)) IF refCount = 0 THEN

CWV2_DP("Delete class")
  Delete @this

END IF RETURN refCount END FUNCTION ' =====================================================================================

' ===================================================================================== FUNCTION CWebView2CreateCoreWebView2ControllerCompletedHandlerInternal.Invoke (BYVAL errorCode AS HRESULT, BYVAL createdController AS Afx_ICoreWebView2Controller PTR) AS HRESULT CWV2_DP(WSTR(errorCode)) IF errorCode = S_OK AND m_pWebView2 <> NULL THEN

m_pWebView2->m_pController = createdController
  m_pWebView2->m_pController->AddRef
  CWV2_DP("createdController: " & WSTR(createdController))
  ' // Get a pointer to the ICoreWebView2 inerface
  DIM pCoreWebView2 AS Afx_ICoreWebView2 PTR
  IF createdController->get_CoreWebView2(@pCoreWebView2) = S_OK THEN
     m_pWebView2->m_pCoreWebView2 = pCoreWebView2
     ' Don't call AddRef here; it is already AddRef'ed
     ' // Make the WebView2 control visible
     createdController->put_IsVisible(TRUE)
     ' // adjust the control to the client area of the window
     DIM rc AS RECT
     GetClientRect(m_pWebView2->m_hwnd, @rc)
     createdController->put_Bounds(rc)
  END IF

END IF RETURN S_OK END FUNCTION ' =====================================================================================

Reference