WebView window

WebView window

Postby Natter » Sun Dec 25, 2022 7:26 pm

Hi,

The window of the WebView object creates a window. Is it possible to make the WebView open in a hidden form (without a window appearing on the screen) ?
Natter
 
Posts: 1222
Joined: Mon May 14, 2007 9:49 am

Re: WebView window

Postby Antonio Linares » Sun Dec 25, 2022 9:35 pm

You can make it children of another window so it will behave as a control

Or do you want it totally hidden ?
regards, saludos

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

Re: WebView window

Postby Natter » Mon Dec 26, 2022 7:01 am

That's what I do. But this does not solve the problem of the window appearing (at least for 1 second) when creating a WebView
Natter
 
Posts: 1222
Joined: Mon May 14, 2007 9:49 am

Re: WebView window

Postby Jimmy » Mon Dec 26, 2022 7:23 am

hi,

you can use "negative" Position at "Create" and later "move" to new Position / Parent
greeting,
Jimmy
User avatar
Jimmy
 
Posts: 1732
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Re: WebView window

Postby Antonio Linares » Mon Dec 26, 2022 7:41 am

Dear Jimmy,

He won't be able to do that as WebView_Create() called from TWebView():New() does not allow the use of coordinates

Maybe this may work:
#define SW_HIDE 0
#define SW_NORMAL 1

local oWebView := TWebView():New()

ShowWindow( oWebView:GetWindow(), SW_HIDE )
... then do the required startup code and finally:
ShowWindow( oWebView:GetWindow(), SW_NORMAL )
regards, saludos

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

Re: WebView window

Postby Natter » Mon Dec 26, 2022 12:41 pm

Trying to execute this program:

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

function Main()
local oWebKds := TWebView():New()

    oWebKds := TWebView():New()

    oWebKds:bOnBind = { | cJson, nCalls | MsgInfo( cJson, nCalls ) }
    oWebKds:Bind( "SendKds" )


    cUrl:="https://www.google.com"
    buf:='function Kds_Url() { SendKds(document.body.innerHTML) } ;'+CRLF+ ;
         'window.location.href="'+cUrl+'" ;'+CRLF+ ;
         'Kds_Url() ;'

    DEFINE DIALOG oKds FROM 0,0 TO 400,400  PIXEL ;
       STYLE nOR(WS_POPUP)  COLOR CLR_BLACK, CLR_WHITE
    ACTIVATE DIALOG oKds  ON PAINT (oWebKds:SetParent(oKds), oWebKds:Eval(buf))
return


The code block :bOnBind does not work. What am I doing wrong ?
Natter
 
Posts: 1222
Joined: Mon May 14, 2007 9:49 am

Re: WebView window

Postby Antonio Linares » Mon Dec 26, 2022 4:03 pm

This works fine:
Code: Select all  Expand view  RUN
#include "FiveWin.ch"

//----------------------------------------------------------------------------//

function Main()

   local oWebView := TWebView():New()

   oWebView:bOnBind = { | cJson, nCalls | MsgInfo( cJson, nCalls ) }
   oWebView:Bind( "SendToFWH" )
   oWebView:Navigate( Html() )
   Sleep( 200 )
   oWebView:Run()
   oWebView:Destroy()

return nil

//----------------------------------------------------------------------------//

function Html()

   local cHtml

   TEXT INTO cHtml
      data:text/html,
      <html>
         <head>
         </head>
         <body style="background-color:cyan">
            <h2>Using WebView from FWH</h2>
            <button onclick='SendToFWH( 123 )'>Call FWH app from web browser</button>
            <button onclick='SendToFWH( 456 )'>Test 2</button>
            <button onclick='SendToFWH( document.body.innerHTML )'>Test 3</button>
         </body>
      </html>
   ENDTEXT      

return cHtml

//----------------------------------------------------------------------------//

Are trying to add javascript code to an exiting web site ?
regards, saludos

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

Re: WebView window

Postby Antonio Linares » Mon Dec 26, 2022 4:15 pm

Another example using Class TWebView Method Eval():

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

//----------------------------------------------------------------------------//

function Main()

   local oWebView := TWebView():New()

   oWebView:bOnBind = { | cJson, nCalls | MsgInfo( cJson, nCalls ) }
   oWebView:Bind( "SendToFWH" )
   oWebView:Navigate( Html() )
   Sleep( 200 )
   oWebView:Eval( "SendToFWH( document.body.innerHTML )" )
   oWebView:Run()
   oWebView:Destroy()

return nil

//----------------------------------------------------------------------------//

function Html()

   local cHtml

   TEXT INTO cHtml
      data:text/html,
      <html>
         <head>
         </head>
         <body style="background-color:cyan">
            <h2>Using WebView from FWH</h2>
            <button onclick='SendToFWH( 123 )'>Call FWH app from web browser</button>
            <button onclick='SendToFWH( 456 )'>Test 2</button>
            <button onclick='SendToFWH( document.body.innerHTML )'>Test 3</button>
         </body>
      </html>
   ENDTEXT      

return cHtml

//----------------------------------------------------------------------------//
regards, saludos

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

Re: WebView window

Postby Natter » Mon Dec 26, 2022 4:36 pm

Yes, I need to make frequent site requests and read the changes. This is a very convenient algorithm for me and I do not understand why in this case the code block :bonBind does not work :cry:

the oWebKds:SetParent() method works, but the oWebKds:Eval() method does not
Natter
 
Posts: 1222
Joined: Mon May 14, 2007 9:49 am

Re: WebView window

Postby Antonio Linares » Mon Dec 26, 2022 5:22 pm

This is working fine:
Code: Select all  Expand view  RUN
#include "FiveWin.ch"

//----------------------------------------------------------------------------//

function Main()

   local oWebView := TWebView():New()

   oWebView:bOnBind = { | cJson, nCalls | MsgInfo( cJson, nCalls ) }
   oWebView:Bind( "SendToFWH" )
   oWebView:Navigate( "https://www.fivetechsoft.com" )
   Sleep( 200 )
   oWebView:Eval( "SendToFWH( document.body.innerHTML )" )
   oWebView:Run()
   oWebView:Destroy()

return nil

//----------------------------------------------------------------------------//
regards, saludos

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

Re: WebView window

Postby cnavarro » Mon Dec 26, 2022 5:36 pm

Try with
Code: Select all  Expand view  RUN

    ACTIVATE DIALOG oKds ON INIT ( oWebKds:SetParent(oKds), Sleep( 300 ) ) ON PAINT ( oWebKds:Eval(buf) )
 
Cristobal Navarro
Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo
El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces
User avatar
cnavarro
 
Posts: 6549
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

Re: WebView window

Postby Natter » Mon Dec 26, 2022 5:59 pm

I checked, nothing has changed :(
Natter
 
Posts: 1222
Joined: Mon May 14, 2007 9:49 am

Re: WebView window

Postby cnavarro » Mon Dec 26, 2022 6:15 pm

Consider the following:
- The change in the content of the oWebView control does not cause the Paint event of the dialog to be executed
- In your javascript code, you are causing a recursive call to the same function.
I want to check that your code ( Eval() ) is executed? ( assuming there is no error in that code )
Change your code and resize dialog
Code: Select all  Expand view  RUN

 DEFINE DIALOG oDlg FROM 0,0 TO 400,400  PIXEL TRUEPIXEL RESIZABLE
 

If you want that function defined in ON PAINT to be executed, one of the possible options is to use a TIMER
Cristobal Navarro
Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo
El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces
User avatar
cnavarro
 
Posts: 6549
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

Re: WebView window

Postby Natter » Mon Dec 26, 2022 7:08 pm

I tried to write like this:

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

function Main()
local oWebKds := TWebView():New()

    oWebKds := TWebView():New()

    oWebKds:bOnBind = { | cJson, nCalls | MsgInfo( cJson, nCalls ) }
    oWebKds:Bind( "SendKds" )

   cUrl:="https://www.google.com"
    buf:='function Kds_Url() { SendKds(document.body.innerHTML) } ;'+CRLF+ ;
         'window.location.href="'+cUrl+'" ;'+CRLF+ ;
         'document.addEventListener("DOMContentLoaded", Kds_Url()) ;'

    DEFINE DIALOG oKds FROM 0,0 TO 400,400  PIXEL TRUEPIXEL RESIZABLE TITLE "Test"
    ACTIVATE DIALOG oKds  ON PAINT (sleep(200), oWebKds:Eval(buf))
return
 


Three :shock: windows appear:
1-DIALOG "Test"
2-webview with GOOGLE.COM
3-webview is empty
Natter
 
Posts: 1222
Joined: Mon May 14, 2007 9:49 am

Re: WebView window

Postby Antonio Linares » Mon Dec 26, 2022 7:20 pm

You are calling TWebView():New() twice

why ?
regards, saludos

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

Next

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 103 guests