Webview question

Webview question

Postby Randal » Thu Jun 29, 2023 1:36 pm

All,

I'm trying to replace an ActiveX shell.explorer.2 with Webview.

With the activex, when the user closed the activex window dialog I could retrieve the document in the oWnd:Valid function.

oDoc := oActiveX:document

I have looked at the examples and previous posts and I'm unable to get this to work.

FUNCTION HPCall( cUrl )

local oDlg, oWebView

cUrl := "www.google.com"

DEFINE DIALOG oDlg SIZE 500, 600

ACTIVATE DIALOG oDlg CENTERED ;
ON INIT ( oWebView := CreateWebView(oDlg), oWebview:Navigate( cUrl ) , .T. ) ;
VALID ( ValidWebView( oWebView ), .t. )

return nil


FUNCTION CreateWebView(oDlg, cUrl)

LOCAL oWebView

oWebView := TWebView():New()
Msginfo("webview new")
oWebView:SetParent( oDlg )
oWebView:bOnBind = { | cJson, nCalls | MsgInfo( cJson, nCalls ) }
oWebView:Bind( "SendToFWH" )

RETURN oWebView

FUNCTION ValidWebView(oWebview)

LOCAL cHtml

cHtml := oWebView:Eval( "SendToFWH( document.body.innerHTML )")
Msginfo( cHtml, "cHtml") // cHtml is empty

RETURN .T.

What should I put in the OnBind code block? I don't want a message to be displayed. When the user closes the dialog I want to capture the document as I did when using Activex.

The other problem I have is when you call TWebview:New() a blank window is displayed momentarily before my dialog is displayed. I saw a reference to this in past posts however, I didn't not see any fix that addresses this. You can see this in the webview.prg and webview5.prg samples also.

Thanks,
Randal
Randal
 
Posts: 260
Joined: Mon Oct 24, 2005 8:04 pm

Re: Webview question

Postby Antonio Linares » Thu Jun 29, 2023 4:56 pm

Dear Randal,

Please review FWH\samples\webviewuni.prg
regards, saludos

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

Re: Webview question

Postby leandro » Thu Jun 29, 2023 5:28 pm

Antonio buenas tardes como estas?

Sera que tu nos puedes ayudar a montar un ejemplo sobre webview, en donde logremos validar un formulario, por lo menos el acceso, usuario y contraseña, directo desde webview, pero lanzando las funciones a FW para validar la existencia del usuario en un dbf. La idea es usar webview como FRONT y fw como BACK.

Lo que pasa es que el ejemplo webviewuni es de solo click, es muy basico y de momento nosotros no le hemos encontrado la funcionalidad.

De antemano gracias
Saludos
LEANDRO AREVALO
Bogotá (Colombia)
https://hymlyma.com
https://hymplus.com/
leandroalfonso111@gmail.com
leandroalfonso111@hotmail.com

[ Embarcadero C++ 7.60 for Win32 ] [ FiveWin 23.07 ] [ xHarbour 1.3.0 Intl. (SimpLex) (Build 20230914) ]
User avatar
leandro
 
Posts: 1676
Joined: Wed Oct 26, 2005 2:49 pm
Location: Colombia

Re: Webview question

Postby Randal » Thu Jun 29, 2023 5:56 pm

Antonio Linares wrote:Dear Randal,

Please review FWH\samples\webviewuni.prg


Antonio,

Thank you for your reply. I have looked at the samples and webviewuni.prg and searched this forum for examples. I need to process the contents of the page after the user closes the browser window.

Can you please look at my sample and tell me what I'm doing wrong?

Additionally, what about the problem of the ghost window being displayed after calling TWebView:new()? This problem is reproduced in the other webview samples, i.e. webview5.prg.

Thanks,
Randal
Randal
 
Posts: 260
Joined: Mon Oct 24, 2005 8:04 pm

Re: Webview question

Postby Antonio Linares » Fri Jun 30, 2023 9:41 am

Dear Randal,

FWH uses https://github.com/webview/webview (a DLL) to manage Webview. This has some advantages and limitations.

We are trying to avoid using it and directly manage a Microsoft IWebBrowser2 object as we could have a much better control over it.
Anyhow, there are several ways to do it and we are looking for the simplest way (as there are very complex ways).

This is a code that we are starting to avoid using the webview.dll:
Code: Select all  Expand view  RUN
#include "FiveWin.ch"

function Main()

   local oWnd

   DEFINE WINDOW oWnd

   MsgInfo( Test( oWnd:hWnd ) )

   ACTIVATE WINDOW oWnd CENTERED

return nil  

#pragma BEGINDUMP

#include <Windows.h>
#include <ExDisp.h>
#include <hbapi.h>

HB_FUNC( TEST )
{
    IWebBrowser2 * webView2;
    BSTR url;
    VARIANT emptyVar;
    HWND hWnd;

    CoInitialize(NULL);
    CoCreateInstance( &CLSID_WebBrowser, NULL, CLSCTX_INPROC_SERVER, &IID_IWebBrowser2, (void**) &webView2 );

    url = SysAllocString(L"https://www.google.com");
    VariantInit( &emptyVar );
    webView2->lpVtbl->Navigate( webView2, url, &emptyVar, &emptyVar, &emptyVar, &emptyVar);
    SysFreeString(url);

    webView2->lpVtbl->get_HWND( webView2, ( LONG_PTR * ) &hWnd );    
    SetParent( hWnd, ( HWND ) hb_parnll( 1 ) );
    webView2->lpVtbl->put_Visible( webView2, VARIANT_TRUE );
    SetForegroundWindow( hWnd );

    hb_retptr( webView2 );
}


#pragma ENDDUMP

We need to complete it, we are working to do it
regards, saludos

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

Re: Webview question

