Page 1 of 4

TWebView:Destroy method does not close the window.

PostPosted: Thu Jul 28, 2022 12:28 pm
by Horizon
Hi Antonio,

My example is below.
Code: Select all  Expand view
#include "FiveWin.ch"
STATIC oWnd, oBar
function Main()
PUBLIC oWebView

   DEFINE WINDOW oWnd MDI

   DEFINE BUTTONBAR oBar 3D OF oWnd SIZE 60,60

   DEFINE BUTTON PROMPT "Open Google" OF oBar  ACTION Open_Google()
   DEFINE BUTTON PROMPT "Close Google" OF oBar  ACTION Close_Google()

   ACTIVATE WINDOW oWnd

return nil


PROCEDURE Open_Google()
LOCAL oWeb, cHtml:="https://www.google.com/"
 
    oWebView := TWebView():New()
    oWebView:Navigate(cHtml)
    oWebView:Run() 
    oWebView:Destroy()

return nil

PROCEDURE Close_Google()
    oWebView:Destroy()
// What should I write here to close google window?
   
return nil


When I click "Close Google", twebview does not close the window. Can you help me please?

Re: TWebView:Destroy method does not close the window.

PostPosted: Thu Jul 28, 2022 2:13 pm
by Horizon
Hi,

I have add these lines.
Code: Select all  Expand view
#pragma BEGINDUMP

#include <hbapi.h>

void webview_terminate( void * w );

HB_FUNC( WEBVIEW_TERMINATE )
{
   webview_terminate( hb_parptr( 1 ) );
}
#pragma ENDDUMP


Code: Select all  Expand view
PROCEDURE Close_Google()
//  oWebView:Destroy()
// What should I write here to close google windows?

   If !HB_ISNIL(oWebView:hWebView) //.and. !HB_ISNIL(oWebView:oWndDlgContainer)
      WEBVIEW_TERMINATE(oWebView:hWebView)
      WEBVIEW_DESTROY(oWebView:hWebView)
      SendMessage(oWebView:hWebView, WM_CLOSE)
   EndIf   
return nil


but I could not compiled. This error is given.
Code: Select all  Expand view
┌────────────────────────────────────────────────────────────────────────────┐
│ FiveWin for Harbour 22.06 (VS32bits) Jun. 2022  Harbour development power  │▄
(c) FiveTech 1993-2022 for Microsoft Windows 9X/NT/200X/ME/XP/Vista/7/8/10 │█
└────────────────────────────────────────────────────────────────────────────┘█
  ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
**********************************************************************
** Visual Studio 2022 Developer Command Prompt v17.2.6
** Copyright (c) 2022 Microsoft Corporation
**********************************************************************
[vcvarsall.bat] Environment initialized for: 'x86'
Compiling...
Harbour 3.2.0dev (r2104281802)
Copyright (c) 1999-2021, https://harbour.github.io/
Compiling 'deneme1.prg' and generating preprocessed output to 'deneme1.ppo'...
Lines 5050, Functions/Procedures 3
Generating C source output to 'deneme1.c'... Done.
deneme1.prg(21) Warning W0001  Ambiguous reference 'OWEBVIEW'
deneme1.prg(22) Warning W0001  Ambiguous reference 'OWEBVIEW'
deneme1.prg(23) Warning W0001  Ambiguous reference 'OWEBVIEW'
deneme1.prg(26) Warning W0006  Procedure returns value
deneme1.prg(32) Warning W0001  Ambiguous reference 'OWEBVIEW'
deneme1.prg(33) Warning W0001  Ambiguous reference 'OWEBVIEW'
deneme1.prg(34) Warning W0001  Ambiguous reference 'OWEBVIEW'
deneme1.prg(35) Warning W0001  Ambiguous reference 'OWEBVIEW'
deneme1.prg(37) Warning W0006  Procedure returns value
x86 için Microsoft (R) C/C++ İyileştirmeli Derleyicisi Sürüm 19.32.31332
Telif Hakkı (C) Microsoft Corporation. Tüm hakları saklıdır.

deneme1.c
deneme1.obj : error LNK2019: çözümlenmemiş dış sembol "void __cdecl webview_terminate(void *)" (?webview_terminate@@YAXP
AX@Z) için _HB_FUN_WEBVIEW_TERMINATE işlevinde başvuruldu
deneme1.exe : fatal error LNK1120: 1 çözümlenmemiş dışlar
* Linking errors *

C:\fwh\samples>

Re: TWebView:Destroy method does not close the window.

PostPosted: Thu Jul 28, 2022 3:45 pm
by Antonio Linares
Dear Hakan,

