VFP and Internet explorer eventHandler
Subject: how to trap windows internet explorer browser events from the parent vfp form.
This code is a browser internet explorer activeX on a vfp form.
When any activeX is placed on a form it receive the focus and make
the intercepting keys (form.keypreview=.t.) unavailbale on the form
All the keystrokes go to the activeX and dont be seen with the form event(keypress)
To intercept the keystrokes intercepted by the activeX , we must build an eventHandler on it.
The activeX seen from the object explorer have interface,methods,.... we can drag the
interface class code fromthe vfp object Browser on the command window or a prg open file
and then have the class code to do that.
The Object Browser displays the classes, properties, methods, events, and constants available for COM object libraries. You can use it to find and use objects you create, as well as objects from other applications.
can execute object browser with :
DO (_OBJECTBROWSER)
Can build the class as yeventHandler.prg and in the form make the relation "eventHandler".
Try to stroke any key ,left mouse, rightmouse,key copy selection CTRL+C and see
the interactive interceptions in the form.labe
you can add the code you want to the yeventHandler.prg procedures to make some actions
when a key is pressed, click,dblclick,rightclick....
*!*Begin Code
Set Defa To Addbs(Justpath(Sys(16,1)))
Set Safe Off
Local m.yevh
TEXT to m.yevh noshow
*code dragged from vfp object browse
DEFINE CLASS HtmlDocumentEvents AS session OLEPUBLIC
IMPLEMENTS HTMLElementEvents IN MSHTML.TLB &&"C:\WINDOWS\SYSTEM32\MSHTML.TLB"
PROCEDURE HTMLElementEvents_onhelp() AS LOGICAL
* add user code here
ENDPROC
PROCEDURE HTMLElementEvents_onclick() AS LOGICAL
* add user code here
this.ylog("document clicked !"+chr(13)+"called from:"+program())
oDOc.focus()
ENDPROC
PROCEDURE HTMLElementEvents_ondblclick() AS LOGICAL
* add user code here
this.ylog("document dblclicked !"+chr(13)+"called from:"+program())
oDOc.focus()
ENDPROC
PROCEDURE HTMLElementEvents_onkeypress() AS LOGICAL
* add user code here
DECLARE INTEGER GetAsyncKeyState IN user32 INTEGER vKey
x=""
for i=1 to 255
if GetAsyncKeyState(i)#0
x="Key "+(trans(i)+" "+chr(i)+" pressed")+chr(13) &&last pressed only
endi
endfor
this.ylog(x+chr(13)+"called from:"+program())
oDOc.focus()
ENDPROC
PROCEDURE HTMLElementEvents_onkeydown() AS VOID
* add user code here
ENDPROC
PROCEDURE HTMLElementEvents_onkeyup() AS VOID
* add user code here
ENDPROC
PROCEDURE HTMLElementEvents_onmouseout() AS VOID
* add user code here
ENDPROC
PROCEDURE HTMLElementEvents_onmouseover() AS VOID
* add user code here
ENDPROC
PROCEDURE HTMLElementEvents_onmousemove() AS VOID
* add user code here
ENDPROC
PROCEDURE HTMLElementEvents_onmousedown() AS VOID
* add user code here
ENDPROC
PROCEDURE HTMLElementEvents_onmouseup() AS VOID
* add user code here
ENDPROC
PROCEDURE HTMLElementEvents_onselectstart() AS LOGICAL
* add user code here
ENDPROC
PROCEDURE HTMLElementEvents_onfilterchange() AS VOID
* add user code here
ENDPROC
PROCEDURE HTMLElementEvents_ondragstart() AS LOGICAL
* add user code here
ENDPROC
PROCEDURE HTMLElementEvents_onbeforeupdate() AS LOGICAL
* add user code here
ENDPROC
PROCEDURE HTMLElementEvents_onafterupdate() AS VOID
* add user code here
ENDPROC
PROCEDURE HTMLElementEvents_onerrorupdate() AS LOGICAL
* add user code here
ENDPROC
PROCEDURE HTMLElementEvents_onrowexit() AS LOGICAL
* add user code here
ENDPROC
PROCEDURE HTMLElementEvents_onrowenter() AS VOID
* add user code here
ENDPROC
PROCEDURE HTMLElementEvents_ondatasetchanged() AS VOID
* add user code here
ENDPROC
PROCEDURE HTMLElementEvents_ondataavailable() AS VOID
* add user code here
ENDPROC
PROCEDURE HTMLElementEvents_ondatasetcomplete() AS VOID
* add user code here
ENDPROC
PROCEDURE HTMLElementEvents_onlosecapture() AS VOID
* add user code here
ENDPROC
PROCEDURE HTMLElementEvents_onpropertychange() AS VOID
* add user code here
ENDPROC
PROCEDURE HTMLElementEvents_onscroll() AS VOID
* add user code here
ENDPROC
PROCEDURE HTMLElementEvents_onfocus() AS VOID
* add user code here
ENDPROC
PROCEDURE HTMLElementEvents_onblur() AS VOID
* add user code here
ENDPROC
PROCEDURE HTMLElementEvents_onresize() AS VOID
* add user code here
ENDPROC
PROCEDURE HTMLElementEvents_ondrag() AS LOGICAL
* add user code here
ENDPROC
PROCEDURE HTMLElementEvents_ondragend() AS VOID
* add user code here
ENDPROC
PROCEDURE HTMLElementEvents_ondragenter() AS LOGICAL
* add user code here
ENDPROC
PROCEDURE HTMLElementEvents_ondragover() AS LOGICAL
* add user code here
ENDPROC
PROCEDURE HTMLElementEvents_ondragleave() AS VOID
* add user code here
ENDPROC
PROCEDURE HTMLElementEvents_ondrop() AS LOGICAL
* add user code here
ENDPROC
PROCEDURE HTMLElementEvents_onbeforecut() AS LOGICAL
* add user code here
ENDPROC
PROCEDURE HTMLElementEvents_oncut() AS LOGICAL
* add user code here
ENDPROC
PROCEDURE HTMLElementEvents_onbeforecopy() AS LOGICAL
* add user code here
this.ylog("Ctrl+C pressed----want to copy selection"+chr(13)+"called from:"+program() )
oDoc.focus()
ENDPROC
PROCEDURE HTMLElementEvents_oncopy() AS LOGICAL
* add user code here
ENDPROC
PROCEDURE HTMLElementEvents_onbeforepaste() AS LOGICAL
* add user code here
ENDPROC
PROCEDURE HTMLElementEvents_onpaste() AS LOGICAL
* add user code here
ENDPROC
PROCEDURE HTMLElementEvents_oncontextmenu() AS LOGICAL
* add user code here
this.ylog("Sorry the rightclic is disabled by me ! you can skip this message and make it silent."+chr(13)+"called from:"+program() )
return .f.
ENDPROC
PROCEDURE HTMLElementEvents_onrowsdelete() AS VOID
* add user code here
ENDPROC
PROCEDURE HTMLElementEvents_onrowsinserted() AS VOID
* add user code here
ENDPROC
PROCEDURE HTMLElementEvents_oncellchange() AS VOID
* add user code here
ENDPROC
PROCEDURE HTMLElementEvents_onreadystatechange() AS VOID
* add user code here
ENDPROC
PROCEDURE HTMLElementEvents_onbeforeeditfocus() AS VOID
* add user code here
ENDPROC
PROCEDURE HTMLElementEvents_onlayoutcomplete() AS VOID
* add user code here
ENDPROC
PROCEDURE HTMLElementEvents_onpage() AS VOID
* add user code here
ENDPROC
PROCEDURE HTMLElementEvents_onbeforedeactivate() AS LOGICAL
* add user code here
ENDPROC
PROCEDURE HTMLElementEvents_onbeforeactivate() AS LOGICAL
* add user code here
ENDPROC
PROCEDURE HTMLElementEvents_onmove() AS VOID
* add user code here
ENDPROC
PROCEDURE HTMLElementEvents_oncontrolselect() AS LOGICAL
* add user code here
ENDPROC
PROCEDURE HTMLElementEvents_onmovestart() AS LOGICAL
* add user code here
ENDPROC
PROCEDURE HTMLElementEvents_onmoveend() AS VOID
* add user code here
ENDPROC
PROCEDURE HTMLElementEvents_onresizestart() AS LOGICAL
* add user code here
ENDPROC
PROCEDURE HTMLElementEvents_onresizeend() AS VOID
* add user code here
this.ylog("document resized !"+chr(13)+"called from:"+program())
oDoc.focus()
ENDPROC
PROCEDURE HTMLElementEvents_onmouseenter() AS VOID
* add user code here
ENDPROC
PROCEDURE HTMLElementEvents_onmouseleave() AS VOID
* add user code here
ENDPROC
PROCEDURE HTMLElementEvents_onmousewheel() AS LOGICAL
* add user code here
ENDPROC
PROCEDURE HTMLElementEvents_onactivate() AS VOID
* add user code here
ENDPROC
PROCEDURE HTMLElementEvents_ondeactivate() AS VOID
* add user code here
ENDPROC
PROCEDURE HTMLElementEvents_onfocusin() AS VOID
* add user code here
ENDPROC
PROCEDURE HTMLElementEvents_onfocusout() AS VOID
* add user code here
ENDPROC
PROCEDURE YLOG(ystr)
_vfp.forms(1).label1.caption=ystr
TRY
LOCAL lcBell
lcBell = SET("Bell")
SET BELL TO (ADDBS(GETENV('windir')))+"MEDIA\notify.WAV"
?? CHR(7)
SET BELL TO (lcBell)
CATCH
ENDTRY
endproc
ENDDEFINE
ENDTEXT
=Strtofile(m.yevh, "yeventHandler.prg")
*this creates a form with a activeX browser.
Publi yform
yform=Newobject("asup")
yform.Show
Read Events
Return
*
Define Class asup As Form
Top = 24
Left = 87
Height = 474
Width = 726
ShowWindow = 2
Caption = "Iexplore EventHandler-intercepting events..."
Name = "form1"
Add Object olecontrol1 As OleControl With ;
oleclass="Shell.explorer.2",;
Top = 3, ;
Left = 4, ;
Height = 348, ;
Width = 720, ;
Name = "Olecontrol1"
Add Object timer1 As Timer With ;
Top = 312, ;
Left = 696, ;
Height = 23, ;
Width = 23, ;
Enabled = .F., ;
Interval = 1000, ;
Name = "Timer1"
Add Object command1 As CommandButton With ;
Top = 408, ;
Left = 48, ;
Height = 27, ;
Width = 84, ;
Anchor = 4, ;
Caption = "Navigate....", ;
Name = "Command1"
Add Object label1 As Label With ;
FontBold = .T., ;
FontSize = 10, ;
Anchor = 4, ;
WordWrap = .T., ;
Caption = "", ;
Height = 108, ;
Left = 180, ;
Top = 358, ;
Width = 540, ;
ForeColor = Rgb(0,255,0), ;
BackColor = Rgb(0,0,0), ;
Name = "Label1"
Procedure Destroy
Clea Events
Endproc
Procedure Load
_Screen.WindowState=1
Endproc
Procedure Init
Thisform.timer1.Enabled=.T.
Endproc
Procedure olecontrol1.Init
This.Anchor=15
This.Navigate("about:blank")
Do While This.busy Or This.readystate#4
Enddo
Inkey(1)
Publi oDOc
oDOc=This.Document
&&set the events hook
oEv = Newobject("HTMLDocumentEvents","yeventhandler.prg")
Eventhandler(oDOc,oEv)
Endproc
Procedure timer1.Timer
TEXT to myvar0 noshow
*!*--Author Yousfi Benameur El Bayadh Algeria<BR>
*!*--Time stamp samedi 14 août 2010; 09:40:58<BR>
*!*--Subject :Focus with activeX on VFP forms<BR>
*!*--Version Vfp9Sp2 WINDOWS XP SP2 WIN8.1 <BR>
ENDTEXT
TEXT to myvar textmerge noshow
<p>
<h3 style="align:center;color:navy ;background-color:yellow;"> HOW TO INTERCEPT KEYSTROKES OU MOUSE EVENTS ON IEXPLORE ACTIVEX</H3><br><br>
This is a browser internet explorer activeX on a form.<br>
When any activeX is placed on a form it receive the focus and make <br>
the intercepting keys (keypreview=.t.) unavailbale on the form <br>
All the keystrokes go to the activeX and dont be seen with the form event(keypress).<br>
To intercept the keystrokes intercepted by the activeX , we must build an eventHandler<br>
on it.
The activeX seen from the object explorer have interface,methods,.... we can drag the <br>
interface class code fromthe vfp object Browser on the command window or a prg open file <br>
and then have the class code to do that.<br><br>
Can build the class as prg and in the form make the relation "eventHandler".<br>
Try to stroke any key ,left mouse, rightmouse,key copy selection CTRL+C and see<br>
the interactive interceptions in the form.label<br>
you can add the code you want to the yeventHandler.prg procedures to make some actions<br>
when a key is pressed, click,dblclick,rightclick....<BR><BR>
<<myvar0>>
</p>
ENDTEXT
oDOc.body.innerhtml=myvar
This.Enabled=.F.
Endproc
Procedure command1.Click
Y=Inputbox("url to navigate to","")
If Not Empty(Y)
Thisform.olecontrol1.Navigate(m.y)
Endi
Endproc
Enddefine
*
*!- End COde