Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


Get file name of a frame

Posted on 2003-03-24
Medium Priority
Last Modified: 2010-04-01
I'm using this code to get a window handle.

GetCursorPos (&pt);
hWnd = WindowFromPoint(pt);

I wish with this code, get a form "file name" of a HTML page.

Explanation of my problem

supposing you have three HTML page:

a) index.htm
b) firstframe.htm
c) secondframe.htm

(a) & (b) is two frames opened by "index.htm".

Well, when I click on the "index.htm" window area, if the mouse is clicked
on the area occupied by the "firstframe.htm" the function will display
its file name; for example by using:


where "lpString" point to: "firstframe.htm"

I've tried but i get only the file name of the "index.htm"

Thank you
Question by:Dario2
  • 2
LVL 12

Expert Comment

ID: 8194342
Your problem is that those frames aren't necessarily separate windows. In particular even if they are it is quite possible that the handle you have isn't the handle to that window. I am not sure what WindowFromPoint() does, if it return the smallest window that contain point or if it return a 'top level window' that contain the point unless the point is within your own application etc...

In any event this is the web browser or html browser's internal implementation that determines how this works and so windows cannot possibly get that right unless the browser has implemented in such a way that windows does happen to get it right.

I am afraid your best bet is to ask the browser of that frame. One thing you CAN do is of course to get the 'index.html' and then from there work your way through, but again that require you to know the internals of the web or html browser you're using.

Some web browsers can respond to external requests and most of them can provide such info to java applet code that runs in the browser. I am afraid that if you are an external application you will have to use whatever interface the browser provide for external programs (for example DOM interface or some such). If you're running a java applet it should be easier but also there it is very much depending on which html browser you're running, internet explorer does it differently from Mozilla for example.

So I am afraid I have to disappoint you, there is no generic way to get the info you seek.


Author Comment

ID: 8197494
My dubt born because I've tried to copy with success only one region of a HTML page, and keep present, a HTML page builded from many frames.

If you try to capture a window handle with my code post below and after you try to create snapshot by clicking on a area of one frame using BitBlt(.....) function, only the clicked area is copied in the destination bitmap container.

This means that every frame in the HTML page, have properly address space and then, I think other informations such as, file name of the frame.
LVL 12

Accepted Solution

Salte earned 1000 total points
ID: 8201612
Not necessarily. This depends on the web browser application. Even if it uses separate windows for each frame those windows doesn't have to have a title and even if they do they don't have to have the tile equal to the name of the file in them. The application determines both the contents of the window and the title and other things.

If the browser have an interface that allow you to get the name of the frame you can use that. For example Internet Explorer has a DOM interface (Document Object Model) that allow you to ask what source file is connected to a specific frame etc. However, this is very much dependent upon the application (Internet explorer in this case). Other web browsers may have a similar interface but it is probably different and it's not obvious they at all have such an interface.

From Java applets however, it is easier in that most browsers do provide ways the applet can ask for the source URL.

However, under no circumstance is this connected with Windows. Windows simply provide a thing called a "window" which can show some graphic on the screen and such windows have a "title" associated with them. What this title contains and how it is related to the contents of the window or if the title contain anything at all is entirely up to the application. There is no policy enforced by windows in this regard - nor should there be, many applications display windows that is NOT originating from a specific file and it would not be meaningful to enforce such a policy at all.

In short, unless you want to be application specific - give it up.

LVL 11

Expert Comment

ID: 9558626
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

Answered: Points to Salte

Please leave any comments here within the next seven days. Experts: Silence
means you don't care.


-bcl (bcladd)
EE Cleanup Volunteer

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
Suggested Courses

581 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question