473,405 Members | 2,310 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

mshtml and frames/iframes

Hi,

I'm doing a kind of control picker like the one in spy++ but for html
document.

When the control picker is over an IFRAME, the mshtml function
ElementFromPoint return an IFrame element.

How can I identify this particular frame/iframe in the frame
collection??? I can only select frame in the framecollection by using
the index or the frame name but the frame name is not always defined.

This is the part of code that try call recursivly
ElementFromPoint...only the last section of the code is releated to my
question

using mshtml;
//..

//--- Get document
IHTMLDocument2 HtmlDoc;
IHTMLDocument3 HtmlDoc; // to get HtmlDoc3.documentElement.ScrollTop,
ScrollLeft
HtmlDoc = GetIHTMLDocumentFromHandle(found); /found=internet
explorer_server handle
HtmlDoc3 = GetIHTMLDocumentFromHandle(found);

//--- Get the elementfromPoint in the main page
IHTMLElement Element;
Point pt;
pt = new Point(Control.MousePosition.X, Control.MousePosition.Y);
ScreenToClient(found, ref pt);
Element = HtmlDoc.elementFromPoint((int)pt.X, (int)pt.Y);

//--- Determine real element size and position relative to the main
page.
int ElementLeft = Element.offsetLeft;
int ElementTop = Element.offsetTop;
mshtml.IHTMLElement TmpElem = Element.offsetParent;
while (TmpElem != null)
{
ElementLeft = ElementLeft + TmpElem.offsetLeft;
ElementTop = ElementTop + TmpElem.offsetTop;
TmpElem = TmpElem.offsetParent;
}

//--- Highlight element
HighlightHtmlElement(found, ElementLeft - ScrollLeft, ElementTop -
ScrollTop, (int)Element.offsetWidth, (int)Element.offsetHeight);

//This is where my nightmare begins
if (Element.TagName.ToString().ToLower()=="iframe")
{
// Need to get an IHtmlDocument2 that point to the correct frame.
FramesCollection frm = (mshtml.FramesCollection)HtmlDoc.frames;
for (int Cnt=0;Cnt<frm.Length)
{
object FrameRefIndex=Cnt; //This is the
mshtml.IHTMLWindow2 HtmlWin = (mshtml.IHTMLWindow2)frm.item(ref
FrameRefIndex);
Trace.write("Inner html of the
iframe="+HtmlWin.Document.Body.InnerHtml.ToString( ));
// If (the framed document is the one contained in the iframe
tag returned by ElementFromPoint)
// doing my stuff to highlight the elements
}

}

MY QUESTION : In the last line of code it look like there is no way to
identify which framed document is associated with my iframe element
returned by ElementFromPoint.

