In order for this site to work correctly we need to store a small file (called a cookie) on your computer. Most every site in the world does this, however since the 25th of May 2011, by law we have to get your permission first. Please abandon the forum if you disagree.

Para que este foro funcione correctamente es necesario guardar un pequeño fichero (llamado cookie) en su ordenador. La mayoría de los sitios de Internet lo hacen, no obstante desde el 25 de Marzo de 2011 y por ley, necesitamos de su permiso con antelación. Abandone este foro si no está conforme.

WebBrowser SetFocus Question

Xailer professional forum in English
Responder
Avatar de Usuario
emeasoft
Mensajes: 1094
Registrado: Mié Abr 01, 2009 4:12 pm
Ubicación: emeasoft
Contactar:

WebBrowser SetFocus Question

Mensaje por emeasoft »

Hello Xailers,
I'm having an issue trying to set the focus on the webbrowser after I enter the url to navigate.
It only sets the focus if I click with the mouse once on the component, after that when I type any url and click ENTER, it automaticaly sets the focus on the webbrowser.
Other question, when the focus is on the webbrowser, i cant trigger any event on the form, like the onKeyDown, is there any way to do that?
Thanks,
Juliano
Avatar de Usuario
jfgimenez
Site Admin
Mensajes: 5718
Registrado: Lun Abr 06, 2015 8:48 pm
Contactar:

WebBrowser SetFocus Question

Mensaje por jfgimenez »

Juliano,
> I'm having an issue trying to set the focus on the
> webbrowser after I enter the url to navigate.
> It only sets the focus if I click with the mouse once on the
> component, after that when I type any url and click ENTER,
> it automaticaly sets the focus on the webbrowser.
How is you doing that? Please, I need a simple example to test it.
> Other question, when the focus is on the webbrowser, i cant
> trigger any event on the form, like the onKeyDown, is there
> any way to do that?
When the OCX has focus, it catches all keyboard strokes, and doesn't
redirect them to the form, as Xailer's native controls do. There is an
OnKeyDown event in the OCX subsystem, that works in almost OCX, but I'm
affraid that WebBrowser is not one of them. That is, OnKeyDown doesn't
work in WebBrowser, since it doesn't notifies its container.
Regards,
Jose F. Gimenez
http://www.xailer.com
http://www.xailer.info
José F. Giménez
[Equipo de Xailer / Xailer team]
http://www.xailer.com
http://www.xailer.info
Avatar de Usuario
emeasoft
Mensajes: 1094
Registrado: Mié Abr 01, 2009 4:12 pm
Ubicación: emeasoft
Contactar:

WebBrowser SetFocus Question

Mensaje por emeasoft »

Hello Jose,
> How is you doing that? Please, I need a simple example to test it.
Here goes the example, I left some comments on the form, on how to make it work.
> When the OCX has focus, it catches all keyboard strokes, and doesn't
> redirect them to the form, as Xailer's native controls do. There is an
> OnKeyDown event in the OCX subsystem, that works in almost OCX, but I'm
> affraid that WebBrowser is not one of them. That is, OnKeyDown doesn't
> work in WebBrowser, since it doesn't notifies its container.
Thank you for answering me this question.
Thanks,
Juliano

Attached files WebBrowser.zip (7.8 KB)Â
Avatar de Usuario
jfgimenez
Site Admin
Mensajes: 5718
Registrado: Lun Abr 06, 2015 8:48 pm
Contactar:

WebBrowser SetFocus Question

Mensaje por jfgimenez »