Postby Antonio Linares » Sat Jul 01, 2023 7:08 am

We discard the above way as it does not work.

We have choosen to directly modify https://github.com/webview/webview as it is simpler and easier for us:

1. First we do a checkout from the official repo:

git clone https://github.com/webview/webview

Then we need to include in webview.h the changes that the webview's author did to implement set_user_agent() for us (and works great) but he decided not to include in the official repo:

git clone https://github.com/SteffenL/webview webview_user_agent
cd webview_user_agent
git checkout up/set-user-agent (he did this fork for us)

Now we compare webview.h in both repos and include the code for set_user_agent. Finally we modify the code to avoid the calling to PostQuitMessage():

BOOL bRunning = FALSE;

Code: Select all  Expand view  RUN
 void run() {
    MSG msg;
    BOOL res;

    bRunning = TRUE;
    while ( bRunning && (res = GetMessage(&msg, nullptr, 0, 0)) != -1) {
      if (msg.hwnd) {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
        continue;
      }
      if (msg.message == WM_APP) {
        auto f = (dispatch_fn_t *)(msg.lParam);
        (*f)();
        delete f;
      }
    }
  }
 

void terminate() { bRunning = FALSE; /* PostQuitMessage(0); */ }

Finally we go to the script folder and run build.bat. The resulting DLLs are placed in c:\webview\dll\x86\ and c:\webview\dll\x64\

FWH examples are working fine and closing the webview does not closes our app! :-)
regards, saludos

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

Re: Webview question

Postby Antonio Linares » Sat Jul 01, 2023 10:28 am

Here you have the updated webview DLLs:

https://github.com/FiveTechSoft/FWH_tools/blob/master/fivetech_webview.zip

Please test them using FWH\samples\webview.prg and webview5.prg

In webview5.prg you can check how closing the webview does not closes the FWH app! :-)
regards, saludos

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

Re: Webview question

Postby Antonio Linares » Sat Jul 01, 2023 11:12 am

Dear Randal,

The other problem I have is when you call TWebview:New() a blank window is displayed momentarily before my dialog is displayed. I saw a reference to this in past posts however, I didn't not see any fix that addresses this. You can see this in the webview.prg and webview5.prg samples also.


Please download the most recent webview DLLs (url in the previous post) and use this new FWH\samples\webview1.prg

This example shows how to create the webview using an existing window (it uses the handle of the provided window to display on it, without creating a new control)
Code: Select all  Expand view  RUN
#include "FiveWin.ch"

function Main()

   local oWnd, oWebView

   DEFINE WINDOW oWnd TITLE "Using a webview from an existing window"

   oWnd:Center()
   oWebView = TWebView():New(, oWnd:hWnd )

   oWebView:Navigate( "http://www.google.com" )
   oWebView:SetUserAgent( "Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.5060.53 Mobile Safari/537.36" )

   ACTIVATE WINDOW oWnd CENTER ;
      ON RESIZE If( nWidth != nil, oWebView:SetSize( nWidth, nHeight ), oWebView:SetSize( 800, 500 ) )

   oWebView:Destroy()

return nil
regards, saludos

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

Re: Webview question

Postby Antonio Linares » Sat Jul 01, 2023 11:36 am

Another new example showing how to place a webview inside a dialog:

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

function Main()

    local oDlg, oWebView  

    DEFINE DIALOG oDlg SIZE 1200, 700

    ACTIVATE DIALOG oDlg CENTER ;
        ON INIT ( oWebView := TWebView():New( , oDlg:hWnd ),;
                  oWebView:Navigate( "http://www.google.com" ), .T. )

return nil  
regards, saludos

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

Re: Webview question

Postby Randal » Sat Jul 01, 2023 11:00 pm

Antonio,

Thank you for all your efforts.

I get an error when using the new dll's.

"d:\fwh\samples\webview.dll is either not designed to run on Windows or it contains an error." "Error status 0xc00035a"

and then another error "Could not load webview.dll".

Works fine with the webview dll's dated 4/30/23.

Randal
Randal
 
Posts: 260
Joined: Mon Oct 24, 2005 8:04 pm

Re: Webview question

Postby Antonio Linares » Sun Jul 02, 2023 5:58 am

Dear Randal,

Here they work fine. I wonder what the difference may be...
regards, saludos

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

Re: Webview question

Postby Antonio Linares » Sun Jul 02, 2023 6:36 am

Dear Randal,

Please download this file with all the running webview examples and test them:

https://github.com/FiveTechSoft/FWH_tools/blob/master/fivetech_webview_examples.zip
regards, saludos

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

Re: Webview question

Postby Horizon » Sun Jul 02, 2023 8:57 am

Antonio Linares wrote:Here you have the updated webview DLLs:

https://github.com/FiveTechSoft/FWH_tools/blob/master/fivetech_webview.zip

Please test them using FWH\samples\webview.prg and webview5.prg

In webview5.prg you can check how closing the webview does not closes the FWH app! :-)


Hi Antonio,

Can you please share webview5.prg sample?

Thanks
Regards,

Hakan ONEMLI

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

Re: Webview question

Postby Antonio Linares » Sun Jul 02, 2023 12:56 pm

Dear Hakan,

It is included in the zip file
regards, saludos

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

Re: Webview question

Postby Randal » Sun Jul 02, 2023 2:26 pm

Antonio,

The latest examples work fine now.

Interestingly, the syntax used in the webview3.prg example does not show the ghost window. Specifically, assigning the dialog/window handle when calling the Webview:New() method.

oWebView := TWebView():New( , oDlg:hWnd )

Thank you so much for all your work.

Randal
Randal
 
Posts: 260
Joined: Mon Oct 24, 2005 8:04 pm

Next

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Timm Sodtalbers and 53 guests