Page 2 of 4

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

PostPosted: Sun Jul 31, 2022 6:03 pm
by Antonio Linares
Dear Giovany,

Do you use it from a MDI environment as the posted examples ?

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

PostPosted: Sun Jul 31, 2022 7:23 pm
by Giovany Vecchi
Hi Antonio, In this example I'm using it, but it also works without being MDI.
Download the link or look at the sources.

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

PostPosted: Sun Jul 31, 2022 9:30 pm
by Antonio Linares
Dear Giovany,

Many thanks for your example.

In your PRGs I don't see any MDICHILD window being created with a WebView inside

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

PostPosted: Sun Jul 31, 2022 10:23 pm
by Giovany Vecchi
Open WebView.prg on line 33 and put 'MDICHILD' then in the Samples menu call 'Test with Fivewin window' which will open a fivewin child window with webview2 handle

Code: Select all  Expand view
FUNCTION WEB_VIEW_TST_WND_FW()
   Local lc_oWndTst
   Local lc_oWebViewFw

   DEFINE WINDOW lc_oWndTst FROM 100, 100 TO 768, 1024 ;
      PIXEL ;
      TITLE "Teste WebView2" MDICHILD

      lc_oWndTst:bInit := <||
         lc_oWebViewFw := WebViewFw():New(lc_oWndTst)
         lc_oWebViewFw:WebViewFw_Start()
         lc_oWebViewFw:WebViewFw_Navigate("http://www.google.com.br")
         lc_oWebViewFw:WebViewFw_Run()
         Return Nil
      >// cEnd

      lc_oWndTst:bValid := <||
         lc_oWebViewFw:End()
         Return .T.
      >//cEnd
   
   ACTIVATE WINDOW lc_oWndTst NORMAL

RETURN NIL
 

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

PostPosted: Mon Aug 01, 2022 11:27 am
by Horizon
Hi Antonio,

Can you please to help me to create wrapper WebView_Terminate for msvc? It is in WebView.dll but I could not access.

Thanks.

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

PostPosted: Mon Aug 01, 2022 12:01 pm
by Antonio Linares
Dear Hakan,

I have already implemented it. I send you the libs this evening, I have to go now...

Do you need them for MSVC 32 bits ?

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

PostPosted: Mon Aug 01, 2022 12:05 pm
by Horizon
Antonio Linares wrote:Dear Hakan,

I have already implemented it. I send you the libs this evening, I have to go now...

ok

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

PostPosted: Mon Aug 01, 2022 12:10 pm
by Antonio Linares
msvc 32 bits ?

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

PostPosted: Mon Aug 01, 2022 12:16 pm
by Horizon
Antonio Linares wrote:msvc 32 bits ?

yes

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

PostPosted: Mon Aug 01, 2022 12:20 pm
by Horizon
Horizon wrote:
Antonio Linares wrote:msvc 32 bits ?

yes

and TWebView class if you have changed.

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

PostPosted: Mon Aug 01, 2022 11:34 pm
by Antonio Linares
Already sent

best regards

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

PostPosted: Wed Aug 03, 2022 6:49 pm
by Horizon
Hi Antonio,

Has our WEBVIEW_CREATE(,::oWndDlgContainer:hWnd) function container dialog parameter?

Code: Select all  Expand view
void * webview_create(int debug, void * window );
 


Code: Select all  Expand view
// Creates a new webview instance. If debug is non-zero - developer tools will
// be enabled (if the platform supports them). Window parameter can be a
// pointer to the native window handle. If it's non-null - then child WebView
// is embedded into the given parent window. Otherwise a new window is created.
// Depending on the platform, a GtkWindow, NSWindow or HWND pointer can be
// passed here.
HB_FUNC( WEBVIEW_CREATE )
{
   INT iDebug = ( INT ) 1 ;
   HWND hWnd = ( HWND ) fw_parH(2) ;
   if ( HB_ISNUM( 2 ) )
      hb_retptr( webview_create( iDebug , &hWnd ));
   else
      hb_retptr( webview_create( iDebug , 0 ));
}

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

PostPosted: Thu Aug 04, 2022 7:09 am
by Antonio Linares
Dear Hakan,