Juliano,
> Here goes the example, I left some comments on the form, on
> how to make it work.
Thanks for your sample.
>> When the OCX has focus, it catches all keyboard strokes,
>> and doesn't redirect them to the form, as Xailer's native controls
>> do. There is an OnKeyDown event in the OCX subsystem, that works in
>> almost OCX, but I'm affraid that WebBrowser is not one of them. That is,
>> OnKeyDown doesn't work in WebBrowser, since it doesn't notifies its
>> container.
>
> Thank you for answering me this question.
You're wellcome.
I've been working on this issue, and I belive it's now fixed. Moreover,
I've even got the OnKeydown event to work fine, although it's fired
asyncronously.
Regards,
Jose F. Gimenez
http://www.xailer.com
http://www.xailer.info
José F. Giménez
[Equipo de Xailer / Xailer team]
http://www.xailer.com
http://www.xailer.info
Avatar de Usuario
jfgimenez
Site Admin
Mensajes: 5718
Registrado: Lun Abr 06, 2015 8:48 pm
Contactar:

WebBrowser SetFocus Question

Mensaje por jfgimenez »

Juliano,
> I'm having an issue trying to set the focus on the
> webbrowser after I enter the url to navigate.
The problem is that when the webrowser OCX is created, it doesn't create
all of its components. It's only done when a web page has began to
download. So, in order to work what you want, it's needed to do a delay.
I.e (from your sample):
METHOD FormInitialize( oSender ) CLASS TForm1
LOCAL nTicks
WITH OBJECT ::oOcx := TWebBrowser():New( ::oBevel1 )
:nAlign := alCLIENT
:Create()
END
::oOcx:Navigate(::oEdit1:value)
// Causes a delay for about 1 second
nTicks := GetTickCount() + 1000
WHILE GetTickCount() < nTicks
ProcessMessages()
ENDDO
// After that, you can set the focus
::oOcx:SetFocus() // This SetFocus does not work, even if i put
it on the event navigationComplete from the webbrowser
RETURN Nil
> It only sets the focus if I click with the mouse once on the
> component, after that when I type any url and click ENTER,
> it automaticaly sets the focus on the webbrowser.
It's now fixed and working fine.
> Other question, when the focus is on the webbrowser, i cant
> trigger any event on the form, like the onKeyDown, is there
> any way to do that?
I've 'hacked' a bit the OCX support to deal with IWebBrowser keystrokes,
and it's working now. But the event is fired asynchronously. That means
that you may receive the OnKeydown event at any time after the key is
pressed in the OCX, while the OCX itself continues running, and any
returned value from the event is completely ignored.
Regards,
Jose F. Gimenez
http://www.xailer.com
http://www.xailer.info
José F. Giménez
[Equipo de Xailer / Xailer team]
http://www.xailer.com
http://www.xailer.info
jlalin
Mensajes: 926
Registrado: Sab Dic 25, 2010 11:10 pm

WebBrowser SetFocus Question

Mensaje por jlalin »

Jose, Juliano,
this is not needed:
> nTicks := GetTickCount() + 1000
> WHILE GetTickCount() < nTicks
> ProcessMessages()
> ENDDO
WHILE ::oOCX:Busy()
ProcessMessages()
END
Regards,
José Lalí­n
Avatar de Usuario
jfgimenez
Site Admin
Mensajes: 5718
Registrado: Lun Abr 06, 2015 8:48 pm
Contactar:

WebBrowser SetFocus Question

Mensaje por jfgimenez »

José,
> this is not needed:
>
>> nTicks := GetTickCount() + 1000
>> WHILE GetTickCount() < nTicks
>> ProcessMessages()
>> ENDDO
>
> WHILE ::oOCX:Busy()
> ProcessMessages()
> END
Yes, you are right. I was focused in the TOcx source and didn't remember
that method from TWebBrowser
Regards,
Jose F. Gimenez
http://www.xailer.com
http://www.xailer.info
José F. Giménez
[Equipo de Xailer / Xailer team]
http://www.xailer.com
http://www.xailer.info
Avatar de Usuario
emeasoft
Mensajes: 1094
Registrado: Mié Abr 01, 2009 4:12 pm
Ubicación: emeasoft
Contactar:

WebBrowser SetFocus Question

Mensaje por emeasoft »

I have tested it and now its working very well.
Thanks for all your help,
Juliano
Responder