TWebView:Destroy method does not close the window.

TWebView:Destroy method does not close the window.

Postby Horizon » Thu Jul 28, 2022 12:28 pm

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?
Regards,

Hakan ONEMLI

Harbour & MSVC 2022 & FWH 23.04
Horizon
 
Posts: 1288
Joined: Fri May 23, 2008 1:33 pm

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

Postby Horizon » Thu Jul 28, 2022 2:13 pm

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>
Regards,

Hakan ONEMLI

Harbour & MSVC 2022 & FWH 23.04
Horizon
 
Posts: 1288
Joined: Fri May 23, 2008 1:33 pm

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

Postby Antonio Linares » Thu Jul 28, 2022 3: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: 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
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 41342
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

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

Postby Giovany Vecchi » Thu Jul 28, 2022 4:00 pm

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)
 
User avatar
Giovany Vecchi
 
Posts: 208
Joined: Mon Jun 05, 2006 9:39 pm
Location: Brasil

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

Postby Horizon » Thu Jul 28, 2022 4:39 pm

:shock:
Regards,

Hakan ONEMLI

Harbour & MSVC 2022 & FWH 23.04
Horizon
 
Posts: 1288
Joined: Fri May 23, 2008 1:33 pm

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

Postby Antonio Linares » Fri Jul 29, 2022 6: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: 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
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 41342
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

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

Postby Horizon » Fri Jul 29, 2022 6: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.04
Horizon
 
Posts: 1288
Joined: Fri May 23, 2008 1:33 pm

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

Postby Antonio Linares » 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
User avatar
Antonio Linares
Site Admin
 
Posts: 41342
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

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

Postby Giovany Vecchi » Fri Jul 29, 2022 7:26 pm

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)
 
User avatar
Giovany Vecchi
 
Posts: 208
Joined: Mon Jun 05, 2006 9:39 pm
Location: Brasil

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

Postby Antonio Linares » Sat Jul 30, 2022 1:40 am

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
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 41342
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

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

Postby Antonio Linares » Sat Jul 30, 2022 1: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: 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
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 41342
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

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

Postby Antonio Linares » Sat Jul 30, 2022 1: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: 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
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 41342
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

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

Postby Antonio Linares » Sat Jul 30, 2022 2: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
User avatar
Antonio Linares
Site Admin
 
Posts: 41342
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

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

Postby Antonio Linares » 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
User avatar
Antonio Linares
Site Admin
 
Posts: 41342
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

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

Postby Giovany Vecchi » Sun Jul 31, 2022 5: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
Image
User avatar
Giovany Vecchi
 
Posts: 208
Joined: Mon Jun 05, 2006 9:39 pm
Location: Brasil

Next

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 18 guests