I'm desesperatively working on this frame issue since many many many
many hours :( Really need help of an mshtml good samaritin expert.

Thanks
Sep 15 '08 #1
1 8676
On Sep 15, 1:51*am, michelqa <miche...@yahoo.cawrote:
Hi,

*I'm doing a kind of control picker like the one in spy++ but for html
document.

When the control picker is over an IFRAME, *the mshtml function
ElementFromPoint return an IFrame element.

How can I identify this particular frame/iframe in the frame
collection??? I can only select frame in the framecollection by using
the index or the frame name but the frame name is not always defined.

This is the part of code that try call recursivly
ElementFromPoint...only the last section of the code is releated to my
question

using mshtml;
//..

//--- Get document
IHTMLDocument2 HtmlDoc;
IHTMLDocument3 HtmlDoc; // to get HtmlDoc3.documentElement.ScrollTop,
ScrollLeft
HtmlDoc = GetIHTMLDocumentFromHandle(found); * /found=internet
explorer_server handle
HtmlDoc3 = GetIHTMLDocumentFromHandle(found);

//--- Get the elementfromPoint in the main page
IHTMLElement Element;
Point pt;
pt = new Point(Control.MousePosition.X, Control.MousePosition.Y);
ScreenToClient(found, ref pt);
Element = HtmlDoc.elementFromPoint((int)pt.X, (int)pt.Y);

//--- Determine real element size and position relative to the main
page.
int ElementLeft = Element.offsetLeft;
int ElementTop = Element.offsetTop;
mshtml.IHTMLElement TmpElem = Element.offsetParent;
while (TmpElem != null)
{
* * * * ElementLeft = ElementLeft + TmpElem.offsetLeft;
* * * * ElementTop = ElementTop + TmpElem.offsetTop;
* * * * TmpElem = TmpElem.offsetParent;

}

//--- Highlight element
HighlightHtmlElement(found, ElementLeft - ScrollLeft, ElementTop -
ScrollTop, (int)Element.offsetWidth, (int)Element.offsetHeight);

//This is where my nightmare begins
if (Element.TagName.ToString().ToLower()=="iframe")
{
* * // Need to get an IHtmlDocument2 that point to the correct frame.
* * FramesCollection frm = (mshtml.FramesCollection)HtmlDoc.frames;
* * for (int Cnt=0;Cnt<frm.Length)
* * {
* * * *object FrameRefIndex=Cnt; * *//This is the
* * * *mshtml.IHTMLWindow2 HtmlWin = (mshtml.IHTMLWindow2)frm.item(ref
FrameRefIndex);
* * * *Trace.write("Inner html of the
iframe="+HtmlWin.Document.Body.InnerHtml.ToString( ));
* * * *// If (the framed document is the one contained in the iframe
tag returned by ElementFromPoint)
* * *// doing my stuff to highlight the elements
* *}

}

MY QUESTION : In the last line of code it look like there is no way to
identify which framed document is associated with my iframe element
returned by ElementFromPoint.

I'm desesperatively working on this frame issue since many many many
many hours :( *Really need help of an mshtml good samaritin expert.

Thanks
The only way I can imagine is to manually scan all document element...
pseudo maybe look like this :

FrameIndex=0
foreach element in the document
{
if (elment TagName="iframe" or "frame")
{
if the element got the same offsetleft an offsettop as the item
returned by elementfrompoint= break the loop
FrameIndex++
}
FrameIndex will be my frameindex and now i will ***MAY*** be able to
identify the right frame....

but this assume that the frame collection parse all the frame exactly
the same way as my application when parsing each element and counting
my own index

I'm sure it's not the right way to do this :(
Sep 15 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: maxim vexler | last post by:
I'm reading a lot of talks lately about the term iFrame and with your permission would like to ask a few question about that : - what is iFrame, i mean what is it good for ? - does all the...
4
by: Arne Hendrickson | last post by:
Can anyone tell me how to edit this script for "traditional frames" to work with iframes? SCRIPT language="JavaScript"> <!----hide function change2() { parent.left_frame.location="page3.htm";...
6
by: adnanx82 | last post by:
Hi, I was wondering if anyone knew how to perform the following 2 tasks in Javascript: 1) distinguish between frames and iframes (during an onload event for example) 2) figure out whether a...
1
by: Owen | last post by:
I believe that different browsers treat frames/iframes differently, and this is one of the reasons to avoid using them in websites/applications. Are there any other reasons to avoid them? In...
4
by: David Pendrey | last post by:
Hello all, I am using the WebBrowser control to browse a webpage containing frames and am having difficulties accessing the 'frames' property of a document object. Bellow is my code and the error...
4
by: Lars-Erik Aabech | last post by:
Hi! I've been walking in extacy since reading the article about test automation with IE in the latest MSDN mag. (http://msdn.microsoft.com/msdnmag/issues/05/10/TestRun/default.aspx) After a...
0
by: geertm | last post by:
Hello, I have a problem accessing frames using the MSHTML object. I tried this code ----------------------------------- For intindex = 0 To objDoc.frames.count - 1 .... Next...
8
by: kaaposc | last post by:
Hello! This is not question, I was just wondering, why people continue using frames and iframes when we have handy AJAX approach to fill needed divs with content. Is it because of some user's...
14
by: Mark | last post by:
Hi Guys, I am very new to ASP.NET world. I need to create three frames. One at the top, one on the left and another on the right side. I don't know how to do it. So please help me with it. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.