IMO this is the way to go, anyhow when a child is closed, the app closes and still don't know why:
Code: Select all  Expand view
#include "FiveWin.ch"

function Main()
 
   local oWnd, oBar

   DEFINE WINDOW oWnd MDI

   DEFINE BUTTONBAR oBar 3D OF oWnd SIZE 60, 60

   DEFINE BUTTON PROMPT "Open Google" OF oBar ACTION Open_Google( oWnd )

   ACTIVATE WINDOW oWnd

return nil

function Open_Google( oWnd )

    LOCAL cHtml:="https://www.google.com/"
    local oWndChild, oWebView

    DEFINE WINDOW oWndChild MDICHILD OF oWnd
   
    oWebView := TWebView():New()
    ShowWindow( oWebView:GetWindow(), 0 )
    oWebView:SetParent( oWndChild )
    oWebView:Navigate(cHtml)

    ACTIVATE WINDOW oWndChild ;
       ON RESIZE oWebView:SetParent( oWndChild )

return nil

Re: TWebView:Destroy method does not close the window.

PostPosted: Thu Jul 28, 2022 4:00 pm
by Giovany Vecchi
In the class I was creating, I did it like this and had no problems.

Code: Select all  Expand view
     WEBVIEW_TERMINATE(::hWebView)
      WEBVIEW_DESTROY(::hWebView)
      SendMessage( ::hWebView, WM_CLOSE)
 

Re: TWebView:Destroy method does not close the window.

PostPosted: Thu Jul 28, 2022 4:39 pm
by Horizon
:shock:

Re: TWebView:Destroy method does not close the window.

PostPosted: Fri Jul 29, 2022 6:09 am
by Antonio Linares
Dear Giovany and Hakan,

IMO WebView_Terminate() has no sense to be called as we don't need WebView_Run() as we use FWH own "run" main loop

Given that, I have just tried this, following Giovany advise:
Code: Select all  Expand view
   ACTIVATE WINDOW oWndChild ;
       ON RESIZE oWebView:SetParent( oWndChild ) ;
       VALID ( oWebView:Destroy(), SendMessage( oWebView:GetWindow(), WM_CLOSE ), .T. )

and the app keeps ending without any created log, so there is no a GPF
I have also tried this:
Code: Select all  Expand view
   ACTIVATE WINDOW oWndChild ;
       ON RESIZE oWebView:SetParent( oWndChild ) ;
       VALID ( SetParent( oWebView:GetWindow(), GetDesktopWindow() ), oWebView:Destroy(), SendMessage( oWebView:GetWindow(), WM_CLOSE ), .T. )
 

and
Code: Select all  Expand view
   ACTIVATE WINDOW oWndChild ;
       ON RESIZE oWebView:SetParent( oWndChild ) ;
       VALID ( SetParent( oWebView:GetWindow(), 0 ), oWebView:Destroy(), SendMessage( oWebView:GetWindow(), WM_CLOSE ), .T. )

with same exiting result

Re: TWebView:Destroy method does not close the window.

PostPosted: Fri Jul 29, 2022 6:59 am
by Horizon
Hi Antonio,

Thank you for your effort. Is it related to webview.dll? Should we ask for it to Steffan?

Re: TWebView:Destroy method does not close the window.

PostPosted: Fri Jul 29, 2022 11:56 am
by Antonio Linares
Dear Hakan,

I am thinking about low level debugging it using Visual Studio, unless a solution appears.

I don't think Steffen may be able to help on that...

Re: TWebView:Destroy method does not close the window.

PostPosted: Fri Jul 29, 2022 7:26 pm
by Giovany Vecchi
Linares, it's not the window handle but the WebView handle.

Code: Select all  Expand view

      ::hWebView  := WEBVIEW_CREATE()
      WEBVIEW_DESTROY(::hWebView)
      SendMessage( ::hWebView, WM_CLOSE)
 

Re: TWebView:Destroy method does not close the window.

PostPosted: Sat Jul 30, 2022 1:40 am
by Antonio Linares
Dear Giovany,

thanks for pointing it, anyhow the behavior remains the same:
Code: Select all  Expand view
#include "FiveWin.ch"

function Main()
 
   local oWnd, oBar

   DEFINE WINDOW oWnd MDI

   DEFINE BUTTONBAR oBar 3D OF oWnd SIZE 60, 60

   DEFINE BUTTON PROMPT "Open Google" OF oBar ACTION Open_Google( oWnd )

   ACTIVATE WINDOW oWnd

return nil

