FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour TWebView:Destroy method does not close the window.
Posts: 1387
Joined: Fri May 23, 2008 01:33 PM
TWebView:Destroy method does not close the window.
Posted: Thu Jul 28, 2022 12:28 PM
Hi Antonio,

My example is below.
Code (fw): Select all Collapse
#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?
Regards,



Hakan ONEMLI



Harbour & MSVC 2022 & FWH 23.06
Posts: 1387
Joined: Fri May 23, 2008 01:33 PM
Re: TWebView:Destroy method does not close the window.
Posted: Thu Jul 28, 2022 02:13 PM
Hi,

I have add these lines.
Code (fw): Select all Collapse
#pragma BEGINDUMP

#include <hbapi.h>

void webview_terminate( void * w );

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


Code (fw): Select all Collapse
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 (fw): Select all Collapse
┌────────────────────────────────────────────────────────────────────────────┐
│ 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>
Regards,



Hakan ONEMLI



Harbour & MSVC 2022 & FWH 23.06
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: TWebView:Destroy method does not close the window.
Posted: Thu Jul 28, 2022 03:45 PM
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 (fw): Select all Collapse
#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
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 244
Joined: Mon Jun 05, 2006 09:39 PM
Re: TWebView:Destroy method does not close the window.
Posted: Thu Jul 28, 2022 04:00 PM
In the class I was creating, I did it like this and had no problems.

Code (fw): Select all Collapse
      WEBVIEW_TERMINATE(::hWebView)
      WEBVIEW_DESTROY(::hWebView)
      SendMessage( ::hWebView, WM_CLOSE)
Posts: 1387
Joined: Fri May 23, 2008 01:33 PM
Re: TWebView:Destroy method does not close the window.
Posted: Thu Jul 28, 2022 04:39 PM

:shock:

Regards,



Hakan ONEMLI



Harbour & MSVC 2022 & FWH 23.06
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: TWebView:Destroy method does not close the window.
Posted: Fri Jul 29, 2022 06:09 AM
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 (fw): Select all Collapse
    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 (fw): Select all Collapse
    ACTIVATE WINDOW oWndChild ;
       ON RESIZE oWebView:SetParent( oWndChild ) ;
       VALID ( SetParent( oWebView:GetWindow(), GetDesktopWindow() ), oWebView:Destroy(), SendMessage( oWebView:GetWindow(), WM_CLOSE ), .T. )

and
Code (fw): Select all Collapse
    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
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 1387
Joined: Fri May 23, 2008 01:33 PM
Re: TWebView:Destroy method does not close the window.
Posted: Fri Jul 29, 2022 06:59 AM

Hi Antonio,

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

Regards,



Hakan ONEMLI



Harbour & MSVC 2022 & FWH 23.06
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: TWebView:Destroy method does not close the window.
Posted: Fri Jul 29, 2022 11:56 AM

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...

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 244
Joined: Mon Jun 05, 2006 09:39 PM
Re: TWebView:Destroy method does not close the window.
Posted: Fri Jul 29, 2022 07:26 PM
Linares, it's not the window handle but the WebView handle.

Code (fw): Select all Collapse
      ::hWebView  := WEBVIEW_CREATE()
      WEBVIEW_DESTROY(::hWebView)
      SendMessage( ::hWebView, WM_CLOSE)
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: TWebView:Destroy method does not close the window.
Posted: Sat Jul 30, 2022 01:40 AM
Dear Giovany,

thanks for pointing it, anyhow the behavior remains the same:
Code (fw): Select all Collapse
#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
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: TWebView:Destroy method does not close the window.
Posted: Sat Jul 30, 2022 01:46 AM
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 (fw): Select all Collapse
#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
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: TWebView:Destroy method does not close the window.
Posted: Sat Jul 30, 2022 01:53 AM
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 (fw): Select all Collapse
#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
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: TWebView:Destroy method does not close the window.
Posted: Sat Jul 30, 2022 02:09 AM
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
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: TWebView:Destroy method does not close the window.
Posted: Sun Jul 31, 2022 12:12 PM
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()
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 244
Joined: Mon Jun 05, 2006 09:39 PM
Re: TWebView:Destroy method does not close the window.
Posted: Sun Jul 31, 2022 05:44 PM
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