I have already implemented it though using a different code from yours:
Code: Select all  Expand view
HB_FUNC( WEBVIEW_CREATE )
{
   if( ! hDLL )
      hDLL = LoadLibrary( "webview.dll" );

   if( ! hDLL )
   {
      MessageBox( 0, "Could not load webview.dll", "Error", MB_OK | MB_ICONERROR );  
      hb_ret();
   }  
   else
   {
      HWND hWnd = ( HWND ) hb_parnll( 2 );

      if( hWnd != 0 )
         hb_retptr( ( ( webview_create * ) GetProcAddress( hDLL, "webview_create" ) )( hb_parnl( 1 ), &hWnd ) );
      else
         hb_retptr( ( ( webview_create * ) GetProcAddress( hDLL, "webview_create" ) )( hb_parnl( 1 ), 0 ) );
   }  
}


In Class TWebView:
Code: Select all  Expand view
  METHOD New( nDebug, hWndParent ) INLINE ( ::hWebView := WebView_Create( nDebug, hWndParent ), AAdd( aWebViews, Self ), Self )
 

I am emailing you the modified libs

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

PostPosted: Thu Aug 04, 2022 7:44 pm
by Horizon
Thank you Antonio,

With this last change, TWebView is easier to control.

Code: Select all  Expand view
#include "FiveWin.ch"
function Main()
  local oWnd, oBar
    public pb_oWebView

   DEFINE WINDOW oWnd

   DEFINE BUTTONBAR oBar 3D OF oWnd SIZE 60, 60

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

   ACTIVATE WINDOW oWnd

return nil

function Open_Google( oWnd )
LOCAL cHtml:="https://www.google.com/"
local oWndChild, oWebView

    IF !EMPTY(pb_oWebView)
        MsgAlert("There is already WINDOW")
        return
    ENDIF
  DEFINE WINDOW oWndChild TITLE "My Test FW Window_"+TIME() ;
    FROM 100, 100 TO 768, 1024 PIXEL
  oWndChild:bInit := <||
        oWebView := TOB_WebView():New(oWndChild)
        oWebView:Navigate(cHtml)
        oWebView:Run()                              // We dont need when oWndChild
        pb_oWebView := oWebView
     Return Nil
  >
 
    oWndChild:bValid := <||
       oWebView:Destroy()
       Return .T.
    >
   
  ACTIVATE WINDOW oWndChild  
   
return nil

PROCEDURE Close_Google(oWnd)
LOCAL oWebView := pb_oWebView
    If EMPTY(pb_oWebView)
        MsgAlert("There is NOT any WINDOW") 
        return 
    ENDIF
    If !HB_ISNIL(oWebView:oWndDlgContainer)
        oWebView:oWndDlgContainer:End()
        pb_oWebView:=nil
    EndIf   
return nil
*------------------------------------------------------------------------------------------
CLASS TOB_WebView FROM TWebView
    Data oWndDlgContainer

    METHOD New(oWndDlgContainer) Constructor
    Method Run()
   
ENDCLASS

METHOD New(oWndDlgContainer) CLASS TOB_WebView
Local lc_lLoopReSize := .F.
  ::oWndDlgContainer := oWndDlgContainer

   If !Hb_IsNil(::oWndDlgContainer)
      ::hWebView        := WEBVIEW_CREATE(,::oWndDlgContainer:hWnd)
      ::oWndDlgContainer:bResized := <||
         If !lc_lLoopReSize
            lc_lLoopReSize := .T.
            hb_idleSleep(.001)
            ::SetSize(::oWndDlgContainer:nWidth,;
                                          ::oWndDlgContainer:nHeight,0)
            lc_lLoopReSize := .F.
         EndIf
         Return Nil
      >
   Else
      ::hWebView        := WEBVIEW_CREATE()
   EndIf  
 
RETURN Self

Method Run() Class TOB_WebView
    IF HB_ISNIL(::oWndDlgContainer)
        If !::lStartRun
          ::super:Run()
        EndIf
        ::lStartRun := .T.
  ENDIF
Return Nil

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

PostPosted: Thu Aug 04, 2022 10:10 pm
by cmsoft
Antonio, para probar, hay que descargar nuevamente las librerias?
Ya que pruebo el ejemplo de Hakan y me quedan abiertas ventanas...
Desde ya muchas gracias