Posts: 858
Threads: 196
Joined: Apr 2005
Is possible to get html element from certain coordinates when acc doesn't locate the element?
Posts: 11,901
Threads: 138
Joined: Dec 2002
Member function
Htm.FromXY2
function x y
;Gets element from point in screen, and initializes this variable.
;Error if fails.
;EXAMPLE
;out
;Htm el.FromXY2(xm ym)
;out el.HTML
POINT p.x=x; p.y=y
if _iever>=0x532
,;get doc of element from point. If in frame, it must not be top-level doc. With acc it is easier.
,Acc a=acc(p.x p.y 0) ;;any elem in that doc
,MSHTML.IHTMLElement _el=htm(a); if(!_el) goto gFailed
,MSHTML.IHTMLDocument2 doc=_el.document
,
,;get doc location in screen, and mouse pos in doc
,_el=doc.body; a=acc(_el)
,if(a.Role!=ROLE_SYSTEM_CLIENT) a.Navigate("parent") ;;PANE -> CLIENT
,a.Location(x y)
,p.x-x; p.y-y
else ;;IE5 (each frame in own IES; htm(a) fails)
,int h=child(p.x p.y 0)
,rep ;;because h may be child combo etc
,,if(!h) goto gFailed
,,if(childtest(h "" "Internet Explorer_Server")) break
,,h=GetParent(h)
,doc=htm(h)
,ScreenToClient h &p
;get element from point
if(_iever>=0x800) EH_MulDiv2 100 EH_GetZoom2(doc) +&p 2
_el=doc.elementFromPoint(p.x p.y); if(!_el) goto gFailed
el=_el
ret
err+
;gFailed
end "failed"
Function
EH_MulDiv2
;/
function mul div *p n
;MulDiv for multiple values.
if(mul=div or !mul or !div) ret
for(n n 0 -1) *p=MulDiv(*p mul div); p+4
Function
EH_GetZoom2
;/
function# MSHTML.IHTMLDocument2'doc
if(_iever<0x800) ret ;;although optical zoom is in IE7 too, but in IE7 don't need to convert coordinates
IOleCommandTarget ct=+doc ;;IE8
VARIANT zoom
ct.Exec(0 OLECMDID_OPTICAL_ZOOM OLECMDEXECOPT_DONTPROMPTUSER 0 &zoom)
err+ zoom=100
ret zoom
Posts: 858
Threads: 196
Joined: Apr 2005