function Open_Google( oWnd )

    LOCAL cHtml:="https://www.google.com/"
    local oWndChild, oWebView

    DEFINE WINDOW oWndChild MDICHILD OF oWnd
   
    oWebView := TWebView():New()
    ShowWindow( oWebView:GetWindow(), 0 )
    oWebView:SetParent( oWndChild )
    oWebView:Navigate(cHtml)

    ACTIVATE WINDOW oWndChild ;
       ON RESIZE oWebView:SetParent( oWndChild ) ;
       VALID ( SendMessage( oWebView:hWebView, WM_CLOSE ), .T. )

return nil

Re: TWebView:Destroy method does not close the window.

PostPosted: Sat Jul 30, 2022 1:46 am
by Antonio Linares
Ok, this is a possible workaround. The reason it is explained here:

https://githubhot.com/repo/MicrosoftEdge/WebView2Feedback/issues/2156
This memory leak happens because the program doesn't enter the message loop. When there is no message loop ICoreWebView2CreateCoreWebView2ControllerCompletedHandler::Invoke() isn't called. If it was called everything is fine, and the webview2 calls Release().

Wow! It can easily be fixed by storing a flag if ICoreWebView2CreateCoreWebView2ControllerCompletedHandler:Invoke() is called. If the flag is false when its destroyed, call release()

Code: Select all  Expand view
#include "FiveWin.ch"

function Main()
 
   local oWnd, oBar

   DEFINE WINDOW oWnd MDI

   DEFINE BUTTONBAR oBar 3D OF oWnd SIZE 60, 60

   DEFINE BUTTON PROMPT "Open Google" OF oBar ACTION Open_Google( oWnd )

   ACTIVATE WINDOW oWnd

return nil

function Open_Google( oWnd )

    LOCAL cHtml:="https://www.google.com/"
    local oWndChild, oWebView

    DEFINE WINDOW oWndChild MDICHILD OF oWnd
   
    oWebView := TWebView():New()
    ShowWindow( oWebView:GetWindow(), 0 )
    oWebView:SetParent( oWndChild )
    oWebView:Navigate(cHtml)
    oWebView:Run()

    ACTIVATE WINDOW oWndChild ;
       ON RESIZE oWebView:SetParent( oWndChild )

return nil

Re: TWebView:Destroy method does not close the window.

PostPosted: Sat Jul 30, 2022 1:53 am
by Antonio Linares
This is another possible solution, based on Giovany suggestion, but again we can not have more than one WebView as Method Run() implements its own message processing loop:
Code: Select all  Expand view
#include "FiveWin.ch"

function Main()
 
   local oWnd, oBar

   DEFINE WINDOW oWnd MDI

   DEFINE BUTTONBAR oBar 3D OF oWnd SIZE 60, 60

   DEFINE BUTTON PROMPT "Open Google" OF oBar ACTION Open_Google( oWnd )

   ACTIVATE WINDOW oWnd

return nil

function Open_Google( oWnd )

    LOCAL cHtml:="https://www.google.com/"
    local oWndChild, oWebView

    DEFINE WINDOW oWndChild MDICHILD OF oWnd
   
    oWebView := TWebView():New()
    ShowWindow( oWebView:GetWindow(), 0 )
    oWebView:SetParent( oWndChild )
    oWebView:Navigate(cHtml)
    oWebView:Run()

    ACTIVATE WINDOW oWndChild ;
       ON RESIZE oWebView:SetParent( oWndChild ) ;
       VALID ( SendMessage( oWebView:hWebView, WM_CLOSE ), .T. )  

return nil

Re: TWebView:Destroy method does not close the window.

PostPosted: Sat Jul 30, 2022 2:09 am
by Antonio Linares
I have opened a new issue on https://github.com/webview/webview explaining it to Steffen:

https://github.com/webview/webview/issues/825

Lets see what they say

Re: TWebView:Destroy method does not close the window.

PostPosted: Sun Jul 31, 2022 12:12 pm
by Antonio Linares
The library does run a message loop temporarily just for WebView2 initialization regardless of whether you call webview_run(). ICoreWebView2CreateCoreWebView2ControllerCompletedHandler will therefore have been invoked already by the time you would normally call webview_run()

Re: TWebView:Destroy method does not close the window.

PostPosted: Sun Jul 31, 2022 5:44 pm
by Giovany Vecchi
Hello, I'm using fw 1909 and I created a webview class before the release of fw 2206. I intend to get the newest version by the beginning of next year.
In this class that I'm not using I did several tests with webview and they work well.
I created an example compiled with the sources and posted it in 2 links.
I have no idea what the fivewin webview class looks like at the moment, but I think my class can serve as an example.

ftp://fwcontrib:123@giovanyvecchi.no-ip.info:97/MyWebView
https://app.box.com/s/dklixp7uu9ni5sz8llqt3nq1zqp13kyb
Image