FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin para Harbour/xHarbour TWebView2 focus soluci贸n
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
TWebView2 focus soluci贸n
Posted: Thu Sep 25, 2025 11:35 AM
Hay una peque帽a diferencia entre TWebView y TWebView2 relativa al foco.

TWebView2 no le da el foco a la p谩gina web automaticamente. Para hacerlo esta es la soluci贸n:

SetFocus( GetWindow( oWnd:hWnd, 5 ) ) // GW_CHILD

De esta forma el hWnd del webview recibe el foco correctamente :wink:
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 8515
Joined: Tue Dec 20, 2005 07:36 PM
Re: TWebView2 focus soluci贸n
Posted: Thu Sep 25, 2025 01:56 PM

Querido Maestro, sin abusar de su buena voluntad, 驴no ser铆a m谩s f谩cil de entender publicar un ejemplo pr谩ctico?

Gracias, tks.

Regards, saludos.

Jo茫o Santos - S茫o Paulo - Brasil - Phone: +55(11)95150-7341
Posts: 231
Joined: Fri Jul 20, 2012 01:49 AM
Re: TWebView2 focus soluci贸n
Posted: Thu Sep 25, 2025 04:58 PM
Hola,

Aqui tiene un ejemplo:
#include "FiveWin.ch"

#ifndef GW_CHILD
	#define GW_CHILD 5
#endif

function Main()

	local oWnd, oWebView

	define window oWnd title "WebView" SIZE 1500, 1000

	oWebView = TWebView2():New( oWnd )
	oWebView:Navigate( openLocalFile( hb_dirBase() + "login.html" ) )
	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" )

	setFocus( GetWindow( oWnd:hWnd, GW_CHILD ) )

	activate window oWnd center;
		on resize oWebView:SetSize( nWidth, nHeight )

return nil

