Webview question
Webview question
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
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
- Antonio Linares
- Site Admin
- Posts: 42259
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Contact:
Re: Webview question
Dear Randal,
Please review FWH\samples\webviewuni.prg
Please review FWH\samples\webviewuni.prg
Re: Webview question
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
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) ]
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) ]
Re: Webview question
Antonio,Antonio Linares wrote:Dear Randal,
Please review FWH\samples\webviewuni.prg
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
- Antonio Linares
- Site Admin
- Posts: 42259
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Contact:
Re: Webview question
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:
We need to complete it, we are working to do it
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
#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
- Antonio Linares
- Site Admin
- Posts: 42259
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Contact:
Re: Webview question
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;
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!
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
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;
}
}
}
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!
- Antonio Linares
- Site Admin
- Posts: 42259
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Contact:
Re: Webview question
Here you have the updated webview DLLs:
https://github.com/FiveTechSoft/FWH_too ... ebview.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!
https://github.com/FiveTechSoft/FWH_too ... ebview.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!
- Antonio Linares
- Site Admin
- Posts: 42259
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Contact:
Re: Webview question
Dear Randal,
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)
Please download the most recent webview DLLs (url in the previous post) and use this new FWH\samples\webview1.prgThe 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.
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
#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
- Antonio Linares
- Site Admin
- Posts: 42259
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Contact:
Re: Webview question
Another new example showing how to place a webview inside a dialog:
webview3.prg
webview3.prg
Code: Select all | Expand
#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
Re: Webview question
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
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
- Antonio Linares
- Site Admin
- Posts: 42259
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Contact:
Re: Webview question
Dear Randal,
Here they work fine. I wonder what the difference may be...
Here they work fine. I wonder what the difference may be...
- Antonio Linares
- Site Admin
- Posts: 42259
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Contact:
Re: Webview question
Dear Randal,
Please download this file with all the running webview examples and test them:
https://github.com/FiveTechSoft/FWH_too ... amples.zip
Please download this file with all the running webview examples and test them:
https://github.com/FiveTechSoft/FWH_too ... amples.zip
Re: Webview question
Hi Antonio,Antonio Linares wrote:Here you have the updated webview DLLs:
https://github.com/FiveTechSoft/FWH_too ... ebview.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!
Can you please share webview5.prg sample?
Thanks
Regards,
Hakan ONEMLI
Harbour & MSVC 2022 & FWH 23.04
Hakan ONEMLI
Harbour & MSVC 2022 & FWH 23.04
- Antonio Linares
- Site Admin
- Posts: 42259
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Contact:
Re: Webview question
Dear Hakan,
It is included in the zip file
It is included in the zip file
Re: Webview question
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
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