Página 1 de 1

WebBrowser SetFocus Question

Publicado: Jue Oct 27, 2011 3:11 pm
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

WebBrowser SetFocus Question

Publicado: Mié Nov 16, 2011 10:06 am
por emeasoft
No support?
Mário Angelini

WebBrowser SetFocus Question

Publicado: Mié Nov 16, 2011 1:46 pm
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

WebBrowser SetFocus Question

Publicado: Mié Nov 16, 2011 6:30 pm
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)Â

WebBrowser SetFocus Question

Publicado: Jue Nov 17, 2011 7:45 pm
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

WebBrowser SetFocus Question

Publicado: Jue Nov 17, 2011 7:57 pm
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

WebBrowser SetFocus Question

Publicado: Jue Nov 17, 2011 8:07 pm
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

WebBrowser SetFocus Question

Publicado: Jue Nov 17, 2011 10:02 pm
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

WebBrowser SetFocus Question

Publicado: Vie Nov 18, 2011 4:41 pm
por emeasoft
I have tested it and now its working very well.
Thanks for all your help,
Juliano