function openLocalFile( cFile )

	local cUrl := hb_dirTemp() + "index.html"

	hb_memoWrit( cUrl, hb_memoRead( cFile ) )

	cUrl := urlEncode( "file:///" + strtran( cUrl, "\", "/" ) )
	cUrl := strtran( cUrl, "+", "%20" )
	cUrl := strtran( cUrl, " ", "%20" )
	cUrl := strtran( cUrl, "%3A", ":" )

return cUrl

#pragma BEGINDUMP
#include <hbvm.h>
#include <hbapi.h>
#include <hbapiitm.h>
#include <hbapierr.h>

HB_FUNC( URLENCODE )
{
	const char * cData     = hb_parc( 1 );
	HB_ISIZ      nLen      = hb_parclen( 1 );
	HB_BOOL      bComplete = hb_parldef( 2, HB_TRUE );
	char *       cRet;
	HB_ISIZ      nPos = 0, nPosRet = 0, nVal;
	char         cElem;

	if( ! cData )
	{
		hb_errRT_BASE( EG_ARG, 3012, NULL,
						HB_ERR_FUNCNAME, 1, hb_paramError( 1 ) );
		return;
	}

	if( ! nLen )
	{
		hb_retc_null();
		return;
	}

	/* Giving maximum final length possible */
	cRet = ( char * ) hb_xgrab( nLen * 3 + 1 );

	while( nPos < nLen )
	{
		cElem = cData[ nPos ];

		if( cElem == ' ' )
		{
			cRet[ nPosRet ] = '+';
		}
		else if(
			( cElem >= 'A' && cElem <= 'Z' ) ||
			( cElem >= 'a' && cElem <= 'z' ) ||
			( cElem >= '0' && cElem <= '9' ) ||
			cElem == '.' || cElem == ',' || cElem == '&' ||
			cElem == '/' || cElem == ';' || cElem == '_' )
		{
			cRet[ nPosRet ] = cElem;
		}
		else if( ! bComplete && ( cElem == ':' || cElem == '?' || cElem == '=' ) )
		{
			cRet[ nPosRet ] = cElem;
		}
		else /* encode! */
		{
			cRet[ nPosRet++ ] = '%';
			nVal = ( ( HB_UCHAR ) cElem ) >> 4;
			cRet[ nPosRet++ ] = nVal < 10 ? '0' + ( char ) nVal : 'A' + ( char ) nVal - 10;
			nVal = ( ( HB_UCHAR ) cElem ) & 0x0F;
			cRet[ nPosRet ] = nVal < 10 ? '0' + ( char ) nVal : 'A' + ( char ) nVal - 10;
		}

		nPosRet++;
		nPos++;
	}

	hb_retclen_buffer( cRet, nPosRet );
}

#pragma ENDDUMP
login.html
<!DOCTYPE html>
<html lang="es">

<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<title>Inicio de Sesi贸n</title>
	<style>
		body {
			font-family: Arial, sans-serif;
			background-color: #f0f0f0;
			display: flex;
			justify-content: center;
			align-items: center;
			height: 100vh;
			margin: 0;
		}

		.login-container {
			background-color: white;
			padding: 2rem;
			border-radius: 8px;
			box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
			width: 100%;
			max-width: 400px;
		}

		.login-container h2 {
			text-align: center;
			color: #333;
			margin-bottom: 1.5rem;
		}

		.form-group {
			margin-bottom: 1rem;
		}

		label {
			display: block;
			margin-bottom: 0.5rem;
			color: #555;
			font-weight: bold;
		}

		input[type="text"],
		input[type="password"] {
			width: 100%;
			padding: 0.75rem;
			border: 1px solid #ddd;
			border-radius: 4px;
			font-size: 1rem;
			box-sizing: border-box;
		}

		input[type="text"]:focus,
		input[type="password"]:focus {
			outline: none;
			border-color: #4CAF50;
			box-shadow: 0 0 5px rgba(76, 175, 80, 0.3);
		}

		.btn-login {
			width: 100%;
			background-color: #4CAF50;
			color: white;
			padding: 0.75rem;
			border: none;
			border-radius: 4px;
			font-size: 1rem;
			cursor: pointer;
			margin-top: 1rem;
		}

		.btn-login:hover {
			background-color: #45a049;
		}
	</style>
</head>

<body>
	<div class="login-container">
		<h2>Iniciar Sesi贸n</h2>

		<form action="/login" method="POST" id="loginForm">
			<div class="form-group">
				<label for="username">Nombre de usuario:</label>
				<input type="text" id="username" name="username" autofocus required>
			</div>

			<div class="form-group">
				<label for="password">Contrase帽a:</label>
				<input type="password" id="password" name="password" required>
			</div>

			<button type="submit" class="btn-login">Iniciar Sesi贸n</button>
		</form>
	</div>

	<script>
		// Funcionalidad de demostraci贸n (opcional)
		document.getElementById('loginForm').addEventListener('submit', function (e) {
			e.preventDefault(); // Prevenir env铆o para demostraci贸n

			const username = document.getElementById('username').value;
			const password = document.getElementById('password').value;

			if (username && password) {
				alert('Login exitoso!\nUsuario: ' + username);
			}
		});
		function setFocus(elementId) {
			const el = document.getElementById(elementId);
			if (el) {
				el.focus()
				el.click()
			}
		}
		setTimeout(function(){ setFocus('username');},3*1000);
	</script>
</body>

</html>
Regards,

Lailton Fernando Mariano
Posts: 8515
Joined: Tue Dec 20, 2005 07:36 PM
Re: TWebView2 focus soluci贸n
Posted: Thu Sep 25, 2025 05:25 PM

Gracias, Lailton. Como siempre, muy amable.

Regards, saludos.

Jo茫o Santos - S茫o Paulo - Brasil - Phone: +55(11)95150-7341
Posts: 467
Joined: Fri Dec 09, 2005 12:41 AM
Re: TWebView2 focus soluci贸n
Posted: Fri Oct 03, 2025 02:45 PM
Estimado Lailton

Buen dato, aprovecho este Hilo estimado Laiton, te agradecer铆a si podemos ponernos en contacto para unas consultas sobre la compilaci贸n del HDO de Manu,

Puedes escribirme a mi correo lubin.am@gmail.com para coordinar, Manu me comento tu experiencia en esta libreria

Gracias ..

Lubin Azahuanche.

Continue the discussion