Re: TWebView:Destroy method does not close the window.
Posted: Sun Jul 31, 2022 6:03 pm
Dear Giovany,
Do you use it from a MDI environment as the posted examples ?
Do you use it from a MDI environment as the posted examples ?
www.FiveTechSoft.com
https://fivetechsupport.com/forums/
https://fivetechsupport.com/forums/viewtopic.php?f=3&t=42010
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
Antonio Linares wrote:Dear Hakan,
I have already implemented it. I send you the libs this evening, I have to go now...
Antonio Linares wrote:msvc 32 bits ?
Horizon wrote:Antonio Linares wrote:msvc 32 bits ?
yes
void * webview_create(int debug, void * window );
// 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 ));
}
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 ) );
}
}
METHOD New( nDebug, hWndParent ) INLINE ( ::hWebView := WebView_Create( nDebug, hWndParent ), AAdd( aWebViews, Self ), Self )
#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