Solved

how to get URLs of Internet Explorer documents

Posted on 2006-06-09
10
493 Views
Last Modified: 2008-02-01
I would like to be able to get the URLs of all documents that are open in IE. I tried by using the tcom package (Windwos com objects, http://www.vex.net/~cthuang/tcom/) of Tcl/Tk. But when I try to get an handle of an existing instance of IE I get an "operation unavailable" error message. Instead I can create a new object with tcom and use it without any problem. Any way of doing it in Windows with C would be fine for me. Thanks.
0
Comment
Question by:s_federici
  • 6
  • 2
  • 2
10 Comments
 
LVL 86

Expert Comment

by:jkr
Comment Utility
See http://support.microsoft.com/kb/q176792/ ("How to connect to a running instance of Internet Explorer") which demonstrates that. The sample code there however is VB or C++, but it is almost complete, all you need to call is 'IWebBrowser2::get_LocationURL()' instead of 'GetDocument()'.
0
 
LVL 3

Expert Comment

by:srinims
Comment Utility
HI, I think IWebBrowser@ is used to create a new instance of IE, And get_LocationURL() will get the address of created instance.
For Getting the url's of already openend windows. U have do the Spy program Which can idendify all the Windows under the Destop handle, And then you have to locate the Internet Explorer application on that. After then you can find the URL of all opened IE windows.  
pls find the below details,which I got from one site.

In the Internet Explorer the current URL is displayed inside the combo box component on the Address bar. In order to "steal" the current URL from IE, you'll need to find the (control class) name of that combo box, locate it, and grab its text. Now, this seems easy, but how do you do that?
To be able to grab a text from an arbitrary window (and its child windowed controls) on the Windows Desktop, you'll need to play with Windows API calls and Windows Messages. First, or better to say last, when you find that combo box with the current URL in it, you can send a WM_GETTEXT message to that window and pick the text displayed inside. Second, or better to say first, you need to know the exact order of controls that are parents to that URL combo box. Then, you use the FindWindowEx API call in order to retrieve the handle (an integer number that uniquely identifies each control / window) of the child window. Ok, all seems easy, but again how do you know the structure of IEs controls and their parenthood?

the main IE window is called "IEFrame".To retrieve the handle to the top-level window whose class name is provided (in our case: IEFrame), you can use the FindWindow API call. When you have the IE handle you then use the FindWindowEx API, to locate that ComboBox control with the URL. Finally, as already mentioned above, you send that ComboBox the WM_GETTEXT message to obtain the text from it.
This seems easy. However, note that FindWindow API retrieves the handle to the top-level window. What this means is that if you have multiple instances of IE opened (as you probably have) the function will locate the last activated IE window

Enumerate all top-level windows using the EnumWindows callback (this gives us a Handle)
Grab the Caption (Title) of each Window
Look only for windows whose class name is "IEFrame"
Use the FindWindow provided with the Handle and the Caption to locate the correct IE window
Call FindWindowEx several times to locate the ComboBox carying the URL, as it is the child to some parent which is a child to our top-level IEFrame (this is the class name) window
Send a message to the ComboBox to retrieve the text inside it
0
 
LVL 3

Expert Comment

by:srinims
Comment Utility
A VB sample

http://www.mvps.org/access/api/api0051.htm

U could use the same thing for windows application, or you can convert into the Vc++ code using the same api calls.

srini ms
0
 
LVL 86

Expert Comment

by:jkr
Comment Utility
>>HI, I think IWebBrowser@ is used to create a new instance of IE, And get_LocationURL() will get the
>>address of created instance.

Thank you, I really appreciate when people repeat what I already wrote.
0
 

Author Comment

by:s_federici
Comment Utility
Sorry, after deep study, I'm totally unable to implement srinims' suggestion in C. Help is needed.
0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 3

Expert Comment

by:srinims
Comment Utility
hi jkr,   I'm really sorry for my comments. I haven't read the documment given in the microsoft site. I have read out only from my local msdn, that's the problem. Any way I'm really sorry for the comments on your post.


hi federici, could u post the problem you are facing.  have u tried the code using vb given in the second link.

srini ms
0
 
LVL 3

Expert Comment

by:srinims
Comment Utility
the vb code is working fine.

u can covert the same vb code in vc++ sdk code.
get the .bas file in the above link, i have given.
try to load in to one VB. and change some code as below mentioned to get the message box with address

                If hWndChild > 0 Then
                    '   Get the length of the URL in Editbox
                    lngLen = apiSendMessage(hWndChild, WM_GETTEXTLENGTH, _
                                    0, ByVal 0&)
                    strURL = Space$(lngLen + 1)
                    '   Get the URL itself
                    lngLen = apiSendMessage(hWndChild, WM_GETTEXT, _
                                            lngLen + 1, ByVal strURL)
                    MsgBox (strURL)

the strURL is the string responsible for address, the sniphet is from the Refresh method.
i have the problem in the first line related with database, just comment it out.

srini ms
0
 
LVL 3

Accepted Solution

by:
srinims earned 500 total points
Comment Utility
finaly I, solved for u,
find it usefull.

srini ms

void GetIEAddress( )
{
      #define MAX_LEN  255
      long lngStyle,lngLen;
      HWND hWnd,hWndChild;      
      char strBuffer[MAX_LEN];
      char strURL[MAX_LEN];
      char strCAPTION[MAX_LEN];
      char *mconCAPTION = " - Microsoft Internet Explorer";
      char *partFOUND;
      OSVERSIONINFO tOSInfo;
      tOSInfo.dwOSVersionInfoSize = sizeof(tOSInfo);
      GetVersionEx(&tOSInfo);

      hWnd =GetWindow(GetDesktopWindow(), GW_CHILD);
      while(hWnd!=0)
      {
            lngStyle = GetWindowLong(hWnd, GWL_STYLE);
            if(lngStyle & WS_VISIBLE)
            {
                  GetClassName(hWnd, strBuffer, MAX_LEN);
                  if(!strcmp(strBuffer,"IEFrame"))
                  {
                        GetWindowText(hWnd, strCAPTION, MAX_LEN);
                        partFOUND = strstr(strCAPTION,mconCAPTION);
                        if(partFOUND)
                        {
                              if(tOSInfo.dwPlatformId == VER_PLATFORM_WIN32_NT)
                                    hWndChild = FindWindowEx(hWnd, 0, "WorkerW",0);
                              else
                                    hWndChild = FindWindowEx(hWnd, 0, "WorkerA",0);
                              if(hWndChild>0)
                                    hWndChild = FindWindowEx(hWndChild, 0, "ReBarWindow32",0);
                              if(hWndChild>0)
                                    hWndChild = FindWindowEx(hWndChild, 0, "ComboBoxEx32",0);
                              if(hWndChild>0)
                                    hWndChild = FindWindowEx(hWndChild, 0, "ComboBox",0);
                              if(hWndChild>0)
                                    hWndChild = FindWindowEx(hWndChild, 0, "Edit",0);
                              if(hWndChild>0)
                              {
                                    lngLen = SendMessage(hWndChild, WM_GETTEXTLENGTH, 0,0);
                                    SendMessage(hWndChild, WM_GETTEXT,((lngLen + 1) > MAX_LEN)?(lngLen + 1):MAX_LEN, (long)&strURL);
                                    MessageBox(NULL,strURL,strCAPTION,0);
                              }
                        }
                  }
            }
            hWnd = GetWindow(hWnd, GW_HWNDNEXT);
      }
}
0
 
LVL 3

Expert Comment

by:srinims
Comment Utility
change the statement from ((lngLen + 1) > MAX_LEN)?(lngLen + 1):MAX_LEN
into
((lngLen + 1) < MAX_LEN)?(lngLen + 1):MAX_LEN
0
 

Author Comment

by:s_federici
Comment Utility
Thanks a lot. Sorry if I didn't test immediately, but I was out of the office. It worked very well.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.